vinix-ports / ports / vpac / check-config.py
35 lines · 34 sloc · 1.74 KB · c33d8afc2906b8dd9a8b905224eccd49a44f7ad5
Raw
1"""Exercise the target binary's bundled Vile resources and real installed database queries."""
2import os
3from pathlib import Path
4import json
5import subprocess
6import tempfile
7
8root = Path(os.environ["VPAC_MAKEPKG_ROOT"])
9db = Path(os.environ["VPAC_MAKEPKG_DB"])
10exe = Path("vpac-target").resolve()
11with tempfile.TemporaryDirectory() as directory:
12 work = Path(directory)
13 # Debug V builds read Scheme files from the compiler checkout. Temporarily move
14 # those build inputs so only a self-contained release executable can pass.
15 moved = []
16 try:
17 for resource in (Path("vpac-src/src/config_objects.scm"), Path("modules/vile/scheme/goops_protocol.scm")):
18 hidden = resource.with_suffix(".scm.hidden")
19 resource.rename(hidden)
20 moved.append((hidden, resource))
21 contents = Path("config.vile").read_text()
22 contents = contents.replace('path-root = "/"', "path-root = " + json.dumps(str(root) + "/"))
23 contents = contents.replace('path-db = "/var/lib/vpac/"', "path-db = " + json.dumps(str(db) + "/"))
24 config = work / "config.vile"
25 config.write_text(contents)
26 env = os.environ.copy()
27 env.pop("V_RESOURCE_PATH", None)
28 result = subprocess.check_output(["vinix-run", exe, "--config", config, "q", "-F",
29 "name,version,validation", "local/musl"], env=env, text=True)
30 fields = dict(line.split(None, 1) for line in result.splitlines() if len(line.split(None, 1)) == 2)
31 if fields.get("name") != "musl" or fields.get("validation") != "signature":
32 raise RuntimeError(f"target vpac did not query signed musl: {result!r}")
33 finally:
34 for hidden, resource in moved:
35 hidden.rename(resource)
36