55 lines
2.4 KiB
Python
55 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Measure whether a real CMake regeneration needlessly rebuilds the core/WASM."""
|
|
import fcntl
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import time
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
TREE = ROOT / "freecad-source/build-web/configure"
|
|
TARGET = "FreeCADWebDocumentProbe"
|
|
TRACKED = ["src/Base/Resources/Base_translation.qrc", "src/App/Resources/App_translation.qrc",
|
|
"src/Base/libFreeCADBase.a", "src/App/libFreeCADApp.a", f"bin/{TARGET}.js", f"bin/{TARGET}.wasm"]
|
|
|
|
|
|
def snapshot():
|
|
return {name: {"mtimeNs": (TREE / name).stat().st_mtime_ns,
|
|
"sha256": hashlib.sha256((TREE / name).read_bytes()).hexdigest()} for name in TRACKED}
|
|
|
|
|
|
def main():
|
|
environment = os.environ.copy()
|
|
environment.setdefault("EM_CONFIG", str(ROOT / "tools/emscripten-writable-config.py"))
|
|
environment.setdefault("EMCC_CORES", "8")
|
|
steps = []
|
|
with (TREE / ".freecad-web-build.lock").open("a") as lock:
|
|
start = time.monotonic()
|
|
fcntl.flock(lock.fileno(), fcntl.LOCK_EX)
|
|
steps.append({"stage": "build-lock", "seconds": time.monotonic() - start})
|
|
def build(stage, target):
|
|
start = time.monotonic()
|
|
command = ["cmake", "--build", str(TREE), "--target", target, "-j8"]
|
|
process = subprocess.run(command, cwd=ROOT, env=environment, pass_fds=(lock.fileno(),), capture_output=True, text=True, timeout=180)
|
|
step = {"stage": stage, "seconds": time.monotonic() - start, "exitCode": process.returncode, "output": process.stdout[-2500:], "stderr": process.stderr[-800:]}
|
|
steps.append(step)
|
|
print(json.dumps(step), flush=True)
|
|
process.check_returncode()
|
|
build("baseline-build", TARGET)
|
|
before = snapshot()
|
|
build("cmake-reconfigure", "rebuild_cache")
|
|
build("unchanged-build", TARGET)
|
|
after = snapshot()
|
|
changed = [name for name in TRACKED if before[name] != after[name]]
|
|
report = {"schema": "freecad-web-reconfigure-stability/v1", "target": TARGET, "passed": not changed,
|
|
"changedFiles": changed, "before": before, "after": after, "steps": steps}
|
|
(ROOT / "docs/current/qt-resource-reconfigure.json").write_text(json.dumps(report, indent=2) + "\n")
|
|
print(json.dumps({"passed": not changed, "changedFiles": changed}), flush=True)
|
|
return int(bool(changed))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|