From e16f48b9c5f4c7a60ec66e5af7be1e07191ed061 Mon Sep 17 00:00:00 2001 From: Nate Crawford Date: Sun, 8 Nov 2026 01:01:59 -0600 Subject: [PATCH 1/2] build-packages: drop a stale cached package after a same-version rebuild A forced rebuild can replace a package's bytes without changing its file name. The pacman cache that tools/build-packages and tools/build-rootfs share ($ALARM_CACHE/pkg, mounted as /var/cache/pacman/pkg) still holds the old file under that name, so the next pacstrap takes the cached copy, whose checksum no longer matches the rebuilt repository's database. add_to_repo now removes a cached file of the same name, and its detached signature, when its bytes differ from the package just added; identical cache entries and other packages are left alone. tests/build-packages-cache runs the real add_to_repo with synthetic package files: a differing cache entry and its signature are removed, an identical one is kept with its signature, an unrelated package is kept, and a local import keeps the signature it came with. Co-Authored-By: Claude Opus 5.5 --- tests/all | 2 +- tests/build-packages-cache | 54 ++++++++++++++++++++++++++++++++++++++ tools/build-packages | 5 ++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100755 tests/build-packages-cache diff --git a/tests/all b/tests/all index 764e66a84..b2f106c62 100755 --- a/tests/all +++ b/tests/all @@ -53,7 +53,7 @@ python3 tests/boot-arch-label.py python3 tests/persistent-root-boot.py python3 tests/initramfs-root-policy.py python3 tests/bt-uart-gpio.py -for t in tests/pr-check tests/kernel-pr-check tests/phone-smoke tests/alarm-wake-test tests/install-phone tests/build-rootfs tests/rootfs-placeholders tests/rootfs-resolve tests/phone-provision tests/nv-backup tests/initramfs-grow tests/images-layout tests/boot-update-parity tests/stage-boot-files tests/build-packages-host-tools tests/initramfs-reproducible tests/device-overlays tests/simplefb-trigger tests/initramfs-steps tests/storage-guard tests/usb-product tests/grep-q-pipes tests/boot-method tests/modules-push tests/make-bundle-keys tests/make-bundle tests/release-signing tests/pinned-packages tests/flame-probe tests/dipper-probe packages/omamobile-firstboot/test/all packages/omamobile-device-felix/test/all packages/omamobile-device-lynx/test/all packages/omamobile-device-panther/test/all tests/local-builds tests/phone-install-package tests/publish-kernel tests/fetch-toolchain tests/release-upload tests/extract-camera-data tests/release tests/build-host-sync tests/lineage-ref tests/repo-publish tests/repo-publish-stage tests/extract-vendor-firmware tests/alpine-fetch-callers tests/alpine-fetch tests/tools-help tests/install-phone-initramfs tests/install-slot-descriptor; do +for t in tests/pr-check tests/kernel-pr-check tests/phone-smoke tests/alarm-wake-test tests/install-phone tests/build-rootfs tests/build-packages-cache tests/rootfs-placeholders tests/rootfs-resolve tests/phone-provision tests/nv-backup tests/initramfs-grow tests/images-layout tests/boot-update-parity tests/stage-boot-files tests/build-packages-host-tools tests/initramfs-reproducible tests/device-overlays tests/simplefb-trigger tests/initramfs-steps tests/storage-guard tests/usb-product tests/grep-q-pipes tests/boot-method tests/modules-push tests/make-bundle-keys tests/make-bundle tests/release-signing tests/pinned-packages tests/flame-probe tests/dipper-probe packages/omamobile-firstboot/test/all packages/omamobile-device-felix/test/all packages/omamobile-device-lynx/test/all packages/omamobile-device-panther/test/all tests/local-builds tests/phone-install-package tests/publish-kernel tests/fetch-toolchain tests/release-upload tests/extract-camera-data tests/release tests/build-host-sync tests/lineage-ref tests/repo-publish tests/repo-publish-stage tests/extract-vendor-firmware tests/alpine-fetch-callers tests/alpine-fetch tests/tools-help tests/install-phone-initramfs tests/install-slot-descriptor; do echo "# $t" "$t" done diff --git a/tests/build-packages-cache b/tests/build-packages-cache new file mode 100755 index 000000000..eb9e84b93 --- /dev/null +++ b/tests/build-packages-cache @@ -0,0 +1,54 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +python3 - <<'PYTEST' +"""Exercise same-version rebuild cache invalidation without Docker/signing.""" +from pathlib import Path +import subprocess +import tempfile + +root = Path.cwd() +source = (root / 'tools/build-packages').read_text() +a = source.index('add_to_repo() {') +b = source.index('\n}\n', a) + 3 +function = source[a:b] +with tempfile.TemporaryDirectory() as directory: + p = Path(directory) + for name in ('repo', 'cache/pkg', 'built'): + (p / name).mkdir(parents=True) + base = 'device-0.1.0-1-aarch64.pkg.tar.zst' + rebuilt = p / 'built' / base + rebuilt.write_text('pkgname = device\nnew bytes\n') + cached = p / 'cache/pkg' / base + signature = Path(str(cached) + '.sig') + unrelated = p / 'cache/pkg/other.pkg.tar.zst' + unrelated.write_text('untouched') + command = '''set -euo pipefail +repo=$1/repo; ALARM_CACHE=$1/cache +local_name=${2:-} +pkginfo() { cat "$1"; } +alarm_die() { exit 99; } +''' + function + '\nadd_to_repo "$1/built/' + base + '"\n' + cached.write_text('pkgname = device\nstale bytes\n') + signature.write_text('stale signature') + subprocess.run(['bash', '-c', command, 'test', str(p)], check=True, + stdout=subprocess.DEVNULL) + assert not cached.exists() and not signature.exists() + assert unrelated.read_text() == 'untouched' + assert (p / 'repo' / base).read_bytes() == rebuilt.read_bytes() + cached.write_bytes(rebuilt.read_bytes()) + signature.write_text('matching signature') + subprocess.run(['bash', '-c', command, 'test', str(p)], check=True, + stdout=subprocess.DEVNULL) + assert cached.exists() and signature.read_text() == 'matching signature' + imported_signature = Path(str(rebuilt) + '.sig') + imported_signature.write_text('imported signature') + subprocess.run(['bash', '-c', command, 'test', str(p), 'comet'], check=True, + stdout=subprocess.DEVNULL) + assert (p / 'repo' / (base + '.sig')).read_text() == 'imported signature' +print('ok - forced same-version rebuild removes stale cached bytes and signature') +print('ok - identical and unrelated cache entries remain') +print('ok - a local import retains its supplied signature') + +PYTEST diff --git a/tools/build-packages b/tools/build-packages index 6f87fd474..832f7798c 100755 --- a/tools/build-packages +++ b/tools/build-packages @@ -201,6 +201,11 @@ add_to_repo() { cp -f "$file" "$repo/$base" rm -f "$repo/$base.sig" if [[ -n $local_name && -f $file.sig ]]; then cp -f "$file.sig" "$repo/$base.sig"; fi + # A forced rebuild can replace bytes without changing the filename. + # Pacstrap must fetch the replacement and its new signature together. + if [[ -f $ALARM_CACHE/pkg/$base ]] && ! cmp -s "$repo/$base" "$ALARM_CACHE/pkg/$base"; then + rm -f -- "$ALARM_CACHE/pkg/$base" "$ALARM_CACHE/pkg/$base.sig" + fi echo " $base" done } From 07292a063595cc049278d45f028a636dc9e0fd6e Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Wed, 18 Nov 2026 13:12:25 -0500 Subject: [PATCH 2/2] tests: the cache suite on its own line, and no test touches the developer's package cache tests/build-packages-cache moves to the one-suite-per-line block at the end of tests/all, and tests/local-builds and tests/pinned-packages set ALARM_CACHE to their scratch folder, since add_to_repo now removes from the cache. Co-Authored-By: Claude Fable 5.2 --- tests/all | 4 +++- tests/local-builds | 1 + tests/pinned-packages | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/all b/tests/all index b2f106c62..be2267308 100755 --- a/tests/all +++ b/tests/all @@ -53,7 +53,7 @@ python3 tests/boot-arch-label.py python3 tests/persistent-root-boot.py python3 tests/initramfs-root-policy.py python3 tests/bt-uart-gpio.py -for t in tests/pr-check tests/kernel-pr-check tests/phone-smoke tests/alarm-wake-test tests/install-phone tests/build-rootfs tests/build-packages-cache tests/rootfs-placeholders tests/rootfs-resolve tests/phone-provision tests/nv-backup tests/initramfs-grow tests/images-layout tests/boot-update-parity tests/stage-boot-files tests/build-packages-host-tools tests/initramfs-reproducible tests/device-overlays tests/simplefb-trigger tests/initramfs-steps tests/storage-guard tests/usb-product tests/grep-q-pipes tests/boot-method tests/modules-push tests/make-bundle-keys tests/make-bundle tests/release-signing tests/pinned-packages tests/flame-probe tests/dipper-probe packages/omamobile-firstboot/test/all packages/omamobile-device-felix/test/all packages/omamobile-device-lynx/test/all packages/omamobile-device-panther/test/all tests/local-builds tests/phone-install-package tests/publish-kernel tests/fetch-toolchain tests/release-upload tests/extract-camera-data tests/release tests/build-host-sync tests/lineage-ref tests/repo-publish tests/repo-publish-stage tests/extract-vendor-firmware tests/alpine-fetch-callers tests/alpine-fetch tests/tools-help tests/install-phone-initramfs tests/install-slot-descriptor; do +for t in tests/pr-check tests/kernel-pr-check tests/phone-smoke tests/alarm-wake-test tests/install-phone tests/build-rootfs tests/rootfs-placeholders tests/rootfs-resolve tests/phone-provision tests/nv-backup tests/initramfs-grow tests/images-layout tests/boot-update-parity tests/stage-boot-files tests/build-packages-host-tools tests/initramfs-reproducible tests/device-overlays tests/simplefb-trigger tests/initramfs-steps tests/storage-guard tests/usb-product tests/grep-q-pipes tests/boot-method tests/modules-push tests/make-bundle-keys tests/make-bundle tests/release-signing tests/pinned-packages tests/flame-probe tests/dipper-probe packages/omamobile-firstboot/test/all packages/omamobile-device-felix/test/all packages/omamobile-device-lynx/test/all packages/omamobile-device-panther/test/all tests/local-builds tests/phone-install-package tests/publish-kernel tests/fetch-toolchain tests/release-upload tests/extract-camera-data tests/release tests/build-host-sync tests/lineage-ref tests/repo-publish tests/repo-publish-stage tests/extract-vendor-firmware tests/alpine-fetch-callers tests/alpine-fetch tests/tools-help tests/install-phone-initramfs tests/install-slot-descriptor; do echo "# $t" "$t" done @@ -98,3 +98,5 @@ echo "# tests/rootfs-smoke-link" # the smoke test's install-link checks, on sm tests/rootfs-smoke-link echo "# tests/build-packages-deps" # a package's dependencies into the build container, behind a library change too tests/build-packages-deps +echo "# tests/build-packages-cache" # a forced same-version rebuild drops the stale cached package +tests/build-packages-cache diff --git a/tests/local-builds b/tests/local-builds index e2cb9f170..f84aa53b4 100755 --- a/tests/local-builds +++ b/tests/local-builds @@ -13,6 +13,7 @@ fail() { printf 'not ok - %s\n' "$1" >&2; exit 1; } pass() { printf 'ok - %s\n' "$1"; } command -v gpg >/dev/null && command -v gpgv >/dev/null || { pass "# skip: no gpg"; exit 0; } t=$(mktemp -d) +export ALARM_CACHE=$t/cache # add_to_repo removes from the package cache: never the developer's own export GNUPGHOME=$t/home && mkdir -m 700 "$GNUPGHOME" # never the user's ~/.gnupg trap 'gpgconf --homedir "$t/signer" --kill gpg-agent 2>/dev/null || true; gpgconf --homedir "$t/other" --kill gpg-agent 2>/dev/null || true; rm -rf "$t"' EXIT diff --git a/tests/pinned-packages b/tests/pinned-packages index edf58de52..8ea52fbbb 100755 --- a/tests/pinned-packages +++ b/tests/pinned-packages @@ -18,6 +18,7 @@ for tool in gpg repo-add bsdtar zstd curl; do command -v "$tool" >/dev/null || { pass "# skip: no $tool"; exit 0; } done t=$(mktemp -d) +export ALARM_CACHE=$t/cache # add_to_repo removes from the package cache: never the developer's own export GNUPGHOME=$t/home && mkdir -m 700 "$GNUPGHOME" # never the user's ~/.gnupg R=$t/repo cleanup() {