#!/usr/bin/env python3 """Compile both real native moderation cores with ASan/UBSan (no Windows/VM emulation).""" import argparse import os import re from pathlib import Path import shutil import subprocess import tempfile ROOT=Path(__file__).resolve().parents[1] p=argparse.ArgumentParser(description=__doc__) p.add_argument('--json-header', help='Pinned single header; {game} expands to t5/t6') a=p.parse_args() with tempfile.TemporaryDirectory(prefix='tws-moderation-tests-') as tmp: temp=Path(tmp) for game in ('t5','t6'): plugin=ROOT/game/'plugins'/f'tws-{game}-gsc-utils' header=Path(a.json_header.format(game=game)) if a.json_header else plugin/'deps/json/single_include/nlohmann/json.hpp' if not header.is_file(): p.error(f'Missing {header}; restore pinned dependencies or pass --json-header') shutil.copyfile(header,temp/'json.hpp') (temp/'stdinc.hpp').write_text('#include \n#include \n#include \n#include \n') exe=temp/game subprocess.run([os.environ.get('CXX','c++'),'-std=c++20','-Wall','-Wextra','-Werror','-fsanitize=address,undefined','-I',str(temp),'-I',str(plugin/'src/utils'),str(plugin/'src/utils/moderation.cpp'),str(ROOT/'tools/tests/moderation_cases.cpp'),'-o',str(exe)],check=True) subprocess.run([str(exe),str(temp/f'{game}-data')],check=True) subprocess.run([str(exe),str(temp/f'{game}-restart'),'write'],check=True) subprocess.run([str(exe),str(temp/f'{game}-restart'),'read'],check=True) component=re.sub(r'^#include[^\n]*\n','',(plugin/'src/component/moderation.cpp').read_text(),flags=re.MULTILINE) (temp/'component.cpp').write_text('#include "moderation_component_stub.hpp"\n#include "moderation.hpp"\n#include \n'+component+(ROOT/'tools/tests/moderation_component_cases.cpp').read_text()) shutil.copyfile(ROOT/'tools/tests/moderation_component_stub.hpp',temp/'moderation_component_stub.hpp') subprocess.run([os.environ.get('CXX','c++'),'-std=c++20','-Wall','-Wextra','-Werror','-fsanitize=address,undefined','-I',str(temp),'-I',str(plugin/'src/utils'),str(plugin/'src/utils/moderation.cpp'),str(temp/'component.cpp'),'-o',str(temp/'component')],check=True) component_dir=temp/f'{game}-component'; component_dir.mkdir() subprocess.run([str(temp/'component')],cwd=component_dir,check=True) print(f'PASS {game}: moderation native policy, journal and process restart',flush=True)