#!/usr/bin/env python3 """Build the combined tree in VFHost, verify DWARF/module output, and smoke the owner world.""" from __future__ import annotations import importlib.util import argparse import json import os from pathlib import Path import re import sys ROOT = Path(__file__).resolve().parents[4] SAVED = ROOT / "Saved/Linux/l173" RUNNER_PATH = ROOT / "Standalone/Research/WorldAssemblerM3/Linux172/RunL172Movement.py" def load_l172_runner(): spec = importlib.util.spec_from_file_location("l172_runner", RUNNER_PATH) if spec is None or spec.loader is None: raise RuntimeError(f"could not load L172 harness: {RUNNER_PATH}") module = importlib.util.module_from_spec(spec) sys.modules[spec.name] = module spec.loader.exec_module(module) module.ROOT = ROOT module.OUT = SAVED module.UE_OUT = SAVED / "ue" module.BUILD_OUT = SAVED / "ue/builds" module.BIN_OUT = SAVED / "ue/bin" return module def write_json(path: Path, value) -> None: path.parent.mkdir(parents=True, exist_ok=True) temporary = path.with_suffix(path.suffix + ".tmp") temporary.write_text(json.dumps(value, indent=2, sort_keys=True) + "\n", encoding="utf-8") temporary.replace(path) def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--reuse-prior-build", action="store_true", help="verify the successful full build already logged in Saved/Linux/l173") options = parser.parse_args() SAVED.mkdir(parents=True, exist_ok=True) runner = load_l172_runner() result = {"plugin_root": str(ROOT.resolve())} try: build_log = SAVED / "ue/builds/ubt-l173-combined.log" if options.reuse_prior_build: if not build_log.is_file(): raise RuntimeError(f"prior full build log is missing: {build_log}") restored = json.loads((SAVED / "ue/restored-main-links.json").read_text( encoding="utf-8")) archive_roots = set() for item in restored.get("intermediates_moved", []): moved = Path(item["to"]) if moved.name == "VoxelForge" and "External" in moved.parts: external_index = moved.parts.index("External") archive_roots.add(Path(*moved.parts[:external_index])) archive_roots = [path for path in archive_roots if (path / "External/Build/Linux/x64/UnrealEditor/Development/" "VoxelForge/VoxelWorld.cpp.o").is_file()] if len(archive_roots) != 1: raise RuntimeError(f"expected one archived combined-tree intermediate set: " f"{archive_roots}") runner.INTERMEDIATE = archive_roots[0] dwarf = runner.dwarf_pre_run_gate() runner.INTERMEDIATE = runner.HOST / "Intermediate" build = { **runner.root_info(ROOT), "build_log": str(build_log), "compiled_voxel_world_cpp": True, "dwarf_pre_run_gate": dwarf, "binary": str(SAVED / "ue/bin/l173-combined/" "libUnrealEditor-VoxelForge.so"), "binary_sha256": runner.sha256_file( SAVED / "ue/bin/l173-combined/libUnrealEditor-VoxelForge.so"), "reused_prior_full_build": True, } else: build = runner.build_tree(ROOT, "l173-combined") output = build_log.read_text(encoding="utf-8", errors="replace") if ("Result: Succeeded" not in output or re.search(r"\[\d+/\d+\] Compile VoxelWorld\.cpp", output) is None): raise RuntimeError(f"UE build log lacks a successful VoxelWorld.cpp compile: {build_log}") actor_compiled = re.search(r"Compile .*VoxelForgeLivingPlaneActor\.cpp", output) is not None module_binary = (runner.HOST / "Binaries/Linux/" "libUnrealEditor-VoxelForgeLivingPlane.so") if not actor_compiled or not module_binary.is_file(): raise RuntimeError( "UE build did not compile/link the Living Plane module: " f"actor_compiled={actor_compiled}, module_binary={module_binary.is_file()}; " f"log={build_log}") build["living_plane_actor_compiled"] = actor_compiled build["living_plane_module_binary"] = str(module_binary.resolve()) result["build"] = build write_json(SAVED / "ue/build.json", result) shader_link = runner.HOST_PLUGIN_LINK / "Shaders" if shader_link.exists() or shader_link.is_symlink(): if shader_link.resolve(strict=True) != (ROOT / "Shaders").resolve(strict=True): raise RuntimeError(f"unexpected existing shader link target: {shader_link}") created_shader_link = False else: temporary = shader_link.with_name(f"Shaders.l173-{os.getpid()}.tmp") temporary.symlink_to(ROOT / "Shaders") os.replace(temporary, shader_link) created_shader_link = True smoke = runner.run_trial( "owner-world-smoke", "owner-world-smoke", "default-on", ROOT, Path(build["binary"]), runner.WAIT_ON, runner.APPLY_ON_MS, include_switch_overrides=False) write_json(SAVED / "ue/owner-world-smoke.json", smoke) result["smoke"] = smoke write_json(SAVED / "ue/result.json", result) print("[L173UE] BUILD PASS VoxelWorld.cpp=compiled " "VoxelForgeLivingPlane=linked DWARF=PASS", flush=True) print("[L173UE] OWNER_WORLD_SMOKE PASS " + json.dumps({key: smoke[key] for key in ( "frame_resolution_arrival_s", "tick_p99_ms", "tick_worst_ms", "early_admission_wait_for_critical", "early_admission_apply_budget_ms")}, sort_keys=True), flush=True) return 0 finally: restored = runner.restore_main_checkout() shader_link = runner.HOST_PLUGIN_LINK / "Shaders" if locals().get("created_shader_link", False): shader_link.unlink(missing_ok=True) write_json(SAVED / "ue/restored-main-links.json", { "main_root": str(runner.MAIN_CHECKOUT.resolve()), "links": restored["links"], "intermediates_moved": restored["intermediates_moved"], }) if __name__ == "__main__": raise SystemExit(main())