Branchwell

PulseCanvas / app · pulsecanvas.ai / scripts / verify-vision-bundle.py

Raw 2.0 KB on 23ffa4e102ea595ec83f2b18683b75332fc815c3
1#!/usr/bin/env python3
2"""Verify a locally generated, native-only visionOS app payload."""
3import argparse
4import hashlib
5import json
6import plistlib
7import subprocess
8from pathlib import Path
9
10parser = argparse.ArgumentParser(description=__doc__)
11parser.add_argument('app', type=Path)
12args = parser.parse_args()
13root = Path(__file__).resolve().parents[1]
14app = args.app
15info = plistlib.loads((app / 'Info.plist').read_bytes())
16assert info['CFBundleIdentifier'] == 'com.protomota.pulsecanvas'
17assert info['UIDeviceFamily'] == [7]
18assert not (app / 'Resources').exists(), 'Flat visionOS bundle must not use the legacy Resources layout'
19payload = app / 'NativeAssets'
20source = root / 'Sources/PulseCanvas/Resources'
21expected = {x.name for x in source.glob('*.metal')} | {'Audio/PulseCanvas.mp3', 'NativeVisualizers.json'}
22actual = {x.relative_to(payload).as_posix() for x in payload.rglob('*') if x.is_file()}
23assert actual == expected
24for relative in expected - {'NativeVisualizers.json'}:
25 assert (payload / relative).read_bytes() == (source / relative).read_bytes(), relative
26catalog = json.loads((payload / 'NativeVisualizers.json').read_text())
27assert catalog == json.loads((source / 'NativeVisualizers.json').read_text())
28assert (app / 'Legal/PulseCanvas-LICENSE.txt').read_bytes() == (root / 'LICENSE').read_bytes()
29assert (app / 'PrivacyInfo.xcprivacy').read_bytes() == (root / 'macOS/PrivacyInfo.xcprivacy').read_bytes()
30assert not any(x.suffix.lower() in {'.milk', '.dylib'} or 'projectm' in x.name.lower()
31 or 'sparkle' in x.name.lower() for x in app.rglob('*'))
32links = subprocess.check_output(['otool', '-L', str(app / info['CFBundleExecutable'])], text=True)
33assert not any(x in links.lower() for x in ['projectm', 'sparkle', 'opengl'])
34print(json.dumps(dict(nativeEffects=catalog['activeCount'], shaderFiles=len(expected)-2,
35 exactNativeBytes=True, noExternalEngineOrAssets=True, legalAndPrivacy=True,
36 executableSHA256=hashlib.sha256((app / info['CFBundleExecutable']).read_bytes()).hexdigest()), indent=2))