Files
ARCADIA-Studio/harness/experiments/compact-help-20261001/package/launch-native.py
T

34 lines
2.2 KiB
Python

from pathlib import Path
import datetime, hashlib, json, os, platform, subprocess
root = Path(__file__).resolve().parent
record = json.loads((root / 'extraction-check.json').read_text())
bundle = Path(record['bundle'])
run = root / 'native'
work = root / 'working'
sha = lambda p: hashlib.sha256(p.read_bytes()).hexdigest()
def inventory(p):
return {f.relative_to(p).as_posix(): sha(f) for f in p.rglob('*') if f.is_file()}
baseline = inventory(work / 'release1')
with (run / 'baseline.json').open('x', encoding='utf-8') as f:
json.dump(baseline, f, indent=2)
env = os.environ.copy()
system = os.environ['SystemRoot']
env['PATH'] = str(Path(system) / 'System32') + ';' + system
for key in list(env):
if key.startswith(('CARGO_', 'RUST', 'LLVM', 'WGPU', 'ARCADIA_')):
del env[key]
cmd = [str(bundle / 'arcadia-studio.exe')]
assert sha(Path(cmd[0])) == record['sha256']['arcadia-studio.exe']
assert sha(bundle / 'libunwind.dll') == record['sha256']['libunwind.dll']
receipt = {'source': '6e7c4ddaf0775198384a8c4882809ea8e14b2976', 'package_source': 'ea23e229260d7d050b3c3b88e77c3a851e936abe', 'start': datetime.datetime.now(datetime.timezone.utc).isoformat(), 'command': cmd, 'cwd': str(work), 'path': env['PATH'], 'platform': platform.platform(), 'binary_sha256': sha(Path(cmd[0])), 'runtime_sha256': sha(bundle / 'libunwind.dll')}
with (run / 'stdout.log').open('xb') as out, (run / 'stderr.log').open('xb') as err:
child = subprocess.Popen(cmd, cwd=work, env=env, stdout=out, stderr=err, creationflags=subprocess.CREATE_NO_WINDOW)
receipt['pid'] = child.pid
(run / 'started.json').write_text(json.dumps(receipt, indent=2)+'\n', encoding='utf-8')
print(json.dumps(receipt, indent=2), flush=True)
code = child.wait()
receipt.update({'exit_code': code, 'finished': datetime.datetime.now(datetime.timezone.utc).isoformat(), 'stdout_bytes': (run / 'stdout.log').stat().st_size, 'stderr_bytes': (run / 'stderr.log').stat().st_size, 'package_files_unchanged': inventory(bundle) == record['sha256']})
(run / 'finished.json').write_text(json.dumps(receipt, indent=2)+'\n', encoding='utf-8')
print(json.dumps(receipt, indent=2), flush=True)
assert code == 0 and receipt['stdout_bytes'] == receipt['stderr_bytes'] == 0 and receipt['package_files_unchanged']