64 lines
2.4 KiB
Python
64 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Record a receipt for a routed native target that was built outside a batch."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from implementation_first import record_implementation_batch
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
CAPABILITY_PATH = ROOT / "docs/current/feature-capability-registry.json"
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--module", required=True)
|
|
parser.add_argument("--target", required=True)
|
|
parser.add_argument("--tree", required=True)
|
|
args = parser.parse_args()
|
|
try:
|
|
capabilities = json.loads(CAPABILITY_PATH.read_text(encoding="utf-8"))
|
|
except (OSError, json.JSONDecodeError) as error:
|
|
print(json.dumps({"status": "error", "error": str(error)}))
|
|
return 2
|
|
rows = [
|
|
row for row in capabilities.get("records", [])
|
|
if isinstance(row, dict)
|
|
and row.get("module") == args.module
|
|
and row.get("implementationStatus") == "routed"
|
|
and isinstance(row.get("route"), dict)
|
|
and str(row["route"].get("nativeRegistration", "")).endswith(f"/{args.module}RuntimeProbe.cpp")
|
|
]
|
|
tree = ROOT / args.tree
|
|
artifacts = [
|
|
str(path.relative_to(ROOT))
|
|
for path in (tree / "bin" / f"{args.target}.js", tree / "bin" / f"{args.target}.wasm")
|
|
if path.is_file()
|
|
]
|
|
if not artifacts:
|
|
print(json.dumps({"status": "unavailable", "module": args.module, "target": args.target}))
|
|
return 78
|
|
if not rows:
|
|
print(json.dumps({"status": "no_routed_records", "module": args.module, "target": args.target}))
|
|
return 0
|
|
batch = {
|
|
"batchId": f"finalize:{args.module}:{args.target}",
|
|
"selected": {"module": args.module, "tier": "feature-workflow", "family": "routed-target", "recordCount": len(rows)},
|
|
"records": [[row["id"], row.get("command", ""), "implementation_required", row.get("sourcePath"), row.get("sourceLine")] for row in rows],
|
|
}
|
|
receipt = record_implementation_batch(
|
|
batch,
|
|
target=args.target,
|
|
build_tree=args.tree,
|
|
artifacts=artifacts,
|
|
source="direct-target-build",
|
|
)
|
|
print(json.dumps({"status": "recorded", "module": args.module, "target": args.target, "records": receipt["recordCount"]}, ensure_ascii=False))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|