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
This commit is contained in:
parent
484e9aa6ef
commit
6b48bea168
|
|
@ -85,6 +85,29 @@ class AbiValidate:
|
|||
parser.check_issues()
|
||||
|
||||
|
||||
class AbiSearch:
|
||||
"""Initialize an argparse subparser for ABI search"""
|
||||
|
||||
def __init__(self, subparsers):
|
||||
"""Initialize argparse subparsers"""
|
||||
|
||||
parser = subparsers.add_parser("search",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
description="Search ABI using a regular expression")
|
||||
|
||||
parser.add_argument("expression",
|
||||
help="Case-insensitive search pattern for the ABI symbol")
|
||||
|
||||
parser.set_defaults(func=self.run)
|
||||
|
||||
def run(self, args):
|
||||
"""Run subparser"""
|
||||
|
||||
parser = AbiParser(args.dir, debug=args.debug)
|
||||
parser.parse_abi()
|
||||
parser.search_symbols(args.expression)
|
||||
|
||||
|
||||
def main():
|
||||
"""Main program"""
|
||||
|
||||
|
|
@ -97,6 +120,7 @@ def main():
|
|||
|
||||
AbiRest(subparsers)
|
||||
AbiValidate(subparsers)
|
||||
AbiSearch(subparsers)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
|
|
|||
|
|
@ -510,3 +510,55 @@ class AbiParser:
|
|||
f.append(f"{fname} lines {", ".join(str(x) for x in lines)}")
|
||||
|
||||
self.log.warning("%s is defined %d times: %s", what, len(f), "; ".join(f))
|
||||
|
||||
def search_symbols(self, expr):
|
||||
""" Searches for ABI symbols """
|
||||
|
||||
regex = re.compile(expr, re.I)
|
||||
|
||||
found_keys = 0
|
||||
for t in sorted(self.data.items(), key=lambda x: [0]):
|
||||
v = t[1]
|
||||
|
||||
wtype = v.get("type", "")
|
||||
if wtype == "File":
|
||||
continue
|
||||
|
||||
for what in v.get("what", [""]):
|
||||
if regex.search(what):
|
||||
found_keys += 1
|
||||
|
||||
kernelversion = v.get("kernelversion", "").strip(" \t\n")
|
||||
date = v.get("date", "").strip(" \t\n")
|
||||
contact = v.get("contact", "").strip(" \t\n")
|
||||
users = v.get("users", "").strip(" \t\n")
|
||||
desc = v.get("description", "").strip(" \t\n")
|
||||
|
||||
files = []
|
||||
for f in v.get("file", ()):
|
||||
files.append(f[0])
|
||||
|
||||
what = str(found_keys) + ". " + what
|
||||
title_tag = "-" * len(what)
|
||||
|
||||
print(f"\n{what}\n{title_tag}\n")
|
||||
|
||||
if kernelversion:
|
||||
print(f"Kernel version:\t\t{kernelversion}")
|
||||
|
||||
if date:
|
||||
print(f"Date:\t\t\t{date}")
|
||||
|
||||
if contact:
|
||||
print(f"Contact:\t\t{contact}")
|
||||
|
||||
if users:
|
||||
print(f"Users:\t\t\t{users}")
|
||||
|
||||
print(f"Defined on file{'s'[:len(files) ^ 1]}:\t{", ".join(files)}")
|
||||
|
||||
if desc:
|
||||
print(f"\n{desc.strip("\n")}\n")
|
||||
|
||||
if not found_keys:
|
||||
print(f"Regular expression /{expr}/ not found.")
|
||||
|
|
|
|||
Loading…
Reference in New Issue