From 06415977ce658ec19ca78b7154e45c34ecd61b51 Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 13:25:41 +0100 Subject: [PATCH] Build each split package recipe once per target --- BOOTSTRAP.md | 2 ++ tools/build-order.py | 9 +++-- tools/build-queue.py | 79 ++++++++++++++++++++++++++++---------------- 3 files changed, 59 insertions(+), 31 deletions(-) diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index 5338004..e30384b 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -93,6 +93,8 @@ Each port gets a fresh, signed SDK containing its transitive prerequisites. The An empty queue reused the existing AArch64 musl and musl-fts archives with the compiler path set to a nonexistent executable. Both archives passed the page audit. The worker also rejected a changed recipe with the same package version and an archive with a mismatched checksum. See `foundation/queue-shared-reuse-01`, receipt SHA-256 `bcab78e7e9fd1d0b86800c32870ceea84abcd5ce54781ddb42d1c46e5970d213`. +Source plans record the recipe directory for each output package. The queue invokes a split recipe once, validates its complete output list and records each archive separately. The AArch64 fixture requested two split packages, built them in one invocation and reused both in an empty queue with the compiler disabled. See `foundation/queue-split-reuse-01`, receipt SHA-256 `437ce9d0bea7bd7e8409877584c082c32804530217a7b5bb65879b624caba2bc`. + The published x86_64 Vinix kernel booted 32 signed network packages. It refreshed the trust store with a local CA, established loopback HTTPS, rejected the wrong hostname, committed and read a Git file, signed and verified that file with the installed SSH tools, then installed and queried a local XBPS package. The fixture and logs are `tests/userland/network.sh` and `foundation/network-guest-03`, receipt SHA-256 `4e9afac33947b999911a4ff35f218b49f3356b345e47e7b90e7ffce644d0c7b4`. An eight-package x86_64 guest tested the BusyBox wget applet and its separately packaged TLS helper. It rejected an unknown certificate, retrieved the expected bytes after installing the local CA, and rejected the same certificate for a different hostname. The guest fixture is `tests/userland/wget.sh`. The worker keeps the install, audit and serial hashes in `foundation/wget-guest-x86_64-01/receipts.sha256`, SHA-256 `5872d1467ee2594b9305bed5fa1ceb084c8c3fde4ebccb0539db25d02b3849f9`. diff --git a/tools/build-order.py b/tools/build-order.py index b95b1d7..2993a9b 100644 --- a/tools/build-order.py +++ b/tools/build-order.py @@ -72,6 +72,7 @@ def recipe_records(args): release, = info["pkgrel"] epoch, = info.get("epoch", ["0"]) info["pkgver"] = [(epoch + ":" if epoch != "0" else "") + version + "-" + release] + info["source_recipe"] = [recipe.parent.name] for name in info["pkgname"]: yield name, info @@ -125,10 +126,12 @@ def plan(args): 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"]) + columns = ["stage", "package", "version", "depends_on", "unresolved_packages"] + table.writerow(columns + (["source_recipe"] if args.recipes else [])) 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))]) + fields = [stages.get(name, "pending"), name, packages[name]["pkgver"][0], + ",".join(sorted(needs[name])), ",".join(sorted(needs[name] & remaining))] + table.writerow(fields + (packages[name]["source_recipe"] if args.recipes else [])) 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") diff --git a/tools/build-queue.py b/tools/build-queue.py index 30baaf6..c63febc 100644 --- a/tools/build-queue.py +++ b/tools/build-queue.py @@ -81,8 +81,8 @@ def record_archive(artifacts, name, filename, checksum): receipt.with_suffix(".new").replace(receipt) -def reuse_archive(args, artifacts, logs, name, version): - recipe = args.recipes / name / "PKGBUILD.vile" +def reuse_archive(args, artifacts, logs, name, version, recipe_name): + recipe = args.recipes / recipe_name / "PKGBUILD.vile" if not recipe.is_file(): return filename = f"{name}-{version}" @@ -127,17 +127,17 @@ def reuse_archive(args, artifacts, logs, name, version): print(f"Reused {name} {version} from {archive.parent}", flush=True) -def build(args, name, version, receipts, logs, artifacts): +def build(args, recipe_name, outputs, receipts, logs, artifacts): # Each package gets its own SDK and source directory. Keep the small # evidence files and signed input hashes after recycling the scratch space. scripts = Path(__file__).resolve().parents[1] / "tests" - with tempfile.TemporaryDirectory(prefix=name + "-", dir=args.work / "scratch") as tmp: + with tempfile.TemporaryDirectory(prefix=recipe_name + "-", dir=args.work / "scratch") as tmp: area = Path(tmp) (area / SCRATCH_MARKER).touch() sdk = area / "sdk" recipe = area / "port" - shutil.copytree(args.recipes / name, recipe) - with (logs / (name + "-recipe.sha256")).open("w") as source: + shutil.copytree(args.recipes / recipe_name, recipe) + with (logs / (recipe_name + "-recipe.sha256")).open("w") as source: for file in sorted(recipe.rglob("*")): if file.is_file(): source.write(f"{digest(file)} {file.relative_to(recipe)}\n") @@ -146,7 +146,7 @@ def build(args, name, version, receipts, logs, artifacts): VPAC_MAKEPKG_DB=str(sdk / "client/db"), VINIX_SYSROOT=str(sdk / "client/root")) env["PKG_CONFIG_SYSROOT_DIR"] = env["VINIX_SYSROOT"] env["PKG_CONFIG_LIBDIR"] = ":".join(env["VINIX_SYSROOT"] + d for d in ("/usr/lib/pkgconfig", "/usr/share/pkgconfig")) - with (logs / (name + "-build.log")).open("w") as log: + with (logs / (recipe_name + "-build.log")).open("w") as log: def run(cmd, **kwargs): subprocess.run(cmd, stdout=log, stderr=subprocess.STDOUT, check=True, **kwargs) try: @@ -154,23 +154,34 @@ def build(args, name, version, receipts, logs, artifacts): finally: for filename in ("selection.tsv", "audit.log", "install.log", "publish.log"): if (sdk / filename).is_file(): - shutil.copyfile(sdk / filename, logs / (name + "-sdk-" + filename)) + shutil.copyfile(sdk / filename, logs / (recipe_name + "-sdk-" + filename)) command = [args.vpac, "--native-build", recipe / "PKGBUILD.vile", manifest] if args.arch != os.uname().machine: command.append("--target=" + args.arch) run(["flock", args.lock, *command], env=env) - archive, = [Path(p) for p in manifest.read_text().splitlines() if p] - check_archive(archive, name, version, args.arch) - with (logs / (name + "-pages.tsv")).open("w") as report: - subprocess.run([sys.executable, scripts / "archive-pages.py", args.arch, archive], - check=True, stdout=report, stderr=log) - output = artifacts / archive.name - checksum = digest(archive) - if output.exists() and digest(output) != checksum: - raise ValueError(f"{name}: conflicting archive for version {version}") - if not output.exists(): - os.replace(archive, output) - record_archive(artifacts, name, output.name, checksum) + archives = {} + for path in manifest.read_text().splitlines(): + archive = Path(path) + name = archive_fields(archive, ".PKGINFO")["pkgname"] + if name not in outputs or name in archives: + raise ValueError(f"{recipe_name}: unexpected build output {name}") + version = outputs[name] + check_archive(archive, name, version, args.arch) + with (logs / (name + "-pages.tsv")).open("w") as report: + subprocess.run([sys.executable, scripts / "archive-pages.py", args.arch, archive], + check=True, stdout=report, stderr=log) + checksum = digest(archive) + output = artifacts / archive.name + if output.exists() and digest(output) != checksum: + raise ValueError(f"{name}: conflicting archive for version {version}") + archives[name] = (archive, output, checksum) + if archives.keys() != outputs.keys(): + raise ValueError(f"{recipe_name}: missing build outputs {sorted(outputs.keys() - archives.keys())}") + for archive, output, _ in archives.values(): + if not output.exists(): + os.replace(archive, output) + for name, (_, output, checksum) in archives.items(): + record_archive(artifacts, name, output.name, checksum) def run_queue(args): @@ -185,16 +196,27 @@ def run_queue(args): shutil.rmtree(old) pending = list(dict.fromkeys(args.packages)) dependencies = {name: prerequisites(name, graph) for name in pending} + recipes = {} + recipe_names = {} + for name, row in graph.items(): + recipe = row.get("source_recipe") or name + if Path(recipe).name != recipe or recipe in ("", ".", ".."): + raise ValueError(f"{name}: invalid source recipe directory {recipe!r}") + recipe_names[name] = recipe + recipes.setdefault(recipe, {})[name] = row["version"] reusable = set(pending) for deps in dependencies.values(): reusable.update(deps) for name in sorted(reusable): if args.reuse and not (artifacts / (name + ".sha256")).exists(): - reuse_archive(args, artifacts, logs, name, graph[name]["version"]) - failed = [] + reuse_archive(args, artifacts, logs, name, graph[name]["version"], recipe_names[name]) + failed = set() while pending: progress = False for name in pending.copy(): + if name in failed: + pending.remove(name) + continue receipt = artifacts / (name + ".sha256") if receipt.exists(): archive, expected = archive_from_receipt(artifacts, name, graph[name]["version"], args.arch) @@ -211,15 +233,16 @@ def run_queue(args): archive_from_receipt(artifacts, dep, graph[dep]["version"], args.arch) if shutil.disk_usage(args.work).free < args.reserve_mib * 1024**2: raise RuntimeError("build volume reached its configured free-space reserve") - print(f"Building {name} {graph[name]['version']}", flush=True) - record_limits(logs / (name + "-cgroup-before")) + recipe = recipe_names[name] + print(f"Building {recipe} {graph[name]['version']}", flush=True) + record_limits(logs / (recipe + "-cgroup-before")) try: - build(args, name, graph[name]["version"], receipts, logs, artifacts) + build(args, recipe, recipes[recipe], receipts, logs, artifacts) except (subprocess.CalledProcessError, ValueError, OSError) as error: - failed.append(name) - print(f"Failed {name}: {error}. See {logs / (name + '-build.log')}", file=sys.stderr, flush=True) + failed.update(recipes[recipe]) + print(f"Failed {recipe}: {error}. See {logs / (recipe + '-build.log')}", file=sys.stderr, flush=True) finally: - record_limits(logs / (name + "-cgroup-after")) + record_limits(logs / (recipe + "-cgroup-after")) pending.remove(name) progress = True if not progress: -- 2.56.1