|
@@ -12,6 +12,7 @@ from __future__ import annotations
|
|
|
import hashlib
|
|
import hashlib
|
|
|
import json
|
|
import json
|
|
|
import re
|
|
import re
|
|
|
|
|
+import subprocess
|
|
|
from datetime import datetime, timezone
|
|
from datetime import datetime, timezone
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
|
from typing import Any
|
|
from typing import Any
|
|
@@ -43,27 +44,133 @@ def release_task_slug() -> str:
|
|
|
RELEASE_TASK_SLUG = _DEFAULT_RELEASE_TASK_SLUG
|
|
RELEASE_TASK_SLUG = _DEFAULT_RELEASE_TASK_SLUG
|
|
|
|
|
|
|
|
|
|
|
|
|
-def release_sibling_filename(kind: str, delivery_commit: str, *, slug: str | None = None) -> str:
|
|
|
|
|
|
|
+def canonical_release_names(
|
|
|
|
|
+ *,
|
|
|
|
|
+ role: str,
|
|
|
|
|
+ stage: str,
|
|
|
|
|
+ delivery_commit: str,
|
|
|
|
|
+ topic: str | None = None,
|
|
|
|
|
+ actual_zip_basename: str | None = None,
|
|
|
|
|
+) -> dict[str, str]:
|
|
|
|
|
+ """Single naming helper for ZIP / sidecar / pointer basenames.
|
|
|
|
|
+
|
|
|
|
|
+ Inputs: topic (default mse-a1), role, stage, delivery short hash, optional
|
|
|
|
|
+ actual ZIP basename. Intermediate names never assume final; final names
|
|
|
|
|
+ never use door-percent / PENDING.
|
|
|
|
|
+ """
|
|
|
|
|
+ topic_n = (topic or release_task_slug()).strip()
|
|
|
|
|
+ if not topic_n:
|
|
|
|
|
+ topic_n = _DEFAULT_RELEASE_TASK_SLUG
|
|
|
|
|
+ stage_n = str(stage or "").strip().casefold().replace("_", "-")
|
|
|
|
|
+ if stage_n in {"intermediate", "intermediate-review", "non-final"}:
|
|
|
|
|
+ stage_n = "intermediate-review"
|
|
|
|
|
+ elif stage_n in {"final", "final-review"}:
|
|
|
|
|
+ stage_n = "final-review"
|
|
|
|
|
+ else:
|
|
|
|
|
+ raise ValueError(f"unsupported package stage for naming: {stage}")
|
|
|
|
|
+ role_n = str(role or "").strip().casefold()
|
|
|
|
|
+ short = _short(delivery_commit, 8)
|
|
|
|
|
+ actual = (actual_zip_basename or "").strip()
|
|
|
|
|
+ blob = f"{topic_n}|{role_n}|{stage_n}|{short}|{actual}"
|
|
|
|
|
+ if "PENDING" in blob.upper():
|
|
|
|
|
+ raise ValueError("PENDING is not allowed in canonical release names")
|
|
|
|
|
+ if role_n in {"review-compact", "review", "compact"}:
|
|
|
|
|
+ if stage_n == "intermediate-review":
|
|
|
|
|
+ zip_name = f"prod2u-review-compact-{topic_n}-intermediate-{short}.zip"
|
|
|
|
|
+ else:
|
|
|
|
|
+ zip_name = f"prod2u-review-compact-{topic_n}-{short}.zip"
|
|
|
|
|
+ elif role_n in {"firmware", "fw"}:
|
|
|
|
|
+ if stage_n == "intermediate-review":
|
|
|
|
|
+ zip_name = f"prod2u-firmware-{topic_n}-intermediate-{short}.zip"
|
|
|
|
|
+ else:
|
|
|
|
|
+ zip_name = f"prod2u-firmware-{topic_n}-{short}.zip"
|
|
|
|
|
+ else:
|
|
|
|
|
+ raise ValueError(f"unsupported naming role: {role}")
|
|
|
|
|
+ if actual:
|
|
|
|
|
+ zip_name = actual if actual.casefold().endswith(".zip") else f"{actual}.zip"
|
|
|
|
|
+ stem = zip_name[:-4] if zip_name.casefold().endswith(".zip") else zip_name
|
|
|
|
|
+ return {
|
|
|
|
|
+ "topic": topic_n,
|
|
|
|
|
+ "role": "firmware" if role_n in {"firmware", "fw"} else "review-compact",
|
|
|
|
|
+ "stage": stage_n,
|
|
|
|
|
+ "delivery_short": short,
|
|
|
|
|
+ "zip_basename": zip_name,
|
|
|
|
|
+ "selftest_basename": f"{stem}.selftest.json",
|
|
|
|
|
+ "detached_replay_basename": f"{stem}.detached-replay.json",
|
|
|
|
|
+ "sha256_basename": f"{zip_name}.sha256",
|
|
|
|
|
+ "cross_package_basename": f"prod2u-cross-package-{topic_n}-{short}.json",
|
|
|
|
|
+ "release_validation_basename": f"prod2u-release-validation-{topic_n}-{short}.json",
|
|
|
|
|
+ "release_set_basename": f"prod2u-release-set-{topic_n}-{short}.json",
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def release_sibling_filename(
|
|
|
|
|
+ kind: str,
|
|
|
|
|
+ delivery_commit: str,
|
|
|
|
|
+ *,
|
|
|
|
|
+ slug: str | None = None,
|
|
|
|
|
+ stage: str = "final-review",
|
|
|
|
|
+ actual_zip_basename: str | None = None,
|
|
|
|
|
+) -> str:
|
|
|
"""Canonical sibling names for this task (topic/stage-aware; never altconfig)."""
|
|
"""Canonical sibling names for this task (topic/stage-aware; never altconfig)."""
|
|
|
topic = (slug or release_task_slug()).strip()
|
|
topic = (slug or release_task_slug()).strip()
|
|
|
- short = _short(delivery_commit, 8)
|
|
|
|
|
kind_n = kind.strip().casefold()
|
|
kind_n = kind.strip().casefold()
|
|
|
if kind_n in {"review-compact", "review", "compact"}:
|
|
if kind_n in {"review-compact", "review", "compact"}:
|
|
|
- return f"prod2u-review-compact-{topic}-{short}.zip"
|
|
|
|
|
|
|
+ return canonical_release_names(
|
|
|
|
|
+ role="review-compact",
|
|
|
|
|
+ stage=stage,
|
|
|
|
|
+ delivery_commit=delivery_commit,
|
|
|
|
|
+ topic=topic,
|
|
|
|
|
+ actual_zip_basename=actual_zip_basename,
|
|
|
|
|
+ )["zip_basename"]
|
|
|
if kind_n in {"firmware", "fw"}:
|
|
if kind_n in {"firmware", "fw"}:
|
|
|
- return f"prod2u-firmware-{topic}-{short}.zip"
|
|
|
|
|
|
|
+ return canonical_release_names(
|
|
|
|
|
+ role="firmware",
|
|
|
|
|
+ stage=stage,
|
|
|
|
|
+ delivery_commit=delivery_commit,
|
|
|
|
|
+ topic=topic,
|
|
|
|
|
+ actual_zip_basename=actual_zip_basename,
|
|
|
|
|
+ )["zip_basename"]
|
|
|
|
|
+ names = canonical_release_names(
|
|
|
|
|
+ role="review-compact" if "firmware" not in kind_n else "firmware",
|
|
|
|
|
+ stage=stage,
|
|
|
|
|
+ delivery_commit=delivery_commit,
|
|
|
|
|
+ topic=topic,
|
|
|
|
|
+ actual_zip_basename=actual_zip_basename,
|
|
|
|
|
+ )
|
|
|
if kind_n in {"review-selftest", "compact-selftest"}:
|
|
if kind_n in {"review-selftest", "compact-selftest"}:
|
|
|
- return f"prod2u-review-compact-{topic}-{short}.selftest.json"
|
|
|
|
|
|
|
+ review = canonical_release_names(
|
|
|
|
|
+ role="review-compact",
|
|
|
|
|
+ stage=stage,
|
|
|
|
|
+ delivery_commit=delivery_commit,
|
|
|
|
|
+ topic=topic,
|
|
|
|
|
+ actual_zip_basename=actual_zip_basename,
|
|
|
|
|
+ )
|
|
|
|
|
+ return review["selftest_basename"]
|
|
|
if kind_n in {"firmware-selftest", "fw-selftest"}:
|
|
if kind_n in {"firmware-selftest", "fw-selftest"}:
|
|
|
- return f"prod2u-firmware-{topic}-{short}.selftest.json"
|
|
|
|
|
|
|
+ fw = canonical_release_names(
|
|
|
|
|
+ role="firmware",
|
|
|
|
|
+ stage=stage,
|
|
|
|
|
+ delivery_commit=delivery_commit,
|
|
|
|
|
+ topic=topic,
|
|
|
|
|
+ actual_zip_basename=actual_zip_basename,
|
|
|
|
|
+ )
|
|
|
|
|
+ return fw["selftest_basename"]
|
|
|
if kind_n in {"release-set", "release_set"}:
|
|
if kind_n in {"release-set", "release_set"}:
|
|
|
- return f"prod2u-release-set-{topic}-{short}.json"
|
|
|
|
|
|
|
+ return names["release_set_basename"]
|
|
|
if kind_n in {"review-replay", "detached-replay"}:
|
|
if kind_n in {"review-replay", "detached-replay"}:
|
|
|
- return f"prod2u-review-compact-{topic}-{short}.detached-replay.json"
|
|
|
|
|
|
|
+ review = canonical_release_names(
|
|
|
|
|
+ role="review-compact",
|
|
|
|
|
+ stage=stage,
|
|
|
|
|
+ delivery_commit=delivery_commit,
|
|
|
|
|
+ topic=topic,
|
|
|
|
|
+ actual_zip_basename=actual_zip_basename,
|
|
|
|
|
+ )
|
|
|
|
|
+ return review["detached_replay_basename"]
|
|
|
if kind_n in {"cross-package", "crosscheck"}:
|
|
if kind_n in {"cross-package", "crosscheck"}:
|
|
|
- return f"prod2u-cross-package-{topic}-{short}.json"
|
|
|
|
|
|
|
+ return names["cross_package_basename"]
|
|
|
if kind_n in {"release-validation", "release_validation"}:
|
|
if kind_n in {"release-validation", "release_validation"}:
|
|
|
- return f"prod2u-release-validation-{topic}-{short}.json"
|
|
|
|
|
|
|
+ return names["release_validation_basename"]
|
|
|
raise ValueError(f"unknown sibling kind: {kind}")
|
|
raise ValueError(f"unknown sibling kind: {kind}")
|
|
|
|
|
|
|
|
|
|
|
|
@@ -184,13 +291,13 @@ def validate_source_closure_relations(relations: dict[str, Any] | Any) -> dict[s
|
|
|
if not isinstance(paths, list):
|
|
if not isinstance(paths, list):
|
|
|
failures.append(f"{edge_key}_paths_not_list")
|
|
failures.append(f"{edge_key}_paths_not_list")
|
|
|
paths = []
|
|
paths = []
|
|
|
- if mode == "commit_compare":
|
|
|
|
|
|
|
+ if mode in {"commit_compare", "snapshot_hash"}:
|
|
|
if unchanged is True and paths:
|
|
if unchanged is True and paths:
|
|
|
failures.append(f"{edge_key}_unchanged_true_with_changed_paths")
|
|
failures.append(f"{edge_key}_unchanged_true_with_changed_paths")
|
|
|
if unchanged is False and not paths:
|
|
if unchanged is False and not paths:
|
|
|
failures.append(f"{edge_key}_unchanged_false_empty_paths")
|
|
failures.append(f"{edge_key}_unchanged_false_empty_paths")
|
|
|
if unchanged not in (True, False):
|
|
if unchanged not in (True, False):
|
|
|
- failures.append(f"{edge_key}_unchanged_not_bool_under_commit_compare")
|
|
|
|
|
|
|
+ failures.append(f"{edge_key}_unchanged_not_bool")
|
|
|
if mode == "comparison_unavailable":
|
|
if mode == "comparison_unavailable":
|
|
|
if unchanged is not None:
|
|
if unchanged is not None:
|
|
|
failures.append(f"{edge_key}_guessed_bool_when_unavailable")
|
|
failures.append(f"{edge_key}_guessed_bool_when_unavailable")
|
|
@@ -440,6 +547,120 @@ def compute_release_set_id(
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+# Extra TD/project files beyond config/source_closure.json (37 production inputs).
|
|
|
|
|
+_TD_EXTRA_PRODUCTION_PATHS = (
|
|
|
|
|
+ "constraints/prod2u_p4_normal_v3.adc",
|
|
|
|
|
+ "constraints/prod2u_p4_normal_v3.sdc",
|
|
|
|
|
+ "td/prod2u_p4_normal_v3.prj",
|
|
|
|
|
+ "td/syn/prod2u_p4_normal_v3.tcl",
|
|
|
|
|
+ "td/phy/prod2u_p4_normal_v3.tcl",
|
|
|
|
|
+ "td/bitgen/prod2u_p4_normal_v3.tcl",
|
|
|
|
|
+ "projects/prod2u-door-temp/project.json",
|
|
|
|
|
+ "src/generated/td-source-manifest.json",
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def production_input_paths(repo_root: Path | None = None) -> list[str]:
|
|
|
|
|
+ """Canonical 37 TD synthesis / production-input paths."""
|
|
|
|
|
+ root = Path(repo_root or ROOT)
|
|
|
|
|
+ closure = root / "config" / "source_closure.json"
|
|
|
|
|
+ paths: list[str] = []
|
|
|
|
|
+ if closure.is_file():
|
|
|
|
|
+ doc = json.loads(closure.read_text(encoding="utf-8"))
|
|
|
|
|
+ for item in doc.get("sources") or []:
|
|
|
|
|
+ text = str(item).replace("\\", "/").strip()
|
|
|
|
|
+ if text and text not in paths:
|
|
|
|
|
+ paths.append(text)
|
|
|
|
|
+ for extra in _TD_EXTRA_PRODUCTION_PATHS:
|
|
|
|
|
+ if extra not in paths:
|
|
|
|
|
+ paths.append(extra)
|
|
|
|
|
+ return paths
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _git_bin() -> str:
|
|
|
|
|
+ candidate = Path("/data/prod2u/bin/git")
|
|
|
|
|
+ return str(candidate) if candidate.is_file() else "git"
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _git_show_sha(repo: Path, commit: str, rel: str) -> str | None:
|
|
|
|
|
+ try:
|
|
|
|
|
+ raw = subprocess.check_output(
|
|
|
|
|
+ [_git_bin(), "-C", str(repo), "show", f"{commit}:{rel}"],
|
|
|
|
|
+ stderr=subprocess.DEVNULL,
|
|
|
|
|
+ )
|
|
|
|
|
+ except (OSError, subprocess.CalledProcessError):
|
|
|
|
|
+ return None
|
|
|
|
|
+ return hashlib.sha256(raw).hexdigest()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def compare_production_source_commits(
|
|
|
|
|
+ *,
|
|
|
|
|
+ from_commit: str,
|
|
|
|
|
+ to_commit: str,
|
|
|
|
|
+ repo_root: Path | None = None,
|
|
|
|
|
+) -> dict[str, Any]:
|
|
|
|
|
+ """Hash-compare production inputs. Commit equality is not a shortcut."""
|
|
|
|
|
+ root = Path(repo_root or ROOT)
|
|
|
|
|
+ changed: list[str] = []
|
|
|
|
|
+ missing: list[str] = []
|
|
|
|
|
+ for rel in production_input_paths(root):
|
|
|
|
|
+ a = _git_show_sha(root, from_commit, rel)
|
|
|
|
|
+ b = _git_show_sha(root, to_commit, rel)
|
|
|
|
|
+ if a is None or b is None:
|
|
|
|
|
+ missing.append(rel)
|
|
|
|
|
+ continue
|
|
|
|
|
+ if a != b:
|
|
|
|
|
+ changed.append(rel)
|
|
|
|
|
+ unchanged = not changed and not missing
|
|
|
|
|
+ return {
|
|
|
|
|
+ "from_commit": from_commit,
|
|
|
|
|
+ "to_commit": to_commit,
|
|
|
|
|
+ "unchanged": unchanged,
|
|
|
|
|
+ "production_changed_paths": changed,
|
|
|
|
|
+ "missing_paths": missing,
|
|
|
|
|
+ "comparison_mode": "snapshot_hash",
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def parse_td_resource_fields(
|
|
|
|
|
+ compact_doc: dict[str, Any],
|
|
|
|
|
+ full_doc: dict[str, Any] | None = None,
|
|
|
|
|
+) -> dict[str, Any]:
|
|
|
|
|
+ """Parse LUT / MSLICE / DSP. Never silently substitute LUT for MSLICE.
|
|
|
|
|
+
|
|
|
|
|
+ Preference:
|
|
|
|
|
+ - LUT: ``resources.utilization.lut.used`` (not hierarchy LUT-only counts)
|
|
|
|
|
+ - MSLICE: top-level ``mslice``, then ``resources.packing.mslice``
|
|
|
|
|
+ - DSP: utilization.dsp.used, else top-level dsp
|
|
|
|
|
+ Missing MSLICE stays None — callers must not treat that as LUT.
|
|
|
|
|
+ """
|
|
|
|
|
+ full_doc = full_doc or {}
|
|
|
|
|
+ resources = compact_doc.get("resources") or full_doc.get("resources") or {}
|
|
|
|
|
+ if not isinstance(resources, dict):
|
|
|
|
|
+ resources = {}
|
|
|
|
|
+ util = resources.get("utilization") if isinstance(resources.get("utilization"), dict) else {}
|
|
|
|
|
+ packing = resources.get("packing") if isinstance(resources.get("packing"), dict) else {}
|
|
|
|
|
+ lut = None
|
|
|
|
|
+ if isinstance(util.get("lut"), dict) and util["lut"].get("used") is not None:
|
|
|
|
|
+ lut = util["lut"].get("used")
|
|
|
|
|
+ elif compact_doc.get("lut") is not None and "utilization" not in resources:
|
|
|
|
|
+ lut = compact_doc.get("lut")
|
|
|
|
|
+ mslice = compact_doc.get("mslice")
|
|
|
|
|
+ if mslice is None:
|
|
|
|
|
+ mslice = full_doc.get("mslice")
|
|
|
|
|
+ if mslice is None:
|
|
|
|
|
+ mslice = packing.get("mslice")
|
|
|
|
|
+ # Do not use packing.total_slices (MSLICE+LSLICE) or LE/LUT as MSLICE.
|
|
|
|
|
+ dsp = None
|
|
|
|
|
+ if isinstance(util.get("dsp"), dict) and util["dsp"].get("used") is not None:
|
|
|
|
|
+ dsp = util["dsp"].get("used")
|
|
|
|
|
+ elif compact_doc.get("dsp") is not None:
|
|
|
|
|
+ dsp = compact_doc.get("dsp")
|
|
|
|
|
+ elif full_doc.get("dsp") is not None:
|
|
|
|
|
+ dsp = full_doc.get("dsp")
|
|
|
|
|
+ return {"lut": lut, "mslice": mslice, "dsp": dsp}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
# Canonical A1 full-chip TD on ff44128a (Round-9 identity source — not hardcoded nulls).
|
|
# Canonical A1 full-chip TD on ff44128a (Round-9 identity source — not hardcoded nulls).
|
|
|
CANONICAL_TD_A1_RECEIPT = "receipts/mse-r4-td-a1-ff44128.json"
|
|
CANONICAL_TD_A1_RECEIPT = "receipts/mse-r4-td-a1-ff44128.json"
|
|
|
CANONICAL_TD_A1_RECEIPT_FULL = "receipts/mse-r4-td-a1-ff44128-full.json"
|
|
CANONICAL_TD_A1_RECEIPT_FULL = "receipts/mse-r4-td-a1-ff44128-full.json"
|
|
@@ -485,16 +706,10 @@ def load_canonical_td_a1_fields(repo_root: Path | None = None) -> dict[str, Any]
|
|
|
or compact_doc.get("verification_run_id")
|
|
or compact_doc.get("verification_run_id")
|
|
|
or ""
|
|
or ""
|
|
|
).strip()
|
|
).strip()
|
|
|
- resources = compact_doc.get("resources") or full_doc.get("resources") or {}
|
|
|
|
|
- util = resources.get("utilization") if isinstance(resources, dict) else {}
|
|
|
|
|
- lut = None
|
|
|
|
|
- mslice = None
|
|
|
|
|
- dsp = None
|
|
|
|
|
- if isinstance(util, dict):
|
|
|
|
|
- lut = (util.get("lut") or {}).get("used")
|
|
|
|
|
- # Anlogic area: LE≈MSLICE packing proxy used historically as mslice
|
|
|
|
|
- mslice = (util.get("le") or {}).get("used") or lut
|
|
|
|
|
- dsp = (util.get("dsp") or {}).get("used")
|
|
|
|
|
|
|
+ parsed = parse_td_resource_fields(compact_doc, full_doc)
|
|
|
|
|
+ lut = parsed["lut"]
|
|
|
|
|
+ mslice = parsed["mslice"]
|
|
|
|
|
+ dsp = parsed["dsp"]
|
|
|
return {
|
|
return {
|
|
|
"td_bound_commit": bound or CANONICAL_TD_A1_BOUND_COMMIT,
|
|
"td_bound_commit": bound or CANONICAL_TD_A1_BOUND_COMMIT,
|
|
|
"artifact_source_commit": bound or CANONICAL_TD_A1_BOUND_COMMIT,
|
|
"artifact_source_commit": bound or CANONICAL_TD_A1_BOUND_COMMIT,
|