Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scripts/lib/abi/abi_parser.py: use an interactor for ReST output

Instead of printing all results line per line, use an interactor
to return each variable as a separate message.

This won't change much when using it via command line, but it
will help Sphinx integration by providing an interactor that
could be used there to handle ABI symbol by symbol.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/e3c94b8cdfd5e955aa19a703921f364a89089634.1739182025.git.mchehab+huawei@kernel.org

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
9bec7870 c67c3fbd

+28 -23
+2 -1
scripts/get_abi.py
··· 62 62 parser = AbiParser(args.dir, debug=args.debug) 63 63 parser.parse_abi() 64 64 parser.check_issues() 65 - parser.print_data(args.enable_lineno, args.raw, not args.no_file) 66 65 66 + for msg in parser.doc(args.enable_lineno, args.raw, not args.no_file): 67 + print(msg) 67 68 68 69 class AbiValidate: 69 70 """Initialize an argparse subparser for ABI validation"""
+26 -22
scripts/lib/abi/abi_parser.py
··· 336 336 name = os.path.join(root, entry.name) 337 337 338 338 if entry.is_dir(): 339 - self.parse_abi(name) 339 + self._parse_abi(name) 340 340 continue 341 341 342 342 if not entry.is_file(): ··· 365 365 if self.debug & AbiDebug.DUMP_ABI_STRUCTS: 366 366 self.log.debug(pformat(self.data)) 367 367 368 - def print_desc_txt(self, desc): 368 + def desc_txt(self, desc): 369 369 """Print description as found inside ABI files""" 370 370 371 371 desc = desc.strip(" \t\n") 372 372 373 - print(desc + "\n") 373 + return desc + "\n\n" 374 374 375 - def print_desc_rst(self, desc): 375 + def desc_rst(self, desc): 376 376 """Enrich ReST output by creating cross-references""" 377 377 378 378 # Remove title markups from the description ··· 425 425 426 426 new_desc += d + "\n" 427 427 428 - print(new_desc + "\n") 428 + return new_desc + "\n\n" 429 429 430 - def print_data(self, enable_lineno, output_in_txt, show_file=False): 430 + def doc(self, enable_lineno, output_in_txt, show_file=False): 431 431 """Print ABI at stdout""" 432 432 433 433 part = None ··· 442 442 if not show_file and wtype == "File": 443 443 continue 444 444 445 + msg = "" 446 + 445 447 if enable_lineno: 446 448 ln = v.get("line_no", 1) 447 - print(f".. LINENO {file_ref[0][0]}#{ln}\n") 449 + msg += f".. LINENO {file_ref[0][0]}#{ln}\n\n" 448 450 449 451 if wtype != "File": 450 452 cur_part = names[0] ··· 458 456 459 457 if cur_part and cur_part != part: 460 458 part = cur_part 461 - print(f"{part}\n{"-" * len(part)}\n") 459 + msg += f"{part}\n{"-" * len(part)}\n\n" 462 460 463 - print(f".. _{key}:\n") 461 + msg += f".. _{key}:\n\n" 464 462 465 463 max_len = 0 466 464 for i in range(0, len(names)): # pylint: disable=C0200 ··· 468 466 469 467 max_len = max(max_len, len(names[i])) 470 468 471 - print("+-" + "-" * max_len + "-+") 469 + msg += "+-" + "-" * max_len + "-+\n" 472 470 for name in names: 473 - print(f"| {name}" + " " * (max_len - len(name)) + " |") 474 - print("+-" + "-" * max_len + "-+") 475 - print() 471 + msg += f"| {name}" + " " * (max_len - len(name)) + " |\n" 472 + msg += "+-" + "-" * max_len + "-+\n" 473 + msg += "\n" 476 474 477 475 for ref in file_ref: 478 476 if wtype == "File": 479 - print(f".. _{ref[1]}:\n") 477 + msg += f".. _{ref[1]}:\n\n" 480 478 else: 481 479 base = os.path.basename(ref[0]) 482 - print(f"Defined on file :ref:`{base} <{ref[1]}>`\n") 480 + msg += f"Defined on file :ref:`{base} <{ref[1]}>`\n\n" 483 481 484 482 if wtype == "File": 485 - print(f"{names[0]}\n{"-" * len(names[0])}\n") 483 + msg += f"{names[0]}\n{"-" * len(names[0])}\n\n" 486 484 487 485 desc = v.get("description") 488 486 if not desc and wtype != "File": 489 - print(f"DESCRIPTION MISSING for {names[0]}\n") 487 + msg += f"DESCRIPTION MISSING for {names[0]}\n\n" 490 488 491 489 if desc: 492 490 if output_in_txt: 493 - self.print_desc_txt(desc) 491 + msg += self.desc_txt(desc) 494 492 else: 495 - self.print_desc_rst(desc) 493 + msg += self.desc_rst(desc) 496 494 497 495 symbols = v.get("symbols") 498 496 if symbols: 499 - print("Has the following ABI:\n") 497 + msg += "Has the following ABI:\n\n" 500 498 501 499 for w, label in symbols: 502 500 # Escape special chars from content 503 501 content = self.re_escape.sub(r"\\\1", w) 504 502 505 - print(f"- :ref:`{content} <{label}>`\n") 503 + msg += f"- :ref:`{content} <{label}>`\n\n" 506 504 507 505 users = v.get("users") 508 506 if users and users.strip(" \t\n"): 509 - print(f"Users:\n\t{users.strip("\n").replace('\n', '\n\t')}\n") 507 + msg += f"Users:\n\t{users.strip("\n").replace('\n', '\n\t')}\n\n" 508 + 509 + yield msg 510 510 511 511 def check_issues(self): 512 512 """Warn about duplicated ABI entries"""