From 47a5c59a61fcff634c73a2faca5d93063357de7b Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 01:26:45 +0100 Subject: [PATCH] Derive target build order from verified package archives --- BOOTSTRAP.md | 10 ++++ tools/build-order.py | 111 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 tools/build-order.py diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index ae81c74..bf06efe 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -13,6 +13,16 @@ Build the ports outside the source checkout. Keep a separate SDK and package dat The order above describes dependencies. The signed feed receipt, clean-install log, file-ownership check and guest transcript record how far a particular build got. Keep these records beside the package archives, outside Git. +For the exact order within a source-built feed, run the following on the worker. The checker verifies each archive against the receipt from `feed publish`, reads its `.PKGINFO`, and resolves runtime, build and check dependencies including versioned providers. Its inputs are the feed and the indicated target architecture. The worker supplies `bsdtar`, ALPM's `vercmp` and Python 3.11 or later. + +```sh +python3 tools/build-order.py x86_64 "$signed_feed" "$work/order" +``` + +`order.tsv` groups packages that may be built after earlier stages finish. `edges.tsv` records every declared dependency and the selected provider. Missing providers, ambiguous virtual names and cycles leave a pending row and cause a nonzero exit. Host tools still follow the bootstrap sequence above. + +The worker resolved all 81 packages in `foundation/xlib-combined-01/repo` into seven stages. For example, BusyBox follows musl and Linux headers, Xlib follows XCB and Xtrans, and the bitmap fonts follow mkfontscale. The order is in `foundation/xlib-order-01/order.tsv` with SHA-256 `51d1464a0a994328c40264105f8b95b7b22a8922cad177daef98e593d4a6930c`. The first signed ARM feed puts both musl and Linux headers in stage zero. Its signed, installed root passed the ownership and ELF audit for 1,165 files and links, including six target ELFs. The worker keeps that receipt in `arm/common/sdk-01-audit.log` with SHA-256 `b315f8d20f2d4c7737fd2e5078c33e12b6183d2ee86a22a9ba6db6852d68c59b`. + ## Running the shared worker The Ubuntu build worker runs one build or guest test at a time under its shared `compile.lock`. Builds may use **two compiler jobs** under the same 1 GiB memory limit. Set `MAKEFLAGS=-j2` and `CMAKE_BUILD_PARALLEL_LEVEL=2`, or pass `-j2` to Ninja or Meson. The systemd service runs as a dynamic user with `CPUQuota=200%`, `MemoryHigh=768M`, `MemoryMax=1G` and `MemorySwapMax=0`. Keep downloads, build directories, emulators and signing tools in private worker state. Store the cgroup's `memory.peak` and `memory.events` with each build and record any single-job retry. The operator laptop needs only source edits and SSH. diff --git a/tools/build-order.py b/tools/build-order.py new file mode 100644 index 0000000..8fe5a49 --- /dev/null +++ b/tools/build-order.py @@ -0,0 +1,111 @@ +"""Order a Vinix feed's target packages by their recorded build, check and runtime inputs.""" +import argparse +import csv +import hashlib +import re +import subprocess +from collections import defaultdict +from pathlib import Path + + +def metadata(path, expected, arch): + if Path(path.name).name != expected["archive"] or "/" in expected["archive"]: + raise ValueError(f"invalid archive name {expected['archive']}") + with path.open("rb") as stream: + if hashlib.file_digest(stream, "sha256").hexdigest() != expected["sha256"]: + raise ValueError(f"checksum mismatch for {path}") + raw = subprocess.check_output(["bsdtar", "-xOf", path, ".PKGINFO"], text=True) + values = defaultdict(list) + for line in raw.splitlines(): + if " = " in line: + key, value = line.split(" = ", 1) + values[key].append(value) + if (values["pkgname"] != [expected["name"]] or values["pkgver"] != [expected["version"]] or + values["arch"] not in (["any"], [arch])): + raise ValueError(f"invalid metadata for {path}") + return values + + +def requirement(text): + match = re.fullmatch(r"([^<>=\s]+)(?:(>=|<=|=|<|>)([^<>=\s]+))?", text) + if not match: + raise ValueError(f"invalid dependency expression {text!r}") + return match.groups() + + +def satisfies(version, operator, requested): + if not operator: + return True + if version is None: + return False + result = int(subprocess.check_output(["vercmp", version, requested], text=True)) + return {"=": result == 0, ">=": result >= 0, "<=": result <= 0, + ">": result > 0, "<": result < 0}[operator] + + +def plan(args): + providers = defaultdict(list) + packages = {} + with (args.feed / "packages.tsv").open() as stream: + for row in csv.DictReader(stream, delimiter="\t"): + name = row["name"] + if name in packages: + raise ValueError(f"duplicate package {name}") + info = metadata(args.feed / args.arch / row["archive"], row, args.arch) + packages[name] = info + providers[name].append((name, row["version"])) + for provide in info["provides"]: + alias, operator, version = requirement(provide) + if operator not in (None, "="): + raise ValueError(f"invalid provides expression {provide!r}") + providers[alias].append((name, version)) + if not packages: + raise ValueError("empty feed") + edges = [] + needs = {name: set() for name in packages} + waiting = set() + for name, info in packages.items(): + for kind in ("depend", "makedepend", "checkdepend"): + for spec in info[kind]: + dependency, operator, requested = requirement(spec) + choices = {pkg for pkg, ver in providers[dependency] if satisfies(ver, operator, requested)} + if dependency in choices: + choices = {dependency} + if len(choices) == 1: + provider, = choices + if provider != name: + needs[name].add(provider) + else: + waiting.add(name) + provider = "missing" if not choices else "choose:" + ",".join(sorted(choices)) + edges.append((name, kind, spec, provider)) + stages = {} + remaining = set(packages) + level = 0 + while ready := {n for n in remaining - waiting if needs[n] <= stages.keys()}: + for name in ready: + stages[name] = level + remaining -= ready + level += 1 + args.output.mkdir() + with (args.output / "edges.tsv").open("x") as stream: + table = csv.writer(stream, delimiter="\t", lineterminator="\n") + table.writerow(["package", "kind", "requirement", "selected_provider"]) + table.writerows(sorted(edges)) + with (args.output / "order.tsv").open("x") as stream: + table = csv.writer(stream, delimiter="\t", lineterminator="\n") + table.writerow(["stage", "package", "version", "depends_on", "unresolved_packages"]) + for name in sorted(packages, key=lambda n: (stages.get(n, level), n)): + table.writerow([stages.get(name, "pending"), name, packages[name]["pkgver"][0], + ",".join(sorted(needs[name])), ",".join(sorted(needs[name] & remaining))]) + print(f"{args.arch}: ordered {len(stages)} of {len(packages)} packages in {level} stages") + if remaining: + raise SystemExit(f"unresolved providers or cycles: {', '.join(sorted(remaining))}; see edges.tsv") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("arch", choices=("x86_64", "aarch64")) + parser.add_argument("feed", type=Path) + parser.add_argument("output", type=Path) + plan(parser.parse_args()) -- 2.56.1