#!/usr/bin/env python3 """Verify the Cocos 4 project and record current toolchain status.""" from __future__ import annotations import json import subprocess from datetime import datetime, timezone from pathlib import Path PROJECT = Path(__file__).resolve().parents[1] def run(cmd: list[str]) -> dict[str, object]: proc = subprocess.run(cmd, cwd=PROJECT, text=True, capture_output=True) return { "cmd": cmd, "returncode": proc.returncode, "stdout_tail": proc.stdout[-4000:], "stderr_tail": proc.stderr[-4000:], } def main() -> None: package = json.loads((PROJECT / "package.json").read_text(encoding="utf-8")) checks = { "generated_at": datetime.now(timezone.utc).isoformat(), "package": { "type": package.get("type"), "version": package.get("version"), "creator_version": package.get("creator", {}).get("version"), }, "cocos_version": run(["zsh", "-lc", "cocos --version"]), "node_abi": run(["zsh", "-lc", "~/.local/tools/node-v24.14.1-darwin-arm64/bin/node -p 'process.version + \" abi=\" + process.versions.modules'"]), "build": run(["zsh", "-lc", "rm -rf temp library build && cocos build --project . --platform web-mobile"]), } checks["status"] = "passed" if checks["build"]["returncode"] == 0 else "blocked" checks["blocker"] = None if checks["status"] == "passed" else "Cocos 4 alpha CLI native gl module expects NODE_MODULE_VERSION 140; local Node 24 reports ABI 137." out = PROJECT / "artifacts/cocos_capture" out.mkdir(parents=True, exist_ok=True) path = out / "stage1_cocos_verify.json" path.write_text(json.dumps(checks, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") print(path) raise SystemExit(0 if checks["status"] == "passed" else 1) if __name__ == "__main__": main()