Files
mesh/scripts/test_saved_ir.py
T
waozi 143a2294a6 Generate the Go at build time instead of committing it
The 202 Go files zi2go makes from the Zi sources are no longer kept in
Git. They are written as .zi.go and .zi_test.go, which .gitignore leaves
out, and make build, test and run regenerate them when a source or
ziran.lock changes. CI, the security checks and the deploy build the
pinned Ziran (cached by commit) and generate the Go before any Go build;
the deploy still ships the generated tree to the origin, which only
compiles it. The pin moves to the current Ziran, whose output matches.
2026-10-24 03:19:26 -03:00

43 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Run the real server suite against Go regenerated from saved Ziran IR."""
import json
import os
from pathlib import Path
import subprocess
import tempfile
from generate_go import generate_go, project_flags, repo_name
def main():
repo = Path(__file__).resolve().parent.parent
ziran = os.environ.get("ZIRAN", "ziran")
sources = sorted(path.name for path in repo.glob("*.zi"))
env = os.environ.copy()
env.pop("DISPLAY", None)
env.pop("WAYLAND_DISPLAY", None)
env["LDLIBS"] = "-loqs"
build = repo / "build"
build.mkdir(exist_ok=True)
env.setdefault("XDG_CACHE_HOME", str(build / "package-cache"))
with tempfile.TemporaryDirectory(prefix="saved-ir-", dir=build) as output:
work = Path(output)
ir = work / "ir"
generated = work / "go"
subprocess.run([ziran, "ir", *project_flags(repo),
"-o", str(ir), *sources], cwd=repo, env=env, check=True)
entries = [str(ir / Path(source).with_suffix(".zir")) for source in sources]
generate_go(ziran, repo, entries, generated, env, source_root=ir)
replacement = {str(repo / repo_name(path.name)): str(path)
for path in generated.glob("*.go")}
overlay = work / "overlay.json"
overlay.write_text(json.dumps({"Replace": replacement}))
subprocess.run([os.environ.get("GO", "go"), "test", "-count=1", "-overlay", str(overlay), "."],
cwd=repo, env=env, check=True)
print("Server tests against saved Ziran IR: passed")
if __name__ == "__main__":
main()