#!/usr/bin/env python3 """Compile actual HTTP component logic using host shims for engine interfaces.""" import os from pathlib import Path import re import subprocess import tempfile ROOT = Path(__file__).resolve().parents[1] with tempfile.TemporaryDirectory(prefix="tws-http-component-") as temp: for game in ("t5", "t6"): plugin = ROOT / game / "plugins" / f"tws-{game}-gsc-utils" / "src" # Only includes are substituted; compile the entire component unchanged. component = re.sub(r'^#include[^\n]*\n', '', (plugin / "component/http.cpp").read_text(), flags=re.MULTILINE) source = Path(temp) / f"{game}.cpp" source.write_text('#include "http_component_stub.hpp"\n' + component + (ROOT / "tools/tests/http_component_cases.cpp").read_text()) executable = Path(temp) / game subprocess.run([os.environ.get("CXX", "c++"), "-std=c++20", "-Wall", "-Wextra", "-Werror", "-fsanitize=address,undefined", "-I", str(plugin / "utils"), "-I", str(ROOT / "tools/tests"), str(source), "-lcurl", "-o", str(executable)], check=True) print(game, flush=True) subprocess.run([str(executable)], check=True)