Debian Codegraph @

test/symbols-leak-test.py

raw
1 #!/usr/bin/env python3
2 """Check that all exported symbols are specified in the symbol version scripts.
3
4 If this fails, please update the appropriate .map file (adding new version
5 nodes as needed).
6 """
7
8 import os
9 import pathlib
10 import re
11 import sys
12
13
14 top_srcdir = pathlib.Path(os.environ["top_srcdir"])
15
16
17 def symbols_from_map(path):
18 return re.findall(r"^\s+(xkb_.*);", path.read_text("utf-8"), re.MULTILINE)
19
20
21 def symbols_from_src(path):
22 return re.findall(r"\bXKB_EXPORT\b.*\n(xkb_.*)\(", path.read_text("utf-8"))
23
24
25 def diff(map_path, src_paths):
26 map_symbols = set(symbols_from_map(map_path))
27 src_symbols = set.union(set(), *(symbols_from_src(path) for path in src_paths))
28 return sorted(map_symbols - src_symbols), sorted(src_symbols - map_symbols)
29
30
31 exit = 0
32
33 # xkbcommon symbols
34 left, right = diff(
35 top_srcdir / "xkbcommon.map",
36 [
37 top_srcdir / "include/xkbcommon/xkbcommon.h",
38 top_srcdir / "include/xkbcommon/xkbcommon-compose.h",
39 ],
40 )
41 if left:
42 print("xkbcommon map has extra symbols:", " ".join(left))
43 exit = 1
44 if right:
45 print("xkbcommon src has extra symbols:", " ".join(right))
46 exit = 1
47
48 # xkbcommon-x11 symbols
49 left, right = diff(
50 top_srcdir / "xkbcommon-x11.map",
51 [
52 top_srcdir / "include/xkbcommon/xkbcommon-x11.h",
53 ],
54 )
55 if left:
56 print("xkbcommon-x11 map has extra symbols:", " ".join(left))
57 exit = 1
58 if right:
59 print("xkbcommon-x11 src has extra symbols:", " ".join(right))
60 exit = 1
61
62 sys.exit(exit)