me

/

vinix-ports Public
382 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

Derive target build order from verified package archives

diviocity committed 6 days ago · 47a5c59a61fcff634c73a2faca5d93063357de7b View patch
Unverified signature 2 files changed +121 -0
BOOTSTRAP.md +10 -0

@@ -13,6 +13,16 @@ Build the ports outside the source checkout. Keep a separate SDK and package dat

1313

1414The 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.

1515

16+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.

17+

18+```sh

19+python3 tools/build-order.py x86_64 "$signed_feed" "$work/order"

20+```

21+

22+`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.

23+

24+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`.

25+

1626## Running the shared worker

1727

1828The 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.

tools/build-order.py new file +111 -0

@@ -0,0 +1,111 @@

1+"""Order a Vinix feed's target packages by their recorded build, check and runtime inputs."""

2+import argparse

3+import csv

4+import hashlib

5+import re

6+import subprocess

7+from collections import defaultdict

8+from pathlib import Path

9+

10+

11+def metadata(path, expected, arch):

12+ if Path(path.name).name != expected["archive"] or "/" in expected["archive"]:

13+ raise ValueError(f"invalid archive name {expected['archive']}")

14+ with path.open("rb") as stream:

15+ if hashlib.file_digest(stream, "sha256").hexdigest() != expected["sha256"]:

16+ raise ValueError(f"checksum mismatch for {path}")

17+ raw = subprocess.check_output(["bsdtar", "-xOf", path, ".PKGINFO"], text=True)

18+ values = defaultdict(list)

19+ for line in raw.splitlines():

20+ if " = " in line:

21+ key, value = line.split(" = ", 1)

22+ values[key].append(value)

23+ if (values["pkgname"] != [expected["name"]] or values["pkgver"] != [expected["version"]] or

24+ values["arch"] not in (["any"], [arch])):

25+ raise ValueError(f"invalid metadata for {path}")

26+ return values

27+

28+

29+def requirement(text):

30+ match = re.fullmatch(r"([^<>=\s]+)(?:(>=|<=|=|<|>)([^<>=\s]+))?", text)

31+ if not match:

32+ raise ValueError(f"invalid dependency expression {text!r}")

33+ return match.groups()

34+

35+

36+def satisfies(version, operator, requested):

37+ if not operator:

38+ return True

39+ if version is None:

40+ return False

41+ result = int(subprocess.check_output(["vercmp", version, requested], text=True))

42+ return {"=": result == 0, ">=": result >= 0, "<=": result <= 0,

43+ ">": result > 0, "<": result < 0}[operator]

44+

45+

46+def plan(args):

47+ providers = defaultdict(list)

48+ 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))

62+ if not packages:

63+ raise ValueError("empty feed")

64+ edges = []

65+ needs = {name: set() for name in packages}

66+ waiting = set()

67+ for name, info in packages.items():

68+ for kind in ("depend", "makedepend", "checkdepend"):

69+ for spec in info[kind]:

70+ dependency, operator, requested = requirement(spec)

71+ choices = {pkg for pkg, ver in providers[dependency] if satisfies(ver, operator, requested)}

72+ if dependency in choices:

73+ choices = {dependency}

74+ if len(choices) == 1:

75+ provider, = choices

76+ if provider != name:

77+ needs[name].add(provider)

78+ else:

79+ waiting.add(name)

80+ provider = "missing" if not choices else "choose:" + ",".join(sorted(choices))

81+ edges.append((name, kind, spec, provider))

82+ stages = {}

83+ remaining = set(packages)

84+ level = 0

85+ while ready := {n for n in remaining - waiting if needs[n] <= stages.keys()}:

86+ for name in ready:

87+ stages[name] = level

88+ remaining -= ready

89+ level += 1

90+ args.output.mkdir()

91+ with (args.output / "edges.tsv").open("x") as stream:

92+ table = csv.writer(stream, delimiter="\t", lineterminator="\n")

93+ table.writerow(["package", "kind", "requirement", "selected_provider"])

94+ table.writerows(sorted(edges))

95+ with (args.output / "order.tsv").open("x") as stream:

96+ table = csv.writer(stream, delimiter="\t", lineterminator="\n")

97+ table.writerow(["stage", "package", "version", "depends_on", "unresolved_packages"])

98+ for name in sorted(packages, key=lambda n: (stages.get(n, level), n)):

99+ table.writerow([stages.get(name, "pending"), name, packages[name]["pkgver"][0],

100+ ",".join(sorted(needs[name])), ",".join(sorted(needs[name] & remaining))])

101+ print(f"{args.arch}: ordered {len(stages)} of {len(packages)} packages in {level} stages")

102+ if remaining:

103+ raise SystemExit(f"unresolved providers or cycles: {', '.join(sorted(remaining))}; see edges.tsv")

104+

105+

106+if __name__ == "__main__":

107+ parser = argparse.ArgumentParser(description=__doc__)

108+ parser.add_argument("arch", choices=("x86_64", "aarch64"))

109+ parser.add_argument("feed", type=Path)

110+ parser.add_argument("output", type=Path)

111+ plan(parser.parse_args())