|
|
@@ -267,17 +267,23 @@ def package_current(output: Path, base_zip: Path) -> Path:
|
|
|
|
|
|
|
|
|
def package_delivery(output: Path, td_receipt: Path, gui_exe: Path, gui_zip: Path, status_json: Path) -> Path:
|
|
|
- commit, tree = clean_identity()
|
|
|
+ package_commit, package_tree = clean_identity()
|
|
|
receipt = json.loads(td_receipt.read_text())
|
|
|
- if receipt.get("status") != "PASS" or receipt.get("commit") != commit:
|
|
|
- raise SystemExit("delivery TD receipt is not bound to current clean commit")
|
|
|
+ source_commit = str(receipt.get("commit", ""))
|
|
|
+ if receipt.get("status") != "PASS" or len(source_commit) != 40:
|
|
|
+ raise SystemExit("delivery TD receipt has no exact PASS source commit")
|
|
|
+ if subprocess.run(
|
|
|
+ ["git", "merge-base", "--is-ancestor", source_commit, package_commit],
|
|
|
+ cwd=ROOT, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
|
|
+ ).returncode != 0:
|
|
|
+ raise SystemExit("delivery source commit is not an ancestor of packager commit")
|
|
|
bit = Path(str(receipt["bitstream"]))
|
|
|
if not bit.is_absolute(): bit = td_receipt.parent / bit
|
|
|
if sha_file(bit) != receipt.get("bitstream_sha256"):
|
|
|
raise SystemExit("delivery bitstream hash mismatch")
|
|
|
gui_meta = json.loads((gui_exe.parent / "gui-build-metadata.json").read_text())
|
|
|
contract_sha = json.loads((ROOT / "generated/6400/host-contract.json").read_text())["contract_sha256"]
|
|
|
- if gui_meta != {"profile": "6400-front-rear", "commit": commit,
|
|
|
+ if gui_meta != {"profile": "6400-front-rear", "commit": source_commit,
|
|
|
"contract_sha256": contract_sha, "bitstream_sha256": sha_file(bit)}:
|
|
|
raise SystemExit("delivery GUI metadata binding mismatch")
|
|
|
external = {bit.name: bit, gui_exe.name: gui_exe, gui_zip.name: gui_zip,
|
|
|
@@ -286,12 +292,15 @@ def package_delivery(output: Path, td_receipt: Path, gui_exe: Path, gui_zip: Pat
|
|
|
for relative in ["generated/6400/host-contract.json", "generated/6400/golden-vectors.json",
|
|
|
"generated/6400/contract-sha256.txt"]:
|
|
|
selected[relative] = (ROOT / relative).read_bytes()
|
|
|
- binding = {"schema": "prod2u-artifact-delivery-binding-v1", "commit": commit,
|
|
|
- "tree": tree, "contract_sha256": contract_sha, "bitstream_sha256": sha_file(bit),
|
|
|
+ source_tree = git("rev-parse", f"{source_commit}^{{tree}}")
|
|
|
+ binding = {"schema": "prod2u-artifact-delivery-binding-v1",
|
|
|
+ "source_commit": source_commit, "source_tree": source_tree,
|
|
|
+ "packager_commit": package_commit, "packager_tree": package_tree,
|
|
|
+ "contract_sha256": contract_sha, "bitstream_sha256": sha_file(bit),
|
|
|
"gui_sha256": sha_file(gui_exe), "hardware": "NOT_RUN"}
|
|
|
selected["ARTIFACT-TO-DELIVERY-BINDING.json"] = (json.dumps(binding, indent=2, sort_keys=True) + "\n").encode()
|
|
|
- payload = common_payload("delivery", commit, tree, selected, binding)
|
|
|
- return write_zip(output / f"Prod2U-6400-Delivery-{commit[:8]}.zip", payload)
|
|
|
+ payload = common_payload("delivery", package_commit, package_tree, selected, binding)
|
|
|
+ return write_zip(output / f"Prod2U-6400-Delivery-{source_commit[:8]}.zip", payload)
|
|
|
|
|
|
|
|
|
def tamper_must_fail(path: Path) -> None:
|