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
omega-mv / tools / adapters / python-export
| 1 | #!/usr/bin/env python3 |
| 2 | """Transparent host dispatch; validation and Python generation run in seeded native Omega (#627). |
| 3 | Usage: python-export [NAME] < unit.upper > unit.py (NAME rules are checked natively).""" |
| 4 | from pathlib import Path |
| 5 | import hashlib,json,subprocess,sys |
| 6 | root=Path(__file__).resolve().parents[2] |
| 7 | INPUTS={'src/source-aware/vendor/sha256.om','src/source-aware/core.om','src/adapters/python-u64-export.om'} |
| 8 | name=sys.argv[1].encode() if len(sys.argv)==2 else b'' |
| 9 | if len(sys.argv)>2 or (len(sys.argv)==2 and not 1<=len(name)<=255): |
| 10 | print('PY_EXPORT_BAD_COMMAND: use python-export [NAME] with the envelope on stdin',file=sys.stderr);raise SystemExit(64) |
| 11 | try: |
| 12 | build=root/'build/L627/export';m=json.loads((build/'build.json').read_text());exe=build/'python-export' |
| 13 | if m['compiler_sha256']!='191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9':raise ValueError('compiler identity') |
| 14 | if set(m['inputs'])!=INPUTS:raise ValueError('source closure') |
| 15 | for rel,digest in m['inputs'].items(): |
| 16 | if hashlib.sha256((root/rel).read_bytes()).hexdigest()!=digest:raise ValueError('changed source') |
| 17 | if hashlib.sha256(exe.read_bytes()).hexdigest()!=m['binary_sha256']:raise ValueError('changed artifact') |
| 18 | except (OSError,ValueError,KeyError) as exc: |
| 19 | print('PY_EXPORT_STALE_OR_MISSING_BUILD: '+str(exc),file=sys.stderr);raise SystemExit(78) |
| 20 | # Frame: one name-length byte (0 = default calc), the name bytes, then stdin to EOF. |
| 21 | r=subprocess.run([str(exe)],input=bytes([len(name)])+name+sys.stdin.buffer.read(),stdout=subprocess.PIPE) |
| 22 | if r.returncode==0:sys.stdout.buffer.write(r.stdout);sys.stdout.buffer.flush() |
| 23 | raise SystemExit(r.returncode) |