52 lines
3.4 KiB
Python
52 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Method-name comparison against active AVA2 Windows extension tables.
|
|
Presence is not behavioral parity. Macros use ONLY AVA2 Windows headers.
|
|
"""
|
|
from pathlib import Path
|
|
import re,json,subprocess,sys
|
|
root=Path(__file__).resolve().parents[1]
|
|
compiler=sys.argv[1] if len(sys.argv)>1 else 'clang++'
|
|
headers=''.join(f'#include "{root/p}"\n' for p in ('upstream/ava2-client/UserInterface/Locale_inc.h','upstream/ava2-client/EterBase/ServiceDefs.h'))
|
|
def modules(paths,preprocess=False):
|
|
result={}
|
|
for path in paths:
|
|
source=path.read_text(errors='replace')
|
|
if preprocess:
|
|
source=re.sub(r'^\s*#\s*include[^\n]*','',source,flags=re.M)
|
|
source=source.replace('#pragma once','')
|
|
source=subprocess.check_output([compiler,'-E','-P','-x','c++','-'],input=headers+source,text=True,stderr=subprocess.DEVNULL)
|
|
tables=list(re.finditer(r'PyMethodDef\s+(\w+)\s*\[\s*\]\s*=\s*\{(.*?)\};',source,re.S))
|
|
for call in re.finditer(r'Py_InitModule\s*\(\s*"([^"\n]+)"\s*,\s*(\w+)',source):
|
|
candidates=[t for t in tables if t[1]==call[2] and t.start()<call.start()]
|
|
if not candidates: continue
|
|
methods={name:handler for name,handler in re.findall(r'\{\s*"([^"\n]+)"\s*,\s*(\w+(?:<[^>{}]*>)?)\s*,',candidates[-1][2])}
|
|
if call[1] in result:
|
|
result[call[1]]['methods'].update(methods)
|
|
else:
|
|
result[call[1]]={'path':str(path.relative_to(root)),'methods':methods}
|
|
return result
|
|
# Only translation units listed in AVA2's Windows build are reference modules.
|
|
# Orphan .cpp files (e.g. guild_ranking) do not define the shipped client API.
|
|
import xml.etree.ElementTree as ET
|
|
compiled=set()
|
|
for project in (root/'upstream/ava2-client').rglob('*.vcxproj'):
|
|
for node in ET.parse(project).getroot().iter():
|
|
if node.tag.rsplit('}',1)[-1]=='ClCompile' and 'Include' in node.attrib:
|
|
compiled.add((project.parent/node.attrib['Include'].replace('\\','/')).resolve())
|
|
reference_paths=[p for p in sorted(compiled) if p.is_file() and
|
|
re.search(r'\bPy_InitModule\s*\(',p.read_text(errors='replace'))]
|
|
windows=modules(reference_paths,True)
|
|
port_paths=sorted((root/'src/scripting').glob('python_*.cpp'))
|
|
if not port_paths:
|
|
raise SystemExit('No port translation units found; check the source layout before auditing')
|
|
port=modules(port_paths)
|
|
rows=[]
|
|
for name,reference in sorted(windows.items()):
|
|
target=port.get(name,{'methods':{}});original=set(reference['methods']);current=set(target['methods'])
|
|
rows.append({'module':name,'windows_file':reference['path'],'port_file':target.get('path'),'windows_methods':len(original),'missing':sorted(original-current),'extra':sorted(current-original),'placeholder':sorted(method for method in original¤t if 'dummy' in target['methods'][method])})
|
|
report={'basis':'AVA2 Windows project-compiled active method tables; module constants/signatures/behavior require further audit','modules':rows,'missing_method_count':sum(len(r['missing']) for r in rows),'placeholder_method_count':sum(len(r['placeholder']) for r in rows)}
|
|
(root/'docs/AVA2-PYTHON-INTERFACES.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
print(f"{len(rows)} Windows modules compared; {report['missing_method_count']} missing methods; {report['placeholder_method_count']} overlapping placeholder methods")
|
|
for row in rows:
|
|
if row['missing']: print(row['module'],len(row['missing']),', '.join(row['missing'][:8]))
|