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/get_abi.py: add support for symbol search

Add support for searching symbols from Documentation/ABI using
regular expressions to match the symbols' names.

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

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
6b48bea1 484e9aa6

+76
+24
scripts/get_abi.py
··· 85 85 parser.check_issues() 86 86 87 87 88 + class AbiSearch: 89 + """Initialize an argparse subparser for ABI search""" 90 + 91 + def __init__(self, subparsers): 92 + """Initialize argparse subparsers""" 93 + 94 + parser = subparsers.add_parser("search", 95 + formatter_class=argparse.ArgumentDefaultsHelpFormatter, 96 + description="Search ABI using a regular expression") 97 + 98 + parser.add_argument("expression", 99 + help="Case-insensitive search pattern for the ABI symbol") 100 + 101 + parser.set_defaults(func=self.run) 102 + 103 + def run(self, args): 104 + """Run subparser""" 105 + 106 + parser = AbiParser(args.dir, debug=args.debug) 107 + parser.parse_abi() 108 + parser.search_symbols(args.expression) 109 + 110 + 88 111 def main(): 89 112 """Main program""" 90 113 ··· 120 97 121 98 AbiRest(subparsers) 122 99 AbiValidate(subparsers) 100 + AbiSearch(subparsers) 123 101 124 102 args = parser.parse_args() 125 103
+52
scripts/lib/abi/abi_parser.py
··· 510 510 f.append(f"{fname} lines {", ".join(str(x) for x in lines)}") 511 511 512 512 self.log.warning("%s is defined %d times: %s", what, len(f), "; ".join(f)) 513 + 514 + def search_symbols(self, expr): 515 + """ Searches for ABI symbols """ 516 + 517 + regex = re.compile(expr, re.I) 518 + 519 + found_keys = 0 520 + for t in sorted(self.data.items(), key=lambda x: [0]): 521 + v = t[1] 522 + 523 + wtype = v.get("type", "") 524 + if wtype == "File": 525 + continue 526 + 527 + for what in v.get("what", [""]): 528 + if regex.search(what): 529 + found_keys += 1 530 + 531 + kernelversion = v.get("kernelversion", "").strip(" \t\n") 532 + date = v.get("date", "").strip(" \t\n") 533 + contact = v.get("contact", "").strip(" \t\n") 534 + users = v.get("users", "").strip(" \t\n") 535 + desc = v.get("description", "").strip(" \t\n") 536 + 537 + files = [] 538 + for f in v.get("file", ()): 539 + files.append(f[0]) 540 + 541 + what = str(found_keys) + ". " + what 542 + title_tag = "-" * len(what) 543 + 544 + print(f"\n{what}\n{title_tag}\n") 545 + 546 + if kernelversion: 547 + print(f"Kernel version:\t\t{kernelversion}") 548 + 549 + if date: 550 + print(f"Date:\t\t\t{date}") 551 + 552 + if contact: 553 + print(f"Contact:\t\t{contact}") 554 + 555 + if users: 556 + print(f"Users:\t\t\t{users}") 557 + 558 + print(f"Defined on file{'s'[:len(files) ^ 1]}:\t{", ".join(files)}") 559 + 560 + if desc: 561 + print(f"\n{desc.strip("\n")}\n") 562 + 563 + if not found_keys: 564 + print(f"Regular expression /{expr}/ not found.")