interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tools / adapters / build-python-export.py

36 lines · 2888 bytes Raw Blame History
1#!/usr/bin/env python3
2"""Host build orchestration only; all exporter computation is seeded Omega (#627)."""
3from pathlib import Path
4import hashlib,json,os,struct,subprocess,tempfile
5ROOT=Path(__file__).resolve().parents[2]
6build=ROOT/'build/L627/export'
7for p in [ROOT/'build',ROOT/'build/L627',build]:
8 if p.is_symlink():raise SystemExit('PY_EXPORT_UNSAFE_BUILD_PATH')
9build.mkdir(parents=True,exist_ok=True)
10# Same source-only #621 construction path and pinned bridge-seed compiler as the C importer.
11subprocess.run(['bash','tools/source-aware/build'],cwd=ROOT,check=True,timeout=600,stdout=subprocess.PIPE)
12compiler=ROOT/'build/L574/toolchain/build/bootstrap/omc'
13verifier=ROOT/'build/L574/toolchain/tools/verify-elf.sh'
14expected='191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9'
15assert compiler.is_file() and hashlib.sha256(compiler.read_bytes()).hexdigest()==expected,'PY_EXPORT_COMPILER_PIN_MISMATCH'
16# Unchanged reviewed #621 SHA256 vendor and decoder core (envelope validation), then the exporter.
17parts=[ROOT/'src/source-aware/vendor/sha256.om',ROOT/'src/source-aware/core.om',ROOT/'src/adapters/python-u64-export.om']
18program=b'\n'.join(p.read_bytes() for p in parts)+b'\n'
19subprocess.run(['sha256sum','-c','tools/source-aware/imports.sha256'],cwd=ROOT,check=True,stdout=subprocess.PIPE)
20result=subprocess.run([str(compiler)],input=program,capture_output=True,timeout=60)
21if result.returncode:raise SystemExit('PY_EXPORT_COMPILE_FAILED: '+result.stderr.decode(errors='replace'))
22binary=result.stdout
23assert len(binary)>64 and binary[:4]==b'\x7fELF' and struct.unpack_from('<HH',binary,16)==(2,183),'PY_EXPORT_NOT_AARCH64_EXEC'
24report={'schema':'omega.python-u64-export.build.v1','profile':'spec/universal/python-u64-v1.md','compiler_sha256':expected,
25 'compiler_choice':'bridge-seed omc 191b776e, the pinned compiler of the C importer/exporter and the #621 codec whose decode core is prepended unchanged',
26 'seed_source_archive':'0fc7d8662cb799e7c206b17c18ea4c3ec2b8fea9','birth_seed':'29b12760',
27 'inputs':{p.relative_to(ROOT).as_posix():hashlib.sha256(p.read_bytes()).hexdigest() for p in parts},
28 'combined_source_sha256':hashlib.sha256(program).hexdigest(),'binary_sha256':hashlib.sha256(binary).hexdigest(),
29 'host_orchestration':'Python process/filesystem only; no Python generator, ast module or compute fallback in the native artifact'}
30with tempfile.TemporaryDirectory(prefix='.python-export-build-',dir=build) as temp:
31 t=Path(temp)
32 (t/'program.om').write_bytes(program);(t/'python-export').write_bytes(binary);(t/'python-export').chmod(0o700)
33 subprocess.run(['sh',str(verifier),str(t/'python-export')],check=True)
34 (t/'build.json').write_text(json.dumps(report,indent=2)+'\n')
35 for name in ['program.om','python-export','build.json']:os.replace(t/name,build/name)
36print(build/'python-export')