41 lines
1.8 KiB
Python
41 lines
1.8 KiB
Python
"""Replay a failed WebGL clang invocation without modifying Unity build artifacts."""
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import time
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--source", default="UnityEngine.CoreModule__4.cpp")
|
|
parser.add_argument("--optimization", default="O3", choices=["O0", "O1", "O2", "O3", "Os", "Oz"])
|
|
args = parser.parse_args()
|
|
repo = Path(__file__).resolve().parent.parent
|
|
project = repo / "AIClient"
|
|
output = repo / "Tools/output/hybridclr_genall"
|
|
output.mkdir(parents=True, exist_ok=True)
|
|
log = Path(os.environ["LOCALAPPDATA"]) / "Unity/Editor/Editor.log"
|
|
commands = re.findall(r"emcc: error: '(.*?)' failed", log.read_text(encoding="utf-8", errors="replace"))
|
|
command = next(c for c in reversed(commands) if args.source in c and "clang++.exe" in c)
|
|
command = re.sub(r" -O[0-3sz](?= )", " -" + args.optimization, command)
|
|
stem = args.source.replace(".cpp", "") + "_" + args.optimization
|
|
object_file = output / (stem + ".o")
|
|
command = re.sub(r" -o .*$", ' -o "' + object_file.as_posix() + '"', command)
|
|
environment = os.environ.copy()
|
|
temp = output / "tmp"
|
|
temp.mkdir(exist_ok=True)
|
|
environment["TEMP"] = str(temp)
|
|
environment["TMP"] = str(temp)
|
|
started = time.monotonic()
|
|
result = subprocess.run(command, cwd=project, env=environment, capture_output=True, timeout=180)
|
|
(output / (stem + ".log")).write_bytes(result.stdout + result.stderr)
|
|
report = {
|
|
"source": args.source, "optimization": args.optimization,
|
|
"returncode": result.returncode, "seconds": round(time.monotonic() - started, 3),
|
|
"objectBytes": object_file.stat().st_size if object_file.exists() else 0,
|
|
"command": command,
|
|
}
|
|
(output / (stem + ".json")).write_text(json.dumps(report, indent=2), encoding="utf-8")
|
|
print(json.dumps({k: v for k, v in report.items() if k != "command"}))
|