Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/all
Original file line number Diff line number Diff line change
Expand Up @@ -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
54 changes: 54 additions & 0 deletions tests/build-packages-cache
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/local-builds
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions tests/pinned-packages
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions tools/build-packages
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down