Skip to content

Commit 3c692c7

Browse files
authored
Merge pull request #1174 from jan-cerny/improve_check_api_script
Improve check_public_api.py script
2 parents 31fd82e + 586b923 commit 3c692c7

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

tests/check_public_api.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def get_public_symbols_from_shared_object(prefix):
1919
nm_output_bytes = subprocess.check_output(nm_command)
2020
nm_output = nm_output_bytes.decode(encoding="utf-8")
2121
symbols = {line.split()[2] for line in nm_output.splitlines()}
22+
symbols = symbols.difference({"__bss_start", "_edata", "_end", "_fini",
23+
"_init"})
2224
return symbols
2325

2426

@@ -50,11 +52,17 @@ def get_public_symbols_from_header(header_path):
5052
content = header_file.read()
5153
prototypes = prototype_regex.findall(content)
5254
function_name_regex = re.compile(r"([a-zA-Z0-9_]+)\s*\(.*\)")
55+
data_name_regex = re.compile(r"\s+([a-zA-Z0-9_]+)\s*;")
5356
for p in prototypes:
5457
p = p.replace("\n", " ")
55-
f_match = function_name_regex.search(p)
56-
f_name = f_match.group(1) if f_match else "unknown"
57-
symbols.add(f_name)
58+
match = function_name_regex.search(p)
59+
if not match:
60+
match = data_name_regex.search(p)
61+
if not match:
62+
print("Invalid prototype '%s'" % p, file=sys.stderr)
63+
continue
64+
symbol_name = match.group(1)
65+
symbols.add(symbol_name)
5866
return symbols
5967

6068

@@ -137,17 +145,19 @@ def main():
137145
print()
138146

139147
so_only = so_symbols.difference(header_symbols)
140-
print("The following %d symbols are exported in binary, "
141-
"but are not present in public header files:" % len(so_only))
142-
for s in sorted(so_only):
143-
print(s)
144-
print()
148+
if so_only:
149+
print("The following %d symbols are exported in binary, "
150+
"but are not present in public header files:" % len(so_only))
151+
for s in sorted(so_only):
152+
print(s)
153+
print()
145154

146155
header_only = header_symbols.difference(so_symbols)
147-
print("The following %d symbols are present in public header files, "
148-
"but are not exported in binary:" % len(header_only))
149-
for s in sorted(header_only):
150-
print(s)
156+
if header_only:
157+
print("The following %d symbols are present in public header files, "
158+
"but are not exported in binary:" % len(header_only))
159+
for s in sorted(header_only):
160+
print(s)
151161

152162

153163
if __name__ == "__main__":

0 commit comments

Comments
 (0)