PulseCanvas / app · pulsecanvas.ai / scripts / verify-native-artifact.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Verify a native-only app's bundled Metal catalog against the current sources.""" |
| 3 | import hashlib |
| 4 | import json |
| 5 | import plistlib |
| 6 | import subprocess |
| 7 | import sys |
| 8 | from pathlib import Path |
| 9 | |
| 10 | app = Path(sys.argv[1]).resolve() |
| 11 | flat = (app / 'NativeAssets').is_dir() |
| 12 | resources = app / ('NativeAssets' if flat else 'Contents/Resources/Resources') |
| 13 | catalog = json.loads((resources / 'NativeVisualizers.json').read_text()) |
| 14 | expected = json.loads(subprocess.check_output([sys.executable, 'scripts/native-visualizer-catalog.py'], text=True)) |
| 15 | assert catalog == expected, 'Bundled catalog does not match the current source' |
| 16 | for name, digest in catalog['shaders'].items(): |
| 17 | assert hashlib.sha256((resources / name).read_bytes()).hexdigest() == digest, name |
| 18 | assert hashlib.sha256((Path('Sources/PulseCanvas/Resources') / name).read_bytes()).hexdigest() == digest, name |
| 19 | bundled = list(app.rglob('PulseCanvas.mp3')) |
| 20 | assert len(bundled) == 1 |
| 21 | source = Path('Sources/PulseCanvas/Resources/Audio/PulseCanvas.mp3') |
| 22 | digest = hashlib.sha256(source.read_bytes()).hexdigest() |
| 23 | assert hashlib.sha256(bundled[0].read_bytes()).hexdigest() == digest, 'Bundled soundtrack changed' |
| 24 | assert not any(app.rglob('*.milk')) and not any(app.rglob('*projectM*.dylib')) |
| 25 | info = plistlib.loads((app / ('Info.plist' if flat else 'Contents/Info.plist')).read_bytes()) |
| 26 | executables = app if flat else app / 'Contents/MacOS' |
| 27 | executable = executables / info['CFBundleExecutable'] |
| 28 | assert executable.is_file() |
| 29 | for binary in [executable, *executables.glob('*.dylib')]: |
| 30 | libraries = subprocess.check_output(['otool', '-L', str(binary)], text=True) |
| 31 | assert 'OpenGL' not in libraries and 'projectM' not in libraries, binary |
| 32 | receipt = {'activeDesigns': catalog['activeCount'], 'reservedIDs': catalog['nativeCount'], |
| 33 | 'shaderFiles': len(catalog['shaders']), 'app': str(app), 'resourcesMatchSource': True, |
| 34 | 'soundtrackSHA256': digest, 'engineAndPresetAssetsAbsent': True, |
| 35 | 'signing': 'Not assessed; this check does not validate release signing or notarization'} |
| 36 | print(json.dumps(receipt, indent=2)) |