1"""Inventory production dependencies; preserve file/line evidence for migration."""
2from pathlib import Path
3from collections import Counter
4import csv
5import json
6import re
7import subprocess
8
9ROOT = Path(__file__).resolve().parents[1]
10TOKENS = re.compile(r'\b(?:IDirect3D\w*|LPDIRECT3D\w*|ID3DX\w*|LPD3DX\w*|D3DX\w+|DXUT\w+|D3D(?:RS|TSS|SAMP|FMT|FVF|POOL|USAGE|PT|LOCK|QUERYTYPE)_\w+|NvidiaDepthCopy|NVAPI|INTZ|RESZ)\b')
11
12
13def main():
14 paths = sorted(set(subprocess.check_output(['git', 'ls-files', '--cached', '--others', '--exclude-standard', '*.cpp', '*.h', '*.fx', '*.fxh', '*.vcxproj'], cwd=ROOT, text=True).splitlines()))
15 rows = []
16 summary = Counter()
17 for filename in paths:
18 if filename.startswith(('Tests/', 'ThirdParty/')) or not (ROOT / filename).is_file():
19 continue
20 block_comment = False
21 for number, original in enumerate((ROOT / filename).read_text(errors='replace').splitlines(), 1):
22
23
24 text = original
25 if block_comment:
26 if '*/' not in text:
27 continue
28 text = text.split('*/', 1)[1]
29 block_comment = False
30 while '/*' in text:
31 before, after = text.split('/*', 1)
32 if '*/' not in after:
33 text = before
34 block_comment = True
35 break
36 text = before + after.split('*/', 1)[1]
37 text = text.split('//', 1)[0]
38 symbols = sorted(set(TOKENS.findall(text)))
39 if symbols:
40 summary[filename] += 1
41 rows.append((filename, number, ';'.join(symbols), original.strip()))
42 destination = ROOT / 'docs/direct3d11-audit.csv'
43 with destination.open('w', newline='', encoding='utf-8') as output:
44 writer = csv.writer(output)
45 writer.writerow(('file', 'line', 'legacy_dependencies', 'source'))
46 writer.writerows(rows)
47 (ROOT / 'outputs/direct3d11/audit-summary.json').write_text(json.dumps({
48 'files': len(summary), 'sites': len(rows), 'by_file': dict(summary.most_common()),
49 'note': 'Symbol inventory, not a DLL-dependency report. Conditional paths retained; Tests and vendored ThirdParty code excluded. Remaining DXUTSETTINGSDLG names are numeric control IDs; D3DX_BC flags name the vendored CPU texture codec.'
50 }, indent=2) + '\n')
51 print(f'{len(summary)} production files, {len(rows)} legacy dependency sites: {destination}')
52
53
54if __name__ == '__main__':
55 main()