"""Recompute docs/port/MANIFEST.tsv status: 'ported' for every game address cited in port sources (`// game @0x...`) and in lines added by tools/port/thirdparty/*.patch, 'verified' for addresses listed in docs/port/verified/*.txt (one file per area, written when its differential test passes). Prints totals per layer.""" import collections, glob, os, re ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) cited = set() for path in glob.glob(os.path.join(ROOT, 'port', '**', '*.*'), recursive=True): if path.endswith(('.cpp', '.h', '.c', '.mm')): for m in re.finditer(r'game @0x([0-9a-fA-F]+)', open(path, errors='replace').read()): cited.add(int(m.group(1), 16)) # third-party patches (e.g. the game's LuaPlus/Lua): only lines the patch adds count for path in glob.glob(os.path.join(ROOT, 'tools/port/thirdparty/*.patch')): for line in open(path, errors='replace'): if line.startswith('+'): for m in re.finditer(r'game @0x([0-9a-fA-F]+)', line): cited.add(int(m.group(1), 16)) verified = set() for path in glob.glob(os.path.join(ROOT, 'docs/port/verified/*.txt')): for line in open(path): line = line.split('#')[0].strip() if line: verified.add(int(line.split()[0], 16)) p = os.path.join(ROOT, 'docs/port/MANIFEST.tsv') rows = open(p).read().rstrip('\n').split('\n') out = [rows[0]] tally = collections.Counter(); total = collections.Counter() for r in rows[1:]: c = r.split('\t') a = int(c[0], 16) c[6] = 'verified' if a in verified else ('ported' if a in cited else 'todo') tally[(c[2], c[6])] += 1; total[c[2]] += 1 out.append('\t'.join(c)) open(p, 'w').write('\n'.join(out) + '\n') for layer in sorted(total): print(f"{layer:10s} total {total[layer]:5d} verified {tally[(layer,'verified')]:5d} ported {tally[(layer,'ported')]:5d}")