32 lines
1.4 KiB
Python
32 lines
1.4 KiB
Python
"""Replay wasm-opt outside Unity build output, with an explicit worker limit."""
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import time
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--cores", type=int, default=4)
|
|
args = parser.parse_args()
|
|
repo = Path(__file__).resolve().parent.parent
|
|
output = repo / "Tools/output/hybridclr_genall"
|
|
output.mkdir(parents=True, exist_ok=True)
|
|
editor_log = Path(os.environ["LOCALAPPDATA"]) / "Unity/Editor/Editor.log"
|
|
commands = re.findall(r"emcc: error: '(.*?)' failed", editor_log.read_text(encoding="utf-8", errors="replace"))
|
|
command = next(c for c in reversed(commands) if "wasm-opt" in c)
|
|
stem = "wasm_opt_cores_" + str(args.cores)
|
|
target = output / (stem + ".wasm")
|
|
command = re.sub(r" -o \S+", ' -o "' + target.as_posix() + '"', command)
|
|
environment = os.environ.copy()
|
|
environment["BINARYEN_CORES"] = str(args.cores)
|
|
started = time.monotonic()
|
|
result = subprocess.run(command, cwd=repo / "AIClient", env=environment, capture_output=True, timeout=240)
|
|
(output / (stem + ".log")).write_bytes(result.stdout + result.stderr)
|
|
report = {"cores": args.cores, "returncode": result.returncode,
|
|
"seconds": round(time.monotonic() - started, 3),
|
|
"outputBytes": target.stat().st_size if target.exists() else 0}
|
|
(output / (stem + ".json")).write_text(json.dumps(report, indent=2), encoding="utf-8")
|
|
print(json.dumps(report))
|