32 lines
1.2 KiB
Python
Executable File
32 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Verify that every literal "Namespace:Tag" used in the sources exists in the WBXML code pages.
|
|
|
|
Element::new() panics on unknown names at runtime; this catches typos at build time.
|
|
"""
|
|
import pathlib
|
|
import re
|
|
import sys
|
|
|
|
root = pathlib.Path(__file__).resolve().parent.parent
|
|
cp = (root / "src/wbxml/codepages.rs").read_text()
|
|
namespaces = re.findall(r'"([^"]+)"', re.search(r"NAMESPACES: &\[&str\] = &\[(.*?)\];", cp, re.S).group(1))
|
|
body = cp[cp.index("pub const PAGES"):]
|
|
known = set()
|
|
for i, chunk in enumerate(re.split(r"\n\s*// \d+ \w+\n", body)[1:]):
|
|
for tag in re.findall(r'\(0x[0-9A-Fa-f]+,\s*"([^"]+)"\)', chunk):
|
|
known.add(f"{namespaces[i]}:{tag}")
|
|
|
|
pattern = re.compile(r'"((?:%s):[A-Za-z0-9]+)"' % "|".join(re.escape(n) for n in namespaces))
|
|
bad = []
|
|
for f in (root / "src").rglob("*.rs"):
|
|
if f.name == "codepages.rs":
|
|
continue
|
|
for n, line in enumerate(f.read_text().splitlines(), 1):
|
|
for m in pattern.finditer(line):
|
|
if m.group(1) not in known:
|
|
bad.append(f"{f.relative_to(root)}:{n}: {m.group(1)}")
|
|
if bad:
|
|
print("Unknown WBXML tag names:\n " + "\n ".join(bad))
|
|
sys.exit(1)
|
|
print(f"WBXML names: OK ({len(known)} known tags)")
|