1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/sh
# Offline contracts by default; FPKGS_TEST_REAL_APK=1 exercises real signed APKs.
set -eu
root=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
(
. "$root/scripts/functions.sh"
unset FPKGS_FORMAT
case "$(canonical_os)" in
Linux)
[ "$(package_format)" = apk ]
case "$(default_target apk)" in *-alpine-linux-musl) ;; *) exit 1 ;; esac ;;
*) [ "$(package_format)" = tar.gz ] ;;
esac
FPKGS_FORMAT=tar.gz
[ "$(package_format)" = tar.gz ]
[ "$(default_target tar.gz)" = "$(guess_triplet)" ]
)
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
trap 'exit 1' HUP INT TERM
mkdir -p "$work/repo/noarch/fixture" "$work/repo/scripts" "$work/bin"
cp "$root/scripts/"*.sh "$work/repo/scripts/"
chmod +x "$work/repo/scripts/"*.sh
cat >"$work/repo/noarch/fixture/APKBUILD" <<'RECIPE'
pkgname=fixture
pkgver=1.0
pkgrel=0
pkgdesc="Disposable APK backend test"
url="https://example.invalid"
arch="noarch"
license="MIT"
subpackages="$pkgname-data"
source=""
builddir="$srcdir"
build() {
if cross_compiling; then echo cross >"$srcdir/checked"; fi
}
check() { echo checked >"$srcdir/checked"; }
package() {
mkdir -p "$pkgdir/usr/share/fixture"
cp "$srcdir/checked" "$pkgdir/usr/share/fixture/checked"
}
data() {
mkdir -p "$subpkgdir/usr/share/fixture-data"
echo data >"$subpkgdir/usr/share/fixture-data/content"
}
RECIPE
if [ "${FPKGS_TEST_REAL_APK:-0}" != 1 ]; then
cat >"$work/bin/abuild" <<'STUB'
#!/bin/sh
set -eu
[ "$1" != -V ] || { echo 'abuild contract-test stub'; exit; }
[ "$#" -eq 1 ] && [ "$1" = -d ]
[ -n "$CBUILD" ] && [ "$CHOST" = x86_64-alpine-linux-musl ]
[ -z "${FPKGS_TEST_EXPECT_CBUILD:-}" ] || [ "$CBUILD" = "$FPKGS_TEST_EXPECT_CBUILD" ]
[ -n "$SRCDEST" ]
for name in srcdir pkgdir subpkgdir tmpdir startdir builddir pkgbasedir workdir destdir; do
eval value=\${$name-}
[ -z "$value" ] || { echo "Inherited CI staging variable: $name" >&2; exit 1; }
done
touch generated-only-in-copy
out=$REPODEST/noarch/x86_64
mkdir -p "$out"
printf main >"$out/fixture-1.0-r0.apk"
printf split >"$out/fixture-data-1.0-r0.apk"
printf index >"$out/APKINDEX.tar.gz"
STUB
chmod +x "$work/bin/abuild"
export FPKGS_ABUILD=$work/bin/abuild
# Native musl must not be mistaken for cross compilation just due to vendor.
mkdir -p "$work/platform-bin"
printf '#!/bin/sh\ncase "$1" in -s) echo Linux ;; -m) echo x86_64 ;; esac\n' >"$work/platform-bin/uname"
printf '#!/bin/sh\necho musl\n' >"$work/platform-bin/ldd"
chmod +x "$work/platform-bin/"*
(unset FPKGS_FORMAT; PATH="$work/platform-bin:$PATH" FPKGS_TEST_EXPECT_CBUILD=x86_64-alpine-linux-musl sh "$root/scripts/build.sh" -o "$work/musl-dist" "$work/repo/noarch/fixture/APKBUILD") >"$work/musl.log" 2>&1 || { cat "$work/musl.log"; exit 1; }
fi
export FPKGS_ROOT=$work/repo FPKGS_WORK_ROOT=$work/cache FPKGS_DL_ROOT=$work/published
export FPKGS_DL_BASE_URL=https://artifacts.invalid
export FPKGS_FORMAT=apk FPKGS_TARGETS=x86_64-alpine-linux-musl
if [ "${FPKGS_TEST_REAL_APK:-0}" = 1 ]; then
# Upstream intentionally skips execution checks for cross builds.
FPKGS_TARGETS=$(. "$root/scripts/functions.sh"; guess_triplet)
fi
mkdir -p "$FPKGS_DL_ROOT"
cd "$work/repo"
git init -q
git add .
git -c user.name=Test -c user.email=test@example.invalid commit -qm fixture
rev=$(git rev-parse HEAD)
cli=$root/scripts/fpkgs-ci.sh
apk_key=$(sh "$cli" key noarch/fixture/APKBUILD "$FPKGS_TARGETS" "$rev")
tar_key=$(FPKGS_FORMAT=tar.gz sh "$cli" key noarch/fixture/APKBUILD "$FPKGS_TARGETS" "$rev")
[ "$apk_key" != "$tar_key" ]
systemd_key=$(FPKGS_INIT_SYSTEM=systemd sh "$cli" key noarch/fixture/APKBUILD "$FPKGS_TARGETS" "$rev")
openrc_key=$(FPKGS_INIT_SYSTEM=openrc sh "$cli" key noarch/fixture/APKBUILD "$FPKGS_TARGETS" "$rev")
[ "$systemd_key" != "$openrc_key" ]
FPKGS_PACKAGES=not-selected sh "$cli" plan "$rev" >"$work/filter"
[ ! -s "$work/filter" ]
FPKGS_PACKAGES=fixture sh "$cli" plan "$rev" >"$work/filter"
[ "$(wc -l <"$work/filter" | tr -d ' ')" -eq 1 ]
mkdir -p "$work/minci-source" "$work/minci-pkg" "$work/minci-work"
printf sentinel >"$work/minci-source/keep"
srcdir="$work/minci-source" pkgdir="$work/minci-pkg" workdir="$work/minci-work" \
sh "$cli" run "$rev" >"$work/run.log" 2>&1 || {
cat "$work/run.log"
find "$FPKGS_WORK_ROOT/build" -name build.log -exec tail -n 100 {} \;
exit 1
}
[ ! -f noarch/fixture/generated-only-in-copy ]
[ "$(cat "$work/minci-source/keep")" = sentinel ]
sh "$cli" status fixture "$FPKGS_TARGETS" "$rev" >"$work/status"
grep -q '^format=apk$' "$work/status"
grep -q '/noarch/x86_64/fixture-1.0-r0.apk$' "$work/status"
archive=$(awk -F= '$1=="artifact_path" {print $2}' "$work/status")
out=${archive%/noarch/x86_64/*}
[ -f "$out/noarch/x86_64/fixture-data-1.0-r0.apk" ]
[ -f "$out/noarch/x86_64/APKINDEX.tar.gz" ]
if [ "${FPKGS_TEST_REAL_APK:-0}" = 1 ]; then
${APK:-apk} verify "$archive" "$out/noarch/x86_64/fixture-data-1.0-r0.apk"
tar -xOzf "$archive" usr/share/fixture/checked | grep -q '^checked$'
# Also exercise the actual Linux default, including upstream cross semantics.
(unset FPKGS_FORMAT; sh scripts/build.sh -o "$work/default-dist" noarch/fixture) >"$work/default.log" 2>&1 || { cat "$work/default.log"; exit 1; }
default_archive=$(find "$work/default-dist" -name fixture-1.0-r0.apk)
case "$default_archive" in */x86_64-alpine-linux-musl/*) ;; *) exit 1 ;; esac
${APK:-apk} verify "$default_archive"
tar -xOzf "$default_archive" usr/share/fixture/checked | grep -q '^cross$'
fi
sh "$cli" plan "$rev" >"$work/plan"
grep -q '^skip ' "$work/plan"
printf corruption >>"$out/noarch/x86_64/fixture-data-1.0-r0.apk"
code=0
sh "$cli" status fixture "$FPKGS_TARGETS" "$rev" >"$work/status" || code=$?
[ "$code" -eq 2 ]
sh "$cli" plan "$rev" >"$work/plan"
grep -q '^build ' "$work/plan"
sh "$cli" run "$rev" >"$work/rebuild.log" 2>&1 || { cat "$work/rebuild.log"; exit 1; }
sh "$cli" status fixture "$FPKGS_TARGETS" "$rev" >/dev/null
printf corruption >>"$out/noarch/x86_64/APKINDEX.tar.gz"
code=0
sh "$cli" status fixture "$FPKGS_TARGETS" "$rev" >"$work/status" || code=$?
[ "$code" -eq 2 ]
if sh scripts/build.sh -f apk -s "$work/unused" noarch/fixture >"$work/rejected" 2>&1; then
echo 'Legacy dependency staging unexpectedly accepted for APK' >&2; exit 1
fi
if sh scripts/build.sh -f invalid noarch/fixture >"$work/rejected" 2>&1; then
echo 'Invalid package format unexpectedly accepted' >&2; exit 1
fi
if FPKGS_FORMAT=invalid sh "$cli" plan "$rev" >"$work/rejected" 2>&1; then
echo 'Invalid CI package format unexpectedly accepted' >&2; exit 1
fi
# A missing tool must fail without creating a successful publication.
before=$(find "$FPKGS_DL_ROOT" -name manifest | wc -l)
if FPKGS_ABUILD="$work/absent" sh "$cli" run "$rev" >"$work/failed.log" 2>&1; then
echo 'Missing abuild unexpectedly succeeded' >&2; exit 1
fi
[ "$before" = "$(find "$FPKGS_DL_ROOT" -name manifest | wc -l)" ]
# Keep the legacy backend and its flat publication layout working on Linux too.
cat >noarch/fixture/APKBUILD <<'LEGACY'
pkgname=fixture
pkgver=1.0
pkgrel=0
arch=noarch
source=""
build() { :; }
package() {
mkdir -p "$pkgdir/usr/share/fixture"
echo legacy >"$pkgdir/usr/share/fixture/content"
}
LEGACY
git add noarch/fixture/APKBUILD
git -c user.name=Test -c user.email=test@example.invalid commit -qm legacy
rev=$(git rev-parse HEAD)
export FPKGS_FORMAT=tar.gz FPKGS_TARGETS=x86_64-unknown-linux-gnu
sh "$cli" run "$rev" >"$work/legacy.log" 2>&1 || { cat "$work/legacy.log"; exit 1; }
sh "$cli" status fixture "$FPKGS_TARGETS" "$rev" >"$work/status"
grep -q '^format=tar.gz$' "$work/status"
archive=$(awk -F= '$1=="artifact_path" {print $2}' "$work/status")
[ -f "$archive" ]
[ -f "${archive%/*}/manifest" ]
echo 'PASS: APK/tar dispatch, split/index publication, format-sensitive keys, verified cache, corruption/rebuild, isolation, tool failures'