Files
glacier-ng/tests/recipe_alpine.sh
T
2026-10-29 09:15:34 -04:00

410 lines
22 KiB
Bash

#!/bin/sh
# Recipe formats (BUILD_DESIGN.txt sections 3, 4 and 8; step 1):
# - gl_recipe_parse: the recipe's fields, strictly (unknown keys,
# missing required ones, bad names, versions, URLs, hashes, traits,
# IF conditions, arguments, @include and NUL are all refused);
# - gl_recipe_read: a bundle holds exactly NAME-VER/{recipe,build,
# patches/FILE}, regular files and directories only, the patches
# PATCHES lists, a build file for BUILD = "hooks", 16 MiB at most;
# - gl_index_parse: a REPO named X-src has BUILD_DEPS, TRAITS, IF and
# .grcp files; a binary index has none of them;
# - PKG_TRAITS in a manifest, read by gl_read_pkg_manifest;
# - grepo -r X-src indexes DIR's bundles, and syspkg -y accepts it.
# Runs INSIDE the Dockerfile.alpine_root image:
#
# docker run --rm -v "$PWD/tests/recipe_alpine.sh:/t.sh:ro" glacier-alpine_root sh /t.sh
FAILS=0
check() { d=$1; shift; if "$@"; then echo "PASS: $d"; else echo "FAIL: $d"; FAILS=$((FAILS+1)); fi; }
nocolor() { sed 's/\x1b\[[0-9;]*m//g'; }
R() {
OUT=$( ("$@"; echo "rc=$?") 2>&1 | nocolor)
RC=$(echo "$OUT" | sed -n 's/^rc=//p' | tail -1)
echo "$OUT" | sed '/^rc=/d; s/^/ /'
}
has() { echo "$OUT" | grep -qF -- "$1"; }
lacks() { ! has "$1"; }
rc() { [ "$RC" = "$1" ]; }
hr() { echo; echo "== $*"; }
export PATH=/app:$PATH
T=/tmp/rt
mkdir -p $T
SHA=sha256:$(printf '%064d' 0 | tr 0 a)
# probe parse FILE | read BUNDLE | index REPO FILE | manifest GPKG
# prints "status=N" and the parsed fields.
cat > $T/probe.lua <<'EOF'
package.path = "/app/?.lua;" .. package.path
local ffi = require("ffi")
require("lib/glacier_cdef")
local pkg = ffi.load("/app/lib/glacier/libglacier_pkg.so")
local ist = ffi.load("/app/lib/glacier/libglacier_istoreutils.so")
local mode, a, b = arg[1], arg[2], arg[3]
local function slurp(p) local f = assert(io.open(p, "rb")); local s = f:read("*a"); f:close(); return s end
local function show(k, v) if v ~= nil then io.write(k, "=[", ffi.string(v), "]\n") end end
if mode == "parse" or mode == "read" then
local r = ffi.new("gl_recipe_t")
local st
if mode == "parse" then
-- parse FILE FIRST: FIRST is parsed before, in this process
if b then
local f = slurp(b)
pkg.gl_recipe_parse(f, #f, r)
end
local s = slurp(a)
st = pkg.gl_recipe_parse(s, #s, r)
else
st = ist.gl_recipe_read(a, r)
end
print("status=" .. tonumber(st))
print("why=[" .. ffi.string(pkg.gl_recipe_error()) .. "]")
if st == 0 then
for _, k in ipairs({ "name", "ver", "repo", "desc", "maint", "copyright",
"sources", "patches", "build", "configure", "traits", "trait_args",
"deps", "build_deps", "confs" }) do
show(k, r[k])
end
pkg.gl_recipe_free(r)
end
elseif mode == "index" then
local s = slurp(b)
local idx = ffi.new("gl_index_t")
local st = pkg.gl_index_parse(s, #s, a, idx)
print("status=" .. tonumber(st))
if st == 0 then
for k = 0, tonumber(idx.npkgs) - 1 do
local p = idx.pkgs[k]
show("file", p.file); show("deps", p.deps); show("confs", p.confs)
show("build_deps", p.build_deps); show("traits", p.traits)
end
pkg.gl_index_free(idx)
end
elseif mode == "manifest" then
local m = ffi.new("gl_pkg_t")
local st = ist.gl_read_pkg_manifest(a, m)
print("status=" .. tonumber(st))
if st == 0 then
if m.pkg_traits == nil then print("traits=NULL") else show("traits", m.pkg_traits) end
ist.gl_free_pkg(m)
end
end
EOF
probe() { R luajit $T/probe.lua "$@"; }
# A good recipe; variants are made from it with sed.
cat > $T/good <<EOF
NAME = "curl";
VER = "8.9.0";
REPO = "extra";
DESC = "URL transfer tool";
MAINT = "maint@example.org";
COPYRIGHT = "curl";
SOURCES = (
{ URL = "https://curl.se/download/curl-8.9.0.tar.gz"; SHA256 = "$SHA"; },
{ URL = "file:///srv/mirror/extra-data.tar.gz"; SHA256 = "$SHA"; }
);
PATCHES = [ "01-a.patch", "02-b.patch" ];
BUILD = "autotools";
CONFIGURE = [ "--disable-static", "--with-ca-path=/etc/ssl certs" ];
TRAITS = (
{ NAME = "ssl"; DEFAULT = true; ON = [ "--with-openssl" ]; OFF = [ "--without-ssl" ]; },
{ NAME = "ldap"; DEFAULT = false; }
);
DEPS = ( { NAME = "zlib"; VER = "1.3.0"; }, { NAME = "libressl"; VER = "3.9.0"; IF = "ssl"; } );
BUILD_DEPS = ( { NAME = "perl"; VER = "5.40.0"; IF = "-ldap"; } );
CONFS = ( { NAME = "curl-old"; VER = "0.0.0"; } );
EOF
hr "gl_recipe_parse"
probe parse $T/good
check "a good recipe parses" has "status=0"
check "...name, version, repo" sh -c 'echo "$0" | grep -q "^name=\[curl\]" && echo "$0" | grep -q "^ver=\[8.9.0\]" && echo "$0" | grep -q "^repo=\[extra\]"' "$OUT"
check "...sources as URL + hash lines" has "https://curl.se/download/curl-8.9.0.tar.gz $SHA"
check "...patches in order" sh -c 'echo "$0" | tr "\n" "|" | grep -qF "patches=[01-a.patch|02-b.patch|]"' "$OUT"
check "...configure arguments, spaces kept" has "--with-ca-path=/etc/ssl certs"
check "...traits with their defaults" sh -c 'echo "$0" | tr "\n" "|" | grep -qF "traits=[ssl 1|ldap 0|]"' "$OUT"
check "...trait arguments, ON and OFF" sh -c 'echo "$0" | tr "\n" "|" | grep -qF "trait_args=[ssl + --with-openssl|ssl - --without-ssl|]"' "$OUT"
check "...deps with their IF" sh -c 'echo "$0" | tr "\n" "|" | grep -qF "deps=[zlib 1.3.0|libressl 3.9.0 ssl|]"' "$OUT"
check "...build deps, a negated IF" has "build_deps=[perl 5.40.0 -ldap"
check "...build system" has "build=[autotools]"
cat > $T/minimal <<EOF
NAME = "hi"; VER = "1.0.0"; REPO = "extra"; DESC = "d"; MAINT = "m"; COPYRIGHT = "MIT";
SOURCES = ( { URL = "https://example.org/hi-1.0.0.tar.gz"; SHA256 = "$SHA"; } );
EOF
probe parse $T/minimal
check "only the required fields: parses" has "status=0"
check "...BUILD absent = autodetect (empty)" has "build=[]"
check "...the optional lists are empty" sh -c 'echo "$0" | grep -q "^deps=\[\]" && echo "$0" | grep -q "^traits=\[\]" && echo "$0" | grep -q "^patches=\[\]"' "$OUT"
# bad DESCRIPTION SED-EXPRESSION WHY: the variant must be refused, and
# gl_recipe_error must say WHY (BUILD_DESIGN section 4)
bad() {
sed "$2" $T/good > $T/bad
probe parse $T/bad
check "refused: $1" has "status=3"
check "...because: $3" has "why=[$3"
}
bad "an unknown key" 's/^REPO = "extra";/REPO = "extra"; SOURCE = "x";/' 'unknown setting SOURCE]'
bad "a misspelt optional key" 's/^BUILD_DEPS/BUILDDEPS/' 'unknown setting BUILDDEPS]'
bad "no NAME" '/^NAME/d' 'NAME is missing]'
bad "no SOURCES" '/^SOURCES/,/^);/d' 'SOURCES is missing]'
bad "an empty SOURCES" '/^SOURCES/,/^);/c SOURCES = ();' 'SOURCES must be a non-empty list'
bad "no DESC" '/^DESC/d' 'DESC is missing]'
bad "an empty MAINT" 's/^MAINT = .*/MAINT = "";/' 'MAINT must be non-empty text without control characters]'
bad "a control character in DESC" 's/^DESC = .*/DESC = "a\\tb";/' 'DESC must be non-empty text'
bad "a name with a slash" 's/^NAME = .*/NAME = "a\/b";/' 'NAME must be a package name'
bad "NAME = .." 's/^NAME = .*/NAME = "..";/' 'NAME must be a package name'
bad "a two-part version" 's/^VER = .*/VER = "8.9";/' 'VER must be a version X.Y.Z'
bad "a version with a leading zero" 's/^VER = .*/VER = "8.09.0";/' 'VER must be a version X.Y.Z'
bad "a version with a tag" 's/^VER = .*/VER = "8.9.0-rc1";/' 'VER must be a version X.Y.Z'
bad "REPO naming a -src repository" 's/^REPO = .*/REPO = "extra-src";/' 'REPO must be the binary repository'
bad "an http:// source" 's|https://curl.se|http://curl.se|' 'SOURCES entry 1: URL must be https:// or file://'
bad "a source with no file name" 's|curl-8.9.0.tar.gz|curl/|' 'SOURCES entry 1: the URL must end in a file name'
bad "a source whose file name is .." 's|curl-8.9.0.tar.gz|..|' 'SOURCES entry 1: the URL must end in a file name'
bad "two sources with one file name" 's|extra-data.tar.gz|curl-8.9.0.tar.gz|' 'SOURCES entries 1 and 2 are both named curl-8.9.0.tar.gz]'
bad "a source without SHA256" "s|SHA256 = \"$SHA\"; },|},|" 'SOURCES entry 1 must have exactly URL and SHA256]'
bad "an uppercase hash" "/curl.se/s/$SHA/sha256:$(printf '%064d' 0 | tr 0 A)/" 'SOURCES entry 1: SHA256 must be "sha256:" followed by 64 lowercase hex digits]'
bad "a short hash" "/curl.se/s/$SHA/sha256:abc/" 'SOURCES entry 1: SHA256 must be'
bad "an unknown member in a source" 's|SHA256 = "\(sha256:[a-f]*\)"; },|SHA256 = "\1"; MIRROR = "x"; },|' 'SOURCES entry 1 must have exactly URL and SHA256]'
bad "a patch name with a slash" 's|01-a.patch|../a.patch|' 'PATCHES entry 1 must be a file name'
bad "a patch listed twice" 's|02-b.patch|01-a.patch|' 'PATCHES lists "01-a.patch" twice]'
bad "an unknown BUILD" 's/^BUILD = .*/BUILD = "scons";/' 'BUILD must be autotools, cmake, meson, make or hooks]'
bad "BUILD = \"\"" 's/^BUILD = .*/BUILD = "";/' 'BUILD must be autotools'
bad "a configure argument with a newline" 's|--disable-static|--a\\nb|' 'CONFIGURE entry 1 must be a non-empty string of printable ASCII'
bad "a configure argument with a tab" 's|--disable-static|--a\\tb|' 'CONFIGURE entry 1 must be'
bad "an empty configure argument" 's|"--disable-static"|""|' 'CONFIGURE entry 1 must be'
bad "an uppercase trait" 's/NAME = "ldap"/NAME = "LDAP"/' 'TRAITS entry 2: NAME must be 1-32 of a-z, 0-9 and _]'
bad "a trait name with a dash" 's/NAME = "ldap"/NAME = "no-ldap"/' 'TRAITS entry 2: NAME must be'
bad "a trait declared twice" 's/NAME = "ldap"/NAME = "ssl"/' 'TRAITS declares ssl twice]'
bad "a trait without DEFAULT" 's/ DEFAULT = false;//' 'TRAITS entry 2: DEFAULT must be true or false]'
bad "a DEFAULT that is not a boolean" 's/DEFAULT = false/DEFAULT = 0/' 'TRAITS entry 2: DEFAULT must be true or false]'
bad "an unknown member in a trait" 's/DEFAULT = false;/DEFAULT = false; USE = true;/' 'TRAITS entry 2 may only have NAME, DEFAULT, ON and OFF]'
bad "an IF naming no trait" 's/IF = "ssl"/IF = "tls"/' 'DEPS entry 2: IF "tls" names no trait in TRAITS]'
bad "an IF naming no trait, negated" 's/IF = "-ldap"/IF = "-tls"/' 'BUILD_DEPS entry 1: IF "-tls" names no trait'
bad "an IF that is not a string" 's/IF = "ssl"/IF = true/' 'DEPS entry 2: IF must be a string]'
bad "a dependency with an unsafe name" 's/"zlib"/"..\/zlib"/' 'DEPS entry 1: "../zlib" is not a valid package name]'
bad "a dependency without VER" 's/{ NAME = "zlib"; VER = "1.3.0"; }/{ NAME = "zlib"; }/' 'DEPS entry 1: VER is missing or not a string]'
bad "an unknown member in a dependency" 's/VER = "1.3.0"; }/VER = "1.3.0"; OPTIONAL = true; }/' 'DEPS entry 1 may only have NAME, VER and IF]'
# The included file is a valid part of a recipe, so only the @include
# refusal itself can stop it.
echo 'CONFS = ();' > $T/inc
bad "an @include line" "/^CONFS/d; 1i @include \"$T/inc\"" '@include is not allowed]'
bad "an indented @include line" "/^CONFS/d; 1i \\ @include \"$T/inc\"" '@include is not allowed]'
bad "a misspelt hash prefix" "/curl.se/s/$SHA/sha256i:$(printf '%064d' 0 | tr 0 a)/" 'SOURCES entry 1: SHA256 must be "sha256:" followed by 64 lowercase hex digits]'
bad "a libconfig syntax error" 's/^VER = "8.9.0";/VER = = "8.9.0";/' 'line 2: syntax error]'
bad "a missing REPO" '/^REPO/d' 'REPO is missing]'
bad "a non-string COPYRIGHT" 's/^COPYRIGHT = .*/COPYRIGHT = 1;/' 'COPYRIGHT must be non-empty text'
bad "PATCHES as a string" 's/^PATCHES = .*/PATCHES = "01-a.patch";/' 'PATCHES must be a list of strings]'
bad "an ON that is not a list" 's/ON = \[ "--with-openssl" \]/ON = "--with-openssl"/' 'TRAITS entry 1: ON must be a list of strings]'
bad "an empty OFF argument" 's/OFF = \[ "--without-ssl" \]/OFF = [ "" ]/' 'TRAITS entry 1: OFF entry 1 must be a non-empty string'
bad "DEPS as a string" 's/^DEPS = .*/DEPS = "zlib";/' 'DEPS must be a list of { NAME; VER; } groups]'
# Untrusted text quoted in the reason is printable ASCII only.
bad "an escape sequence in a dependency name" 's/"zlib"/"\\x1b[31mz"/' 'DEPS entry 1: "?[31mz" is not a valid package name]'
bad "SOURCES as a string" '/^SOURCES/,/^);/c SOURCES = "https://a/b.tar.gz";' 'SOURCES must be a non-empty list'
{
sed '/^TRAITS/,/^);/d; /IF =/d; s/, { NAME = "libressl"; VER = "3.9.0"; IF = "ssl"; }//' $T/good | grep -v BUILD_DEPS
printf 'TRAITS = ('
i=0; sep=""
while [ $i -lt 33 ]; do printf '%s { NAME = "t%d"; DEFAULT = false; }' "$sep" $i; sep=","; i=$((i+1)); done
printf ' );\n'
} > $T/many
probe parse $T/many
check "refused: 33 traits" has "status=3"
check "...because: more than 32" has "why=[TRAITS has more than 32 traits]"
sed 's/ t32.*DEFAULT = false; }/ );/; s/, { NAME = "t32"; DEFAULT = false; }//' $T/many > $T/32
probe parse $T/32
check "32 traits parse" has "status=0"
printf 'NAME = "a\0b";\n' > $T/nul
probe parse $T/nul
check "refused: a NUL byte" has "status=3"
check "...because: a NUL byte" has "why=[the recipe contains a NUL byte]"
head -c $((1024*1024+1)) /dev/zero | tr '\0' ' ' > $T/huge
cat $T/minimal >> $T/huge
probe parse $T/huge
check "refused: more than 1 MiB" has "status=3"
check "...because: too large" has "why=[the recipe is larger than 1048576 bytes]"
probe parse $T/good $T/huge
check "a success after a failure leaves no reason" has "why=[]"
hr "gl_recipe_read"
# mkb DIR -> bundle at $T/b.grcp, made from a tree in $T/tree/DIR
mkb() { (cd $T/tree && tar czf $T/b.grcp "$@"); }
fresh() {
rm -rf $T/tree && mkdir -p $T/tree/curl-8.9.0/patches
cp $T/good $T/tree/curl-8.9.0/recipe
echo a > $T/tree/curl-8.9.0/patches/01-a.patch
echo b > $T/tree/curl-8.9.0/patches/02-b.patch
}
fresh; mkb curl-8.9.0
probe read $T/b.grcp
check "a good bundle reads" has "status=0"
check "...with no reason" has "why=[]"
check "...with its recipe" has "name=[curl]"
fresh; (cd $T/tree && tar czf $T/b.grcp curl-8.9.0/recipe curl-8.9.0/patches/01-a.patch curl-8.9.0/patches/02-b.patch)
probe read $T/b.grcp
check "no directory entries: still reads" has "status=0"
fresh; printf 'configure() { :; }\n' > $T/tree/curl-8.9.0/build; mkb curl-8.9.0
probe read $T/b.grcp
check "a build file is allowed" has "status=0"
fresh; sed -i 's/^BUILD = .*/BUILD = "hooks";/' $T/tree/curl-8.9.0/recipe; mkb curl-8.9.0
probe read $T/b.grcp
check "refused: BUILD = hooks without a build file" has "status=2"
check "...because: no build file" has 'why=[BUILD = "hooks" needs a build file]'
printf 'compile() { :; }\n' > $T/tree/curl-8.9.0/build; mkb curl-8.9.0
probe read $T/b.grcp
check "BUILD = hooks with a build file reads" has "status=0"
# badb DESCRIPTION WHY [STATUS]
badb() {
probe read $T/b.grcp
check "refused: $1" has "status=${3:-2}"
check "...because: $2" has "why=[$2"
}
fresh; rm $T/tree/curl-8.9.0/patches/02-b.patch; ln -s /etc/shadow $T/tree/curl-8.9.0/patches/02-b.patch; mkb curl-8.9.0
badb "a symlink (as a listed patch)" 'curl-8.9.0/patches/02-b.patch is not a regular file or directory]'
fresh; ln $T/tree/curl-8.9.0/patches/01-a.patch $T/tree/curl-8.9.0/build; mkb curl-8.9.0
badb "a hardlink" 'curl-8.9.0/build is not a regular file or directory]'
fresh; echo x > $T/tree/curl-8.9.0/README; mkb curl-8.9.0
badb "an extra file at the top" 'curl-8.9.0/README is not allowed (only recipe, build and patches/FILE)]'
fresh; mkdir $T/tree/curl-8.9.0/files; mkb curl-8.9.0
badb "an extra directory" 'curl-8.9.0/files/ is not allowed'
fresh; mkdir $T/tree/curl-8.9.0/patches/sub; mkb curl-8.9.0
badb "a directory inside patches/" 'curl-8.9.0/patches/sub/ is not allowed'
fresh; echo c > $T/tree/curl-8.9.0/patches/03-c.patch; mkb curl-8.9.0
badb "a patch PATCHES does not list" 'patches/03-c.patch is not in PATCHES]'
fresh; rm $T/tree/curl-8.9.0/patches/02-b.patch; mkb curl-8.9.0
badb "a listed patch missing" 'PATCHES lists 02-b.patch, but there is no patches/02-b.patch]'
fresh; rm $T/tree/curl-8.9.0/recipe; mkb curl-8.9.0
badb "no recipe" 'it has no recipe]'
fresh; mv $T/tree/curl-8.9.0 $T/tree/curl-9.0.0; mkb curl-9.0.0
badb "a top directory that is not NAME-VER" 'its top directory is curl-9.0.0, but the recipe says curl-8.9.0]'
fresh; mkdir -p $T/tree/other; echo x > $T/tree/other/recipe; mkb curl-8.9.0 other
badb "two top directories" 'it has two top directories'
fresh; (cd $T/tree && tar czf $T/b.grcp curl-8.9.0 --transform 's|^curl-8.9.0/patches/02-b.patch|curl-8.9.0/../02-b.patch|')
badb "a .. entry" 'curl-8.9.0/../02-b.patch is not allowed'
fresh; (cd $T/tree && tar czf $T/b.grcp -P curl-8.9.0 --transform 's|^curl-8.9.0/patches/02-b.patch|/tmp/02-b.patch|')
badb "an absolute entry" '/tmp/02-b.patch is not under a NAME-VER directory]'
fresh; (cd $T/tree && tar czf $T/b.grcp curl-8.9.0 curl-8.9.0/patches/01-a.patch)
# tar stores the second copy as a hardlink to the first
badb "an entry twice" 'curl-8.9.0/patches/01-a.patch is not a regular file or directory]'
fresh; mkfifo $T/tree/curl-8.9.0/build; mkb curl-8.9.0
badb "a fifo" 'curl-8.9.0/build is not a regular file or directory]'
fresh; head -c $((16*1024*1024)) /dev/zero > $T/tree/curl-8.9.0/patches/02-b.patch; mkb curl-8.9.0
badb "more than 16 MiB in all" 'its files add up to more than 16777216 bytes]'
echo junk > $T/b.grcp
badb "junk" 'not a gzip tar' 1
fresh; sed -i 's/^REPO = .*/REPO = "extra"; COLOR = "red";/' $T/tree/curl-8.9.0/recipe; mkb curl-8.9.0
badb "a malformed recipe" 'unknown setting COLOR]' 3
hr "-src indexes"
cat > $T/src.idx <<EOF
REPO = "extra-src"; SERIAL = 1L; VALID_UNTIL = 4000000000L;
PKGS = (
{ NAME = "curl"; VER = "8.9.0"; FILE = "curl-8.9.0.grcp"; SHA256 = "$SHA"; SIZE = 10L;
DEPS = ( { NAME = "zlib"; VER = "1.3.0"; }, { NAME = "libressl"; VER = "3.9.0"; IF = "ssl"; } );
CONFS = ();
BUILD_DEPS = ( { NAME = "perl"; VER = "5.40.0"; IF = "-ldap"; } );
TRAITS = ( { NAME = "ssl"; DEFAULT = true; }, { NAME = "ldap"; DEFAULT = false; } ); }
);
EOF
probe index extra-src $T/src.idx
check "a -src index parses" has "status=0"
check "...deps with IF" sh -c 'echo "$0" | tr "\n" "|" | grep -qF "deps=[zlib 1.3.0|libressl 3.9.0 ssl|]"' "$OUT"
check "...build deps" has "build_deps=[perl 5.40.0 -ldap"
check "...traits" sh -c 'echo "$0" | tr "\n" "|" | grep -qF "traits=[ssl 1|ldap 0|]"' "$OUT"
badi() {
sed "$3" $T/src.idx > $T/bad.idx
probe index $2 $T/bad.idx
check "refused: $1" has "status=1"
}
badi "no BUILD_DEPS" extra-src 's/BUILD_DEPS = .*//'
badi "no TRAITS" extra-src 's/TRAITS = .*/}/'
badi "a .gpkg FILE" extra-src 's/curl-8.9.0.grcp/curl-8.9.0.gpkg/'
badi "an IF naming no trait" extra-src 's/IF = "ssl"/IF = "tls"/'
badi "ON in an index trait" extra-src 's/DEFAULT = true;/DEFAULT = true; ON = [ "x" ];/'
badi "REPO = -src alone" -src 's/"extra-src"/"-src"/'
# The same entry in a binary index: every recipe field is malformed.
sed 's/extra-src/extra/; s/grcp/gpkg/; s/, { NAME = "libressl"; VER = "3.9.0"; IF = "ssl"; }//; s/ IF = "-ldap";//' $T/src.idx > $T/bin.idx
probe index extra $T/bin.idx
check "refused: BUILD_DEPS and TRAITS in a binary index" has "status=1"
sed -i 's/BUILD_DEPS = .*//; s/TRAITS = .*/}/' $T/bin.idx
cp $T/bin.idx $T/good-bin.idx
sed -i 's/{ NAME = "zlib"; VER = "1.3.0"; }/{ NAME = "zlib"; VER = "1.3.0"; IF = "ssl"; }/' $T/bin.idx
probe index extra $T/bin.idx
check "refused: IF in a binary index" has "status=1"
probe index extra $T/good-bin.idx
check "...without them, it is a good binary index" has "status=0"
check "...whose build deps and traits are empty" sh -c 'echo "$0" | grep -q "^build_deps=\[\]" && echo "$0" | grep -q "^traits=\[\]"' "$OUT"
hr "PKG_TRAITS"
mkman() {
rm -rf $T/m && mkdir -p $T/m/hi-1.0.0/files
printf 'PKG_NAME = "hi"; PKG_VER = "1.0.0"; PKG_REPO = "extra";\nPKG_DEPS = (); PKG_CONFS = ();\n%s\n' "$1" > $T/m/hi-1.0.0/manifest.gpm.cfg
tar czf $T/m.gpkg -C $T/m hi-1.0.0
}
mkman 'PKG_TRAITS = [ "ssl", "-ldap" ];'
probe manifest $T/m.gpkg
check "PKG_TRAITS is read" sh -c 'echo "$0" | tr "\n" "|" | grep -qF "traits=[ssl|-ldap|]"' "$OUT"
mkman ''
probe manifest $T/m.gpkg
check "...and absent, NULL" has "traits=NULL"
mkman 'PKG_TRAITS = [ ];'
probe manifest $T/m.gpkg
check "...an empty list, empty" has "traits=[]"
for v in '[ "ssl", "-ssl" ]' '[ "SSL" ]' '[ "--ssl" ]' '[ "" ]' '"ssl"' '[ 1 ]'; do
mkman "PKG_TRAITS = $v;"
probe manifest $T/m.gpkg
check "refused: PKG_TRAITS = $v" has "status=2"
done
hr "grepo -r X-src"
K=/etc/glacier/keys
D=/srv/extra-src
mkdir -p $D && chmod 755 /srv $D
gsign -G -p $K/srckey.pub -s /root/srckey.sec -c srckey >/dev/null
fresh; (cd $T/tree && tar czf $D/curl-8.9.0.grcp curl-8.9.0)
rm -rf $T/tree/hi-1.0.0 && mkdir -p $T/tree/hi-1.0.0 && cp $T/minimal $T/tree/hi-1.0.0/recipe
(cd $T/tree && tar czf $D/hi-1.0.0.grcp hi-1.0.0)
cp /dev/null $D/ignored.gpkg
R grepo -s /root/srckey.sec -r extra-src $D
check "grepo indexes a -src repository" rc 0
check "...both bundles" has "2 packages"
probe index extra-src $D/repo.idx
check "...an index gl_index_parse accepts" has "status=0"
check "...with the recipe's relations and traits" sh -c 'echo "$0" | tr "\n" "|" | grep -qF "deps=[zlib 1.3.0|libressl 3.9.0 ssl|]|confs=[curl-old 0.0.0|]|build_deps=[perl 5.40.0 -ldap|]|traits=[ssl 1|ldap 0|]"' "$OUT"
check "...each bundle's hash" grep -qF "SHA256 = \"sha256:$(sha256sum $D/hi-1.0.0.grcp | cut -c1-64)\"" $D/repo.idx
mv $D/hi-1.0.0.grcp $D/hi-2.0.0.grcp
R grepo -s /root/srckey.sec -r extra-src $D
check "refused: a misnamed bundle" has "[x] $D/hi-2.0.0.grcp must be named hi-1.0.0.grcp, as its recipe says."
rm $D/hi-2.0.0.grcp
sed 's/REPO = "extra"/REPO = "community"/' $T/minimal > $T/tree/hi-1.0.0/recipe
(cd $T/tree && tar czf $D/hi-1.0.0.grcp hi-1.0.0)
R grepo -s /root/srckey.sec -r extra-src $D
check "refused: a recipe of another repository" has "[x] $D/hi-1.0.0.grcp builds community packages, not extra."
echo junk > $D/hi-1.0.0.grcp
R grepo -s /root/srckey.sec -r extra-src $D
check "refused: a bundle that can't be read" has "[x] $D/hi-1.0.0.grcp is not a readable recipe bundle: not a gzip tar"
sed 's/SHA256 = "sha256:/SHA256 = "sha256i:/' $T/minimal > $T/tree/hi-1.0.0/recipe
(cd $T/tree && tar czf $D/hi-1.0.0.grcp hi-1.0.0)
R grepo -s /root/srckey.sec -r extra-src $D
check "refused: a malformed recipe, saying why" has '[x] '"$D"'/hi-1.0.0.grcp is a bundle with a malformed recipe: SOURCES entry 1: SHA256 must be "sha256:" followed by 64 lowercase hex digits.'
cp $T/minimal $T/tree/hi-1.0.0/recipe; echo x > $T/tree/hi-1.0.0/notes
(cd $T/tree && tar czf $D/hi-1.0.0.grcp hi-1.0.0)
R grepo -s /root/srckey.sec -r extra-src $D
check "refused: an invalid bundle, saying why" has "[x] $D/hi-1.0.0.grcp is not a valid recipe bundle: hi-1.0.0/notes is not allowed (only recipe, build and patches/FILE)."
rm -rf $D/hi-1.0.0.grcp $T/tree/hi-1.0.0/notes
R grepo -s /root/srckey.sec -r extra-src $D
hr "syspkg -y with a -src repository"
syspkg -n >/dev/null
printf 'repos = (\n\t{ name = "extra-src"; url = "file:///srv/extra-src"; keys = [ "srckey" ]; }\n);\n' > /etc/glacier/repos.conf
chmod 644 /etc/glacier/repos.conf
R syspkg -y
check "syspkg -y accepts a -src index" rc 0
check "...and stores it" cmp $D/repo.idx /glacier/sys/repos/extra-src.idx
echo
if [ $FAILS -eq 0 ]; then echo "ALL PASSED"; else echo "$FAILS FAILED"; fi
[ $FAILS -eq 0 ]