Explorar o código

chore(manifest): establish XML-only workspace authority

root hai 3 meses
pai
achega
430447e00a

+ 6 - 0
AGENTS.md

@@ -0,0 +1,6 @@
+# Engineering manifest rules
+
+- XML is the sole repository inventory. Do not add `workspace.yaml` or another hand-maintained repository list.
+- Product manifests select repositories/branches; snapshots replace every revision with a full 40-hex commit.
+- Snapshot tools must reject duplicate names/paths, floating snapshot revisions, missing repositories, dirty repos, and commit mismatches.
+- Release metadata records the container digest and TD version without inventing repository rows.

+ 12 - 0
README.md

@@ -0,0 +1,12 @@
+# engineering-manifests
+
+Android Repo-style manifests for the Prod2U thermal workspace. XML is the only repository-list authority.
+
+```sh
+./tools/manifest-lint manifests/products/6400-front-rear.xml
+./tools/ws list manifests/products/6400-front-rear.xml
+./tools/snapshot-create manifests/products/6400-front-rear.xml manifests/snapshots/6400-front-rear/development.xml
+./tools/snapshot-verify manifests/snapshots/6400-front-rear/development.xml
+```
+
+Snapshot creation is fail-closed: every repository must exist, be clean, and have a resolvable HEAD.

+ 4 - 0
default.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest>
+  <include name="manifests/current-all.xml" />
+</manifest>

+ 4 - 0
manifests/current-all.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest>
+  <include name="products/6400-front-rear.xml" />
+</manifest>

+ 4 - 0
manifests/current-firmware.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest>
+  <project name="cpld-temperature-control" path="cpld-temperature-control" revision="refs/heads/dev" groups="firmware,6400,legacy" />
+</manifest>

+ 5 - 0
manifests/current-software.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest>
+  <project name="hth-platform" path="hth-platform" revision="refs/heads/dev" groups="software,host" />
+  <project name="thermal-control-lab" path="thermal-control-lab" revision="refs/heads/dev" groups="software,lab" />
+</manifest>

+ 9 - 0
manifests/products/6400-front-rear.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest>
+  <remote name="local" fetch="file:///root/workspaces/thermal-system" />
+  <default remote="local" revision="refs/heads/dev" sync-j="4" />
+  <project name="cpld-temperature-control" path="cpld-temperature-control" groups="firmware,6400,legacy" />
+  <project name="hth-platform" path="hth-platform" groups="software,host" />
+  <project name="thermal-control-lab" path="thermal-control-lab" groups="software,lab" />
+  <project name="engineering-manifests" path="engineering-manifests" groups="manifest" />
+</manifest>

+ 7 - 0
manifests/products/legacy-door-percent.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest>
+  <remote name="local" fetch="file:///root/workspaces/thermal-system" />
+  <default remote="local" revision="refs/heads/dev" sync-j="2" />
+  <project name="cpld-temperature-control" path="cpld-temperature-control" groups="firmware,legacy" />
+  <project name="engineering-manifests" path="engineering-manifests" groups="manifest" />
+</manifest>

BIN=BIN
tests/__pycache__/test_manifest.cpython-313.pyc


+ 49 - 0
tests/test_manifest.py

@@ -0,0 +1,49 @@
+from pathlib import Path
+import tempfile
+
+import pytest
+
+from tools.manifest_cli import lint
+
+
+ROOT = Path(__file__).resolve().parents[1]
+
+
+def test_product_manifest_has_exact_repository_set() -> None:
+    projects = lint(ROOT / "manifests/products/6400-front-rear.xml")
+    assert {item.get("name") for item in projects} == {
+        "engineering-manifests",
+        "cpld-temperature-control",
+        "hth-platform",
+        "thermal-control-lab",
+    }
+
+
+def test_legacy_manifest_is_minimal() -> None:
+    projects = lint(ROOT / "manifests/products/legacy-door-percent.xml")
+    assert {item.get("name") for item in projects} == {
+        "engineering-manifests",
+        "cpld-temperature-control",
+    }
+
+
+def test_duplicate_project_is_rejected() -> None:
+    with tempfile.TemporaryDirectory() as directory:
+        path = Path(directory) / "bad.xml"
+        path.write_text(
+            '<manifest><project name="a" path="x"/><project name="a" path="y"/></manifest>',
+            encoding="utf-8",
+        )
+        with pytest.raises(ValueError, match="duplicate"):
+            lint(path)
+
+
+def test_floating_snapshot_is_rejected() -> None:
+    with tempfile.TemporaryDirectory() as directory:
+        path = Path(directory) / "bad.xml"
+        path.write_text(
+            '<manifest><project name="a" path="a" revision="refs/heads/dev"/></manifest>',
+            encoding="utf-8",
+        )
+        with pytest.raises(ValueError, match="full SHA"):
+            lint(path, snapshot=True)

BIN=BIN
tools/__pycache__/manifest_cli.cpython-313.pyc


+ 3 - 0
tools/manifest-lint

@@ -0,0 +1,3 @@
+#!/bin/sh
+set -eu
+exec python3 "$(dirname "$0")/manifest_cli.py" lint "$@"

+ 141 - 0
tools/manifest_cli.py

@@ -0,0 +1,141 @@
+#!/usr/bin/env python3
+"""Lint, list, create, and verify Repo-style XML manifests."""
+
+from __future__ import annotations
+
+import argparse
+import os
+from pathlib import Path
+import re
+import subprocess
+import sys
+import xml.etree.ElementTree as ET
+
+
+ROOT = Path(__file__).resolve().parents[1]
+WORKSPACE = ROOT.parent
+FULL_SHA = re.compile(r"[0-9a-f]{40}")
+
+
+def git(path: Path, *args: str) -> str:
+    return subprocess.run(
+        ["git", "-C", str(path), *args],
+        check=True,
+        text=True,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE,
+    ).stdout.strip()
+
+
+def load(path: Path, seen: set[Path] | None = None) -> tuple[ET.Element, list[ET.Element]]:
+    path = path.resolve()
+    seen = set() if seen is None else seen
+    if path in seen:
+        raise ValueError(f"include cycle: {path}")
+    seen.add(path)
+    root = ET.parse(path).getroot()
+    if root.tag != "manifest":
+        raise ValueError(f"root must be manifest: {path}")
+    projects = list(root.findall("project"))
+    for include in root.findall("include"):
+        name = include.get("name")
+        if not name:
+            raise ValueError(f"include missing name: {path}")
+        _, children = load((path.parent / name).resolve(), seen)
+        projects.extend(children)
+    return root, projects
+
+
+def lint(path: Path, snapshot: bool = False) -> list[ET.Element]:
+    root, projects = load(path)
+    names: set[str] = set()
+    paths: set[str] = set()
+    default = root.find("default")
+    default_revision = default.get("revision") if default is not None else None
+    for project in projects:
+        name = project.get("name")
+        repo_path = project.get("path")
+        revision = project.get("revision") or default_revision
+        if not name or not repo_path:
+            raise ValueError("each project requires name and path")
+        if name in names or repo_path in paths:
+            raise ValueError(f"duplicate project name/path: {name} {repo_path}")
+        names.add(name)
+        paths.add(repo_path)
+        if snapshot and (revision is None or FULL_SHA.fullmatch(revision) is None):
+            raise ValueError(f"snapshot revision is not full SHA: {name}={revision}")
+    if not projects:
+        raise ValueError("manifest has no projects")
+    return projects
+
+
+def create_snapshot(source: Path, output: Path) -> None:
+    projects = lint(source)
+    rows: list[tuple[str, str, str, str]] = []
+    for project in projects:
+        name = project.get("name", "")
+        repo_path = project.get("path", "")
+        checkout = WORKSPACE / repo_path
+        if not (checkout / ".git").exists():
+            raise ValueError(f"repository missing: {checkout}")
+        if git(checkout, "status", "--porcelain"):
+            raise ValueError(f"repository dirty: {checkout}")
+        rows.append((name, repo_path, git(checkout, "rev-parse", "HEAD"), project.get("groups", "")))
+    container_digest = os.environ.get("PRODU2_CONTAINER_DIGEST", "NOT_RECORDED")
+    td_version = os.environ.get("PRODU2_TD_VERSION", "NOT_RECORDED")
+    manifest = ET.Element("manifest")
+    notice = ET.SubElement(manifest, "notice")
+    notice.text = f"container_digest={container_digest}; td_version={td_version}"
+    for name, repo_path, revision, groups in rows:
+        attrs = {"name": name, "path": repo_path, "revision": revision}
+        if groups:
+            attrs["groups"] = groups
+        ET.SubElement(manifest, "project", attrs)
+    ET.indent(manifest, space="  ")
+    output.parent.mkdir(parents=True, exist_ok=True)
+    ET.ElementTree(manifest).write(output, encoding="utf-8", xml_declaration=True)
+
+
+def verify(path: Path) -> None:
+    projects = lint(path, snapshot=True)
+    for project in projects:
+        checkout = WORKSPACE / project.get("path", "")
+        expected = project.get("revision", "")
+        actual = git(checkout, "rev-parse", "HEAD")
+        if actual != expected:
+            raise ValueError(f"commit mismatch {project.get('name')}: {actual} != {expected}")
+        if git(checkout, "status", "--porcelain"):
+            raise ValueError(f"repository dirty: {checkout}")
+
+
+def main() -> int:
+    parser = argparse.ArgumentParser()
+    sub = parser.add_subparsers(dest="command", required=True)
+    for command in ("lint", "list", "verify"):
+        item = sub.add_parser(command)
+        item.add_argument("manifest", type=Path)
+    create = sub.add_parser("create")
+    create.add_argument("manifest", type=Path)
+    create.add_argument("output", type=Path)
+    args = parser.parse_args()
+    if args.command == "lint":
+        projects = lint(args.manifest)
+        print(f"PASS: {len(projects)} unique projects")
+    elif args.command == "list":
+        for project in lint(args.manifest):
+            print(f"{project.get('path')}\t{project.get('revision', '<default>')}")
+    elif args.command == "create":
+        create_snapshot(args.manifest, args.output)
+        print(args.output)
+    else:
+        verify(args.manifest)
+        print(f"PASS: {args.manifest}")
+    return 0
+
+
+if __name__ == "__main__":
+    try:
+        sys.exit(main())
+    except (OSError, ValueError, ET.ParseError, subprocess.CalledProcessError) as exc:
+        print(f"ERROR: {exc}", file=sys.stderr)
+        sys.exit(2)

+ 3 - 0
tools/snapshot-create

@@ -0,0 +1,3 @@
+#!/bin/sh
+set -eu
+exec python3 "$(dirname "$0")/manifest_cli.py" create "$@"

+ 3 - 0
tools/snapshot-verify

@@ -0,0 +1,3 @@
+#!/bin/sh
+set -eu
+exec python3 "$(dirname "$0")/manifest_cli.py" verify "$@"

+ 3 - 0
tools/ws

@@ -0,0 +1,3 @@
+#!/bin/sh
+set -eu
+exec python3 "$(dirname "$0")/manifest_cli.py" "$@"