From 35dabc1ae32cdac629e208f04b29260d2f546959 Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 02:02:24 +0100 Subject: [PATCH] Resolve native Vile recipes in dependency order before building --- BOOTSTRAP.md | 9 +++++ tools/build-order.py | 71 +++++++++++++++++++++++++++++--------- tools/recipe-metadata.vile | 31 +++++++++++++++++ 3 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 tools/recipe-metadata.vile diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index bf06efe..3854ca9 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -21,6 +21,15 @@ 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. +To plan before the archives exist, point the same command at a trusted ports checkout. It uses vpac to evaluate each native recipe's metadata for the selected architecture. Include a prepared signing-key port with `--extra-recipe` when it belongs in the build. + +```sh +python3 tools/build-order.py --recipes aarch64 "$ports" "$work/source-order" \ + --extra-recipe "$work/vinix-keyring/PKGBUILD.vile" +``` + +The worker cross-checked the source plan against the signed x86_64 archives for musl, Linux UAPI, zlib and PCRE2. The package versions, stages and dependency edges matched byte for byte. A second check of ports revision `c745c03` found an unsatisfied check dependency on xkeyboard-config for xkbcomp on both targets. It ordered the other 100 x86_64 and 99 arm64 packages in that checkout. The worker keeps the results in `foundation/source-order-01`. Its receipt manifest has SHA-256 `d46e8c29cb0404a5dc61489662e41e8999aaea0bb4186d534fea50dea7a15797`. + 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 diff --git a/tools/build-order.py b/tools/build-order.py index 8fe5a49..b95b1d7 100644 --- a/tools/build-order.py +++ b/tools/build-order.py @@ -1,7 +1,8 @@ -"""Order a Vinix feed's target packages by their recorded build, check and runtime inputs.""" +"""Order Vinix packages by the dependencies in a signed feed or a native ports tree.""" import argparse import csv import hashlib +import os import re import subprocess from collections import defaultdict @@ -43,24 +44,54 @@ def satisfies(version, operator, requested): ">": result > 0, "<": result < 0}[operator] +def feed_records(directory, arch): + with (directory / "packages.tsv").open() as stream: + for row in csv.DictReader(stream, delimiter="\t"): + yield row["name"], metadata(directory / arch / row["archive"], row, arch) + + +def recipe_records(args): + reader = Path(__file__).resolve().with_name("recipe-metadata.vile") + recipes = sorted(args.source.glob("*/PKGBUILD.vile")) + args.extra_recipe + aliases = {"depends": "depend", "makedepends": "makedepend", "checkdepends": "checkdepend"} + for recipe in recipes: + env = {**os.environ, "VINIX_RECIPE": str(recipe.resolve()), "VPAC_TARGET_ARCH": args.arch} + result = subprocess.run(["vpac", "--recipe-run", reader, "check"], env=env, + text=True, capture_output=True) + if result.returncode: + raise ValueError(f"{recipe}: vpac could not read the metadata:\n{result.stderr}{result.stdout}") + info = defaultdict(list) + for line in result.stdout.splitlines(): + key, value = line.split("\t") + info[aliases.get(key, key)].append(value) + if not info["arch"] or not info["pkgname"]: + raise ValueError(f"missing architecture or package name in {recipe}") + if args.arch not in info["arch"] and "any" not in info["arch"]: + continue + version, = info["pkgver"] + release, = info["pkgrel"] + epoch, = info.get("epoch", ["0"]) + info["pkgver"] = [(epoch + ":" if epoch != "0" else "") + version + "-" + release] + for name in info["pkgname"]: + yield name, info + + 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)) + records = recipe_records(args) if args.recipes else feed_records(args.source, args.arch) + for name, info in records: + if name in packages: + raise ValueError(f"duplicate package {name}") + packages[name] = info + providers[name].append((name, info["pkgver"][0])) + 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") + raise ValueError("no target packages") edges = [] needs = {name: set() for name in packages} waiting = set() @@ -106,6 +137,12 @@ def plan(args): 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("source", type=Path, help="published feed, or ports root with --recipes") parser.add_argument("output", type=Path) - plan(parser.parse_args()) + parser.add_argument("--recipes", action="store_true", help="read native Vile recipes using vpac") + parser.add_argument("--extra-recipe", type=Path, default=[], action="append", + help="include an externally prepared recipe such as vinix-keyring") + args = parser.parse_args() + if args.extra_recipe and not args.recipes: + parser.error("--extra-recipe requires --recipes") + plan(args) diff --git a/tools/recipe-metadata.vile b/tools/recipe-metadata.vile new file mode 100644 index 0000000..05e4f2a --- /dev/null +++ b/tools/recipe-metadata.vile @@ -0,0 +1,31 @@ +; Run through vpac --recipe-run so the target recipe uses makepkg's real evaluator. +; Only the declared metadata is read. Its build and package closures stay in the VM. +emit-field := fn(key, value) { + display(key) + display("\t") + display(value) + newline() +} + +defpkgbuild(metadata-reader, + #:pkgname, "metadata-reader", + #:pkgdesc, "Read the dependency fields from a trusted native recipe", + #:pkgver, "1", + #:pkgrel, 1, + #:arch, [#:any], + #:check, fn() { + path := get-environment-variable("VINIX_RECIPE") + recipe := eval(list(string->symbol("include"), path), interaction-environment()) + fields := list("pkgname", "pkgver", "pkgrel", "epoch", "arch", "depends", "makedepends", "checkdepends", "provides") + for-each(fn(key, value) { + if member(key, fields) { + if procedure?(value) { error("the source version must be resolved by a build", path) } + if list?(value) { + for-each(fn(item) { emit-field(key, item) }, value) + } else { + emit-field(key, value) + } + } + }, vector->list(vpac-pkgbuild-keys(recipe)), vector->list(vpac-pkgbuild-values(recipe))) + }, + #:package, fn() { true }) -- 2.56.1