#!/usr/bin/env python3 """ Compare two symbol JSON files produced by collect_symbols.py. Usage: compare_symbols.py Output: + [module] symbol — new build adds a required symbol the old build did not have - [module] symbol — new build drops a required symbol the old build had Exit codes: 0 — no differences 1 — differences found """ import json import sys from pathlib import Path old = json.loads(Path(sys.argv[1]).read_text()) new = json.loads(Path(sys.argv[2]).read_text()) all_mods = sorted(set(old) | set(new)) changes = [] for mod in all_mods: added = sorted(set(new.get(mod, [])) - set(old.get(mod, []))) removed = sorted(set(old.get(mod, [])) - set(new.get(mod, []))) if added or removed: changes.append((mod, added, removed)) if not changes: print("OK: no symbol changes between stable and PR build") sys.exit(0) print("Symbol changes detected (+ new requirement in PR build, - dropped by PR build):") for mod, added, removed in changes: for sym in added: print(f" + [{mod}] {sym}") for sym in removed: print(f" - [{mod}] {sym}") sys.exit(1)