Files
makronix/tools/test-tools.sh
T
lotherk 974603f8a6 pkgsrc: the forks of ext/ build from their tree, not from an archive
Each fork kept a recipe beside its source and a tarball in distfiles/ whose
distinfo had to be regenerated after every commit (tools/ext-dist.sh,
tools/mcde-dist.sh), and the work directory of a build could not see a later
commit at all (tools/ext-resync.sh merged an archive into it).  Three tools,
one artefact per fork in git, and the failure mode that cost the 2026-11-23
release: mcde 288d1383 built from the commit of the day before, because the
recipe's mtime said "not stale".

Now the recipe builds the source tree itself, which is how pkgsrc's own
net/fetch and pkgtools/pkg_install do it: DISTFILES= # empty, do-extract
fills WRKSRC.  What is gone with that:

  - the tarballs (distfiles/{mcde,splinter,junction,wikid,skilld,memoryd,
    tasksd}-*) and their .key
  - tools/ext-dist.sh, tools/mcde-dist.sh, tools/ext-resync.sh and its test
  - fork_archives in tools/makronix-distfiles.sh (nothing to fetch or stage)
  - the distinfo files of the eight recipes

What replaces it: tools/ext-extract.sh, called from do-extract.  It hashes
the tree, copies only the files that differ, keeps the time stamp of the rest
(so a commit rebuilds what it touched and not 27 minutes of MCDE) and
removes the copy when a file left the tree.  The build key of a fork carries
the source commit for the same reason: a commit does not change the recipe.

The recipes keep $Makronix$ as their header; afpfs-ng keeps its upstream
$NetBSD: ...$ line and its real distfile, and fork_src() leaves it alone.

Verified:
  - bmake package built all eight recipes from the tree with no distinfo:
    splinter, junction, wikid, skilld, memoryd, tasksd, mcde (16 MB), and
    mcde-motif's shared tree
  - tools/test-tools.sh: 38 ok, 0 bad (5 new cases for ext-extract.sh)
  - tools/makronix-distfiles.sh check: 0 missing, 0 wrong hash
  - tools/makronix-pins.sh check: PINS matches
2026-11-23 19:49:07 +00:00

386 lines
14 KiB
Bash
Executable File

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# test-tools.sh -- tests for the build tools (t0232)
#
# usage: test-tools.sh
#
# Tests pkglist.sh, tools/makronix-set.sh, tools/keep-images.sh and mxupgrade
# with artificial inputs in a scratch directory. No network, no build.
# Exit 0 when all cases pass. Output: result: N ok, M bad
set -eu
R=$(cd "$(dirname "$0")/.." && pwd)
TMP=$(mktemp -d "${TMPDIR:-/tmp}/test-tools.XXXXXX")
trap 'rm -rf "$TMP"' EXIT
ok=0
fail=0
pass() { printf 'ok %s\n' "$1"; ok=$((ok + 1)); }
bad() { printf 'BAD %s: %s\n' "$1" "$2" >&2; fail=$((fail + 1)); }
# --- pkglist.sh -----------------------------------------------------------
# Uses a test packages.list via PACKAGES_LIST. Covers set/repo/fetch/bin/
# sysroot/games/built/all, -n, @ARCH, unknown kind (error).
cat > "$TMP/packages.list" <<'EOF'
# comment
wm/mcde
devel/git-base bin
editors/vim bin
shells/ksh93 bin
multimedia/xine-ui fetch
games/freeciv games
misc/something repo
archivers/p7zip fetch @aarch64
EOF
plist_set=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" set)
plist_repo=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" repo)
plist_fetch=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" fetch)
plist_bin=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" bin)
plist_sysroot=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" sysroot)
plist_games=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" games)
plist_built=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" built)
plist_all=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" all)
plist_set_n=$(PACKAGES_LIST="$TMP/packages.list" sh "$R/tools/pkglist.sh" set -n)
expect_eq() {
name=$1; got=$2; want=$3
if [ "$got" = "$want" ]; then pass "$name"; else bad "$name" "got [$got] want [$want]"; fi
}
expect_has() {
name=$1; got=$2; needle=$3
case "$got" in *"$needle"*) pass "$name" ;; *) bad "$name" "[$got] missing [$needle]" ;; esac
}
expect_not() {
name=$1; got=$2; needle=$3
case "$got" in *"$needle"*) bad "$name" "[$got] unexpectedly has [$needle]" ;; *) pass "$name" ;; esac
}
expect_eq "pkglist set" "$plist_set" "wm/mcde"
expect_eq "pkglist set -n" "$plist_set_n" "mcde"
expect_eq "pkglist repo" "$plist_repo" "misc/something"
expect_eq "pkglist games" "$plist_games" "games/freeciv"
expect_has "pkglist fetch has xine-ui" "$plist_fetch" "multimedia/xine-ui"
expect_has "pkglist fetch has bin" "$plist_fetch" "devel/git-base"
expect_not "pkglist fetch no games" "$plist_fetch" "games/freeciv"
expect_has "pkglist bin has vim" "$plist_bin" "editors/vim"
expect_not "pkglist bin no fetch-only" "$plist_bin" "multimedia/xine-ui"
expect_eq "pkglist sysroot==bin" "$plist_sysroot" "$plist_bin"
expect_has "pkglist built has set" "$plist_built" "wm/mcde"
expect_has "pkglist built has repo" "$plist_built" "misc/something"
expect_not "pkglist built no fetch" "$plist_built" "multimedia/xine-ui"
expect_not "pkglist built no games" "$plist_built" "games/freeciv"
expect_has "pkglist all has repo" "$plist_all" "misc/something"
expect_has "pkglist all has games" "$plist_all" "games/freeciv"
expect_not "pkglist all no aarch64-only on amd64" "$plist_all" "archivers/p7zip"
plist_aarch=$(PACKAGES_LIST="$TMP/packages.list" ARCH=aarch64 sh "$R/tools/pkglist.sh" all)
expect_has "pkglist @aarch64 selected" "$plist_aarch" "archivers/p7zip"
# unknown kind must fail
set +e
printf 'misc/bad\tbogus\n' > "$TMP/bad.list"
PACKAGES_LIST="$TMP/bad.list" sh "$R/tools/pkglist.sh" all >/dev/null 2>&1
rc=$?
set -e
if [ "$rc" -ne 0 ]; then pass "pkglist unknown kind fails"; else bad "pkglist unknown kind fails" "rc=$rc"; fi
# --- keep-images.sh -------------------------------------------------------
# Fake release images dir and SHA512. keep-images copies and verifies.
KD="$TMP/keepenv"
mkdir -p "$KD/build/obj/releasedir/images" "$KD/tools"
cp "$R/tools/keep-images.sh" "$KD/tools/keep-images.sh"
printf 'disk' > "$KD/build/obj/releasedir/images/Makronix-0.99.10-amd64.iso"
printf 'img' > "$KD/build/obj/releasedir/images/Makronix-0.99.10-amd64.img"
(
cd "$KD/build/obj/releasedir/images"
for f in *.iso *.img; do
printf 'SHA512 (%s) = %s\n' "$f" "$(sha512sum "$f" | awk '{print $1}')"
done > SHA512
)
# keep-images computes TOP from dirname/.. of itself -> KD
if sh "$KD/tools/keep-images.sh" test1 >"$TMP/keep1.out" 2>&1; then
if [ -f "$KD/build/keep-test1/Makronix-0.99.10-amd64.iso" ] && \
grep -q 'ok' "$TMP/keep1.out"; then
pass "keep-images copies and verifies"
else
bad "keep-images copies and verifies" "missing copy or ok"
fi
else
bad "keep-images copies and verifies" "exit $?"
fi
# wrong SHA512 must fail
KD2="$TMP/keepenv2"
mkdir -p "$KD2/build/obj/releasedir/images" "$KD2/tools"
cp "$R/tools/keep-images.sh" "$KD2/tools/keep-images.sh"
printf 'disk' > "$KD2/build/obj/releasedir/images/x.iso"
printf 'SHA512 (x.iso) = 0000\n' > "$KD2/build/obj/releasedir/images/SHA512"
set +e
sh "$KD2/tools/keep-images.sh" bad >"$TMP/keep2.out" 2>&1
rc=$?
set -e
if [ "$rc" -ne 0 ]; then pass "keep-images bad checksum fails"; else bad "keep-images bad checksum fails" "rc=$rc"; fi
# --- mxupgrade -n ---------------------------------------------------------
# Artificial release directory with empty sets and a kernel carrying a version
# string. With -n it must report and change nothing (no sysupgrade, no root).
MR="$TMP/release/amd64"
mkdir -p "$MR/binary/sets" "$MR/binary/kernel" "$MR/installation/miniroot"
: > "$MR/binary/sets/base.tgz"
: > "$MR/binary/sets/etc.tgz"
# create a tiny gz whose uncompressed content contains the version string
printf 'Makronix 0.99.11 kernel\n' | gzip -c > "$MR/binary/kernel/netbsd-GENERIC.gz"
# file:// URL and plain path; -n exits 0 and prints info
set +e
MXUPGRADE_CONF=/nonexistent sh "$R/src/usr.sbin/mxupgrade/mxupgrade.sh" -n "$MR" >"$TMP/mx1.out" 2>&1
rc1=$?
MXUPGRADE_CONF=/nonexistent sh "$R/src/usr.sbin/mxupgrade/mxupgrade.sh" -n "file://$MR" >"$TMP/mx2.out" 2>&1
rc2=$?
MXUPGRADE_CONF=/nonexistent sh "$R/src/usr.sbin/mxupgrade/mxupgrade.sh" -n /no/such/release >"$TMP/mx3.out" 2>&1
rc3=$?
set -e
if [ "$rc1" -eq 0 ] && grep -q '0.99.11' "$TMP/mx1.out" && grep -q 'nothing was changed' "$TMP/mx1.out"; then
pass "mxupgrade -n reports release dir"
else
bad "mxupgrade -n reports release dir" "rc=$rc1"
fi
if [ "$rc2" -eq 0 ] && grep -q 'nothing was changed' "$TMP/mx2.out"; then
pass "mxupgrade -n accepts file://"
else
bad "mxupgrade -n accepts file://" "rc=$rc2"
fi
if [ "$rc3" -ne 0 ]; then
pass "mxupgrade rejects missing release dir"
else
bad "mxupgrade rejects missing release dir" "rc=$rc3"
fi
# --- makronix-set.sh ------------------------------------------------------
# Build a minimal fake TOP so makronix-set.sh (which derives TOP from its own
# location) can run against artificial pkgdb/DESTDIR/METALOG without touching
# the real tree. Covers: relative @cwd (build/obj/destdir.../usr/pkg),
# @ignore followed by +COMMENT, @pkgdir, a file name with a space (skipped with
# a warning, not fatal), and a directory that must appear in METALOG.
MS="$TMP/mset"
mkdir -p "$MS/tools" "$MS/src/distrib/sets/lists/makronix" "$MS/build/pkg/sbin" "$MS/build/logs"
cp "$R/tools/makronix-set.sh" "$MS/tools/makronix-set.sh"
cp "$R/tools/pkglist.sh" "$MS/tools/pkglist.sh"
DD="$MS/build/obj/destdir.test"
mkdir -p "$DD/usr/pkg/bin" "$DD/usr/pkg/lib" "$DD/usr/pkg/share/doc/pkgA" "$DD/usr/pkg/etc/dt/cde/fontaliases"
printf '#!/bin/sh\nexit 0\n' > "$DD/usr/pkg/bin/progA"
chmod 755 "$DD/usr/pkg/bin/progA"
printf 'lib\n' > "$DD/usr/pkg/lib/libA.so.1"
printf 'hi\n' > "$DD/usr/pkg/share/doc/pkgA/readme.txt"
# file name with a space (setuptools template case): must be warned and skipped
printf 'x\n' > "$DD/usr/pkg/share/doc/pkgA/lorem ipsum.txt"
touch "$DD/METALOG"
# pkgdb: pkgA is the "set" package, pkgB a runtime dep
mkdir -p "$DD/usr/pkg/pkgdb/pkgA-1.0" "$DD/usr/pkg/pkgdb/pkgB-2.0"
cat > "$DD/usr/pkg/pkgdb/pkgA-1.0/+BUILD_INFO" <<'EOF'
PKGNAME=pkgA-1.0
PKGPATH=cat/pkgA
EOF
cat > "$DD/usr/pkg/pkgdb/pkgA-1.0/+CONTENTS" <<'EOF'
@name pkgA-1.0
@cwd build/obj/destdir.test/usr/pkg
@pkgdir etc/dt/cde/fontaliases
@ignore
+COMMENT
bin/progA
@comment MD5:000
@pkgdep pkgB>=1
lib/libA.so.1
share/doc/pkgA/readme.txt
share/doc/pkgA/lorem ipsum.txt
EOF
cat > "$DD/usr/pkg/pkgdb/pkgB-2.0/+BUILD_INFO" <<'EOF'
PKGNAME=pkgB-2.0
PKGPATH=cat/pkgB
EOF
cat > "$DD/usr/pkg/pkgdb/pkgB-2.0/+CONTENTS" <<'EOF'
@name pkgB-2.0
@cwd /usr/pkg
EOF
# packages.list with the set seed
cat > "$MS/packages.list" <<'EOF'
cat/pkgA
EOF
# fake pkg_info: -E <pattern> -> echo matching installed package name
cat > "$MS/build/pkg/sbin/pkg_info" <<'SH'
#!/bin/sh
DB=
while [ $# -gt 0 ]; do
case $1 in
-K) DB=$2; shift 2 ;;
-E) pat=$2; shift 2 ;;
*) shift ;;
esac
done
for d in "$DB"/*/; do
[ -d "$d" ] || continue
n=${d%/}; n=${n##*/}
base=$(printf '%s\n' "$n" | sed 's/-[^-]*$//')
case "$n" in "$pat"|"${pat}-"*|"$pat".*)
printf '%s\n' "$n"; exit 0 ;;
esac
case "$base" in "$pat") printf '%s\n' "$n"; exit 0 ;; esac
done
exit 1
SH
chmod 755 "$MS/build/pkg/sbin/pkg_info"
# fake pkg_delete (not expected to be needed here, but present)
cat > "$MS/build/pkg/sbin/pkg_delete" <<'SH'
#!/bin/sh
exit 0
SH
chmod 755 "$MS/build/pkg/sbin/pkg_delete"
set +e
sh "$MS/tools/makronix-set.sh" "$DD" >"$TMP/mset.out" 2>&1
mrc=$?
set -e
MLIST="$MS/src/distrib/sets/lists/makronix/mi"
if [ "$mrc" -eq 0 ] && [ -f "$MLIST" ]; then
pass "makronix-set runs on crafted pkgdb"
else
bad "makronix-set runs on crafted pkgdb" "rc=$mrc"
fi
# relative @cwd resolved: file recorded as usr/pkg/bin/progA
if grep -q '^\./usr/pkg/bin/progA' "$MLIST" 2>/dev/null; then
pass "makronix-set relative @cwd"
else
bad "makronix-set relative @cwd" "progA missing from list"
fi
# @ignore consumed +COMMENT (no +COMMENT as a file)
if grep -q '+COMMENT' "$MLIST" 2>/dev/null; then
bad "makronix-set @ignore skips +COMMENT" "+COMMENT present"
else
pass "makronix-set @ignore skips +COMMENT"
fi
# @pkgdir recorded
if grep -q 'fontaliases' "$MLIST" 2>/dev/null; then
pass "makronix-set @pkgdir recorded"
else
bad "makronix-set @pkgdir recorded" "fontaliases missing"
fi
# space in name warned+skipped, not fatal (already rc==0 above)
if grep -q 'lorem ipsum' "$MLIST" 2>/dev/null; then
bad "makronix-set skips space-in-name" "name with space present"
elif grep -q 'space' "$TMP/mset.out" 2>/dev/null; then
pass "makronix-set skips space-in-name"
else
bad "makronix-set skips space-in-name" "no warning found"
fi
# directories present in METALOG (nbmtree missing directory in specification case)
if grep -q '^\./usr/pkg/bin type=dir' "$DD/METALOG" 2>/dev/null; then
pass "makronix-set METALOG has directories"
else
bad "makronix-set METALOG has directories" "usr/pkg/bin dir record missing"
fi
# intentionally broken case: relative @cwd handling removed -> progA missing/fail
BROKEN="$TMP/mset-broken"
cp -R "$MS" "$BROKEN"
# remove the relative @cwd normalization line
sed '/\*\/usr\/pkg) cwd=\/usr\/pkg ;; esac/d' "$MS/tools/makronix-set.sh" > "$BROKEN/tools/makronix-set.sh"
rm -f "$BROKEN/src/distrib/sets/lists/makronix/mi"
: > "$BROKEN/build/obj/destdir.test/METALOG"
set +e
sh "$BROKEN/tools/makronix-set.sh" "$BROKEN/build/obj/destdir.test" >"$TMP/mset.broken.out" 2>&1
brc=$?
set -e
if [ "$brc" -ne 0 ] || ! grep -q '^\./usr/pkg/bin/progA' "$BROKEN/src/distrib/sets/lists/makronix/mi" 2>/dev/null; then
pass "makronix-set broken relative-@cwd falls red"
else
bad "makronix-set broken relative-@cwd falls red" "rc=$brc but progA still listed"
fi
# --- docs/guide -----------------------------------------------------------
# The guide's installed forms: green on the tree as it is, red when one of
# them is missing. check.sh reads only the installed copies; it does not
# need pandoc or Chrome.
G="$TMP/guideroot"
mkdir -p "$G/src/share/doc/makronix" "$G/src/share/man/man7" "$G/src/etc" "$G/www"
cp -R "$R/src/share/doc/makronix/." "$G/src/share/doc/makronix/"
cp "$R/src/share/man/man7"/makronix-guide*.7 "$G/src/share/man/man7/"
cp "$R/src/etc/makronix-xsession" "$R/src/etc/Makefile" "$G/src/etc/"
cp "$R/www/guide.html" "$R/www/style.css" "$G/www/"
cp -R "$R/www/img" "$G/www/"
if sh "$R/docs/guide/check.sh" "$G" >"$TMP/guide.ok" 2>&1; then
pass "guide check green"
else
bad "guide check green" "$(cat "$TMP/guide.ok")"
fi
rm -f "$G/src/share/man/man7/makronix-guide-mcde.7"
if sh "$R/docs/guide/check.sh" "$G" >"$TMP/guide.bad" 2>&1; then
bad "guide check broken man page falls red" "check still passed"
else
pass "guide check broken man page falls red"
fi
# --- ext-extract.sh -------------------------------------------------------
# The copy in a pkgsrc work directory is refreshed from the source tree. The
# point of the script is what a plain `cp -R' does not do: an unchanged file
# keeps its time stamp (or make rebuilds all of MCDE), a changed one gets a new
# one (or the build keeps an object file of the old source), and a file that
# left the tree removes the copy (or the build compiles a file that is not in
# the tree any more).
XS="$TMP/xsrc"; XW="$TMP/xwork"
mkdir -p "$XS/sub"
printf 'a\n' > "$XS/a.c"; printf 'b\n' > "$XS/sub/b.c"; printf 'c\n' > "$XS/c.h"
X="$R/tools/ext-extract.sh"
if sh "$X" "$XS" "$XW/w" >/dev/null 2>&1 && [ -f "$XW/w/a.c" ] && [ -f "$XW/w/sub/b.c" ]; then
pass "ext-extract fills a work directory"
else
bad "ext-extract fills a work directory" "no copy below $XW/w"
fi
touch -d '2020-01-01 00:00' "$XW/w/a.c" "$XW/w/sub/b.c"
printf 'a\n' > "$XS/a.c"
sh "$X" "$XS" "$XW/w" >/dev/null 2>&1
if [ "$(date -r "$XW/w/a.c" +%Y)" = 2020 ]; then
pass "ext-extract keeps the time stamp of an unchanged file"
else
bad "ext-extract keeps the time stamp of an unchanged file" "a.c is $(date -r "$XW/w/a.c")"
fi
printf 'a2\n' > "$XS/a.c"
sh "$X" "$XS" "$XW/w" >/dev/null 2>&1
if [ "$(date -r "$XW/w/a.c" +%Y)" != 2020 ] && [ "$(cat "$XW/w/a.c")" = a2 ] &&
[ "$(date -r "$XW/w/sub/b.c" +%Y)" = 2020 ]; then
pass "ext-extract copies a changed file and leaves the rest"
else
bad "ext-extract copies a changed file and leaves the rest" "a.c=$(cat "$XW/w/a.c") b.c=$(date -r "$XW/w/sub/b.c")"
fi
printf 'd\n' > "$XS/d.c"
sh "$X" "$XS" "$XW/w" >/dev/null 2>&1
if [ -f "$XW/w/d.c" ]; then
pass "ext-extract copies a new file"
else
bad "ext-extract copies a new file" "d.c is missing"
fi
rm "$XS/c.h"
sh "$X" "$XS" "$XW/w" >/dev/null 2>&1
if [ ! -f "$XW/w/c.h" ]; then
pass "ext-extract drops a copy a file left"
else
bad "ext-extract drops a copy a file left" "c.h is still there"
fi
printf 'result: %s ok, %s bad\n' "$ok" "$fail"
[ "$fail" -eq 0 ]