"""The pipeline state list: the back end's record (gpu/vk/vk_draw.cpp StateRec) and the tools that merge and ship the lists agree. A list made by one build is read by another (that is its point): its record size and magic are a file format. nx2/pipeline_states.py merges lists into work/pipeline_states.bin, each pipeline once, and nx2/make_game.py puts that beside the game. Synthetic data only. python -I -B tests/test_pipeline_states.py """ import importlib.util import os import re import struct import subprocess import sys import tempfile from pathlib import Path ROOT = Path(__file__).resolve().parents[1] def load(name, path): spec = importlib.util.spec_from_file_location(name, path) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) return mod def main(): tool = load("pipeline_states", ROOT / "nx2" / "pipeline_states.py") draw = (ROOT / "gpu" / "vk" / "vk_draw.cpp").read_text(encoding="utf-8") m = re.search(r"static_assert\(sizeof\(StateRec\) == (\d+)", draw) if not m or int(m.group(1)) != tool.SIZE: raise SystemExit("the back end's StateRec (%s bytes) and nx2/pipeline_states.py (%d) differ" % (m and m.group(1), tool.SIZE)) magic = re.search(r"kStateMagic\[8\] = \{([^}]*)\}", draw).group(1) if "".join(re.findall(r"'(.)'", magic)).encode() != tool.MAGIC: raise SystemExit("the back end's magic and the tool's differ") if "hookshot_pipeline_states_shipped.bin" not in draw: raise SystemExit("the back end does not read the shipped list") def rec(vs, fs, topo): r = bytearray(tool.SIZE) struct.pack_into("