Resolve native Vile recipes in dependency order before building
@@ -21,6 +21,15 @@ python3 tools/build-order.py x86_64 "$signed_feed" "$work/order"
2121
2222`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.
2323
24+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.
25+
26+```sh
27+python3 tools/build-order.py --recipes aarch64 "$ports" "$work/source-order" \
28+ --extra-recipe "$work/vinix-keyring/PKGBUILD.vile"
29+```
30+
31+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`.
32+
2433The 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`.
2534
2635## Running the shared worker
@@ -1,7 +1,8 @@
1-"""Order a Vinix feed's target packages by their recorded build, check and runtime inputs."""
1+"""Order Vinix packages by the dependencies in a signed feed or a native ports tree."""
22import argparse
33import csv
44import hashlib
5+import os
56import re
67import subprocess
78from collections import defaultdict
@@ -43,24 +44,54 @@ def satisfies(version, operator, requested):
4344 ">": result > 0, "<": result < 0}[operator]
4445
4546
47+def feed_records(directory, arch):
48+ with (directory / "packages.tsv").open() as stream:
49+ for row in csv.DictReader(stream, delimiter="\t"):
50+ yield row["name"], metadata(directory / arch / row["archive"], row, arch)
51+
52+
53+def recipe_records(args):
54+ reader = Path(__file__).resolve().with_name("recipe-metadata.vile")
55+ recipes = sorted(args.source.glob("*/PKGBUILD.vile")) + args.extra_recipe
56+ aliases = {"depends": "depend", "makedepends": "makedepend", "checkdepends": "checkdepend"}
57+ for recipe in recipes:
58+ env = {**os.environ, "VINIX_RECIPE": str(recipe.resolve()), "VPAC_TARGET_ARCH": args.arch}
59+ result = subprocess.run(["vpac", "--recipe-run", reader, "check"], env=env,
60+ text=True, capture_output=True)
61+ if result.returncode:
62+ raise ValueError(f"{recipe}: vpac could not read the metadata:\n{result.stderr}{result.stdout}")
63+ info = defaultdict(list)
64+ for line in result.stdout.splitlines():
65+ key, value = line.split("\t")
66+ info[aliases.get(key, key)].append(value)
67+ if not info["arch"] or not info["pkgname"]:
68+ raise ValueError(f"missing architecture or package name in {recipe}")
69+ if args.arch not in info["arch"] and "any" not in info["arch"]:
70+ continue
71+ version, = info["pkgver"]
72+ release, = info["pkgrel"]
73+ epoch, = info.get("epoch", ["0"])
74+ info["pkgver"] = [(epoch + ":" if epoch != "0" else "") + version + "-" + release]
75+ for name in info["pkgname"]:
76+ yield name, info
77+
78+
4679def plan(args):
4780 providers = defaultdict(list)
4881 packages = {}
49- with (args.feed / "packages.tsv").open() as stream:
50- for row in csv.DictReader(stream, delimiter="\t"):
51- name = row["name"]
52- if name in packages:
53- raise ValueError(f"duplicate package {name}")
54- info = metadata(args.feed / args.arch / row["archive"], row, args.arch)
55- packages[name] = info
56- providers[name].append((name, row["version"]))
57- for provide in info["provides"]:
58- alias, operator, version = requirement(provide)
59- if operator not in (None, "="):
60- raise ValueError(f"invalid provides expression {provide!r}")
61- providers[alias].append((name, version))
82+ records = recipe_records(args) if args.recipes else feed_records(args.source, args.arch)
83+ for name, info in records:
84+ if name in packages:
85+ raise ValueError(f"duplicate package {name}")
86+ packages[name] = info
87+ providers[name].append((name, info["pkgver"][0]))
88+ for provide in info["provides"]:
89+ alias, operator, version = requirement(provide)
90+ if operator not in (None, "="):
91+ raise ValueError(f"invalid provides expression {provide!r}")
92+ providers[alias].append((name, version))
6293 if not packages:
63- raise ValueError("empty feed")
94+ raise ValueError("no target packages")
6495 edges = []
6596 needs = {name: set() for name in packages}
6697 waiting = set()
@@ -106,6 +137,12 @@ def plan(args):
106137if __name__ == "__main__":
107138 parser = argparse.ArgumentParser(description=__doc__)
108139 parser.add_argument("arch", choices=("x86_64", "aarch64"))
109- parser.add_argument("feed", type=Path)
140+ parser.add_argument("source", type=Path, help="published feed, or ports root with --recipes")
110141 parser.add_argument("output", type=Path)
111- plan(parser.parse_args())
142+ parser.add_argument("--recipes", action="store_true", help="read native Vile recipes using vpac")
143+ parser.add_argument("--extra-recipe", type=Path, default=[], action="append",
144+ help="include an externally prepared recipe such as vinix-keyring")
145+ args = parser.parse_args()
146+ if args.extra_recipe and not args.recipes:
147+ parser.error("--extra-recipe requires --recipes")
148+ plan(args)
@@ -0,0 +1,31 @@
1+; Run through vpac --recipe-run so the target recipe uses makepkg's real evaluator.
2+; Only the declared metadata is read. Its build and package closures stay in the VM.
3+emit-field := fn(key, value) {
4+ display(key)
5+ display("\t")
6+ display(value)
7+ newline()
8+}
9+
10+defpkgbuild(metadata-reader,
11+ #:pkgname, "metadata-reader",
12+ #:pkgdesc, "Read the dependency fields from a trusted native recipe",
13+ #:pkgver, "1",
14+ #:pkgrel, 1,
15+ #:arch, [#:any],
16+ #:check, fn() {
17+ path := get-environment-variable("VINIX_RECIPE")
18+ recipe := eval(list(string->symbol("include"), path), interaction-environment())
19+ fields := list("pkgname", "pkgver", "pkgrel", "epoch", "arch", "depends", "makedepends", "checkdepends", "provides")
20+ for-each(fn(key, value) {
21+ if member(key, fields) {
22+ if procedure?(value) { error("the source version must be resolved by a build", path) }
23+ if list?(value) {
24+ for-each(fn(item) { emit-field(key, item) }, value)
25+ } else {
26+ emit-field(key, value)
27+ }
28+ }
29+ }, vector->list(vpac-pkgbuild-keys(recipe)), vector->list(vpac-pkgbuild-values(recipe)))
30+ },
31+ #:package, fn() { true })