Files
makronix/tools/test-ext-resync.sh
T
lotherk b74473cb8e ext-resync: a file the work directory already has is no reason to clean
userland-2026-11-17f.log:11 'pkgsrc changed ./include/Dt/WsmP.h, cleaning':
the .pristine was older than the extract (the run before was started with
the userland.sh that kept no snapshot after a failure), so a header changed
since then looked like pkgsrc's, and MCDE was compiled from nothing for a
file the work directory already held as the new archive has it.  Such a
file is now skipped -- not cleaned and not copied, so its time stamp stays
and make does not recompile what includes it.

tools/test-ext-resync.sh (asked for by t0231, never written): six cases in
a scratch tree with a stand-in bmake; the committed ext-resync.sh fails
"stale pristine: no clean", this one passes 14 of 14.  test-tools.sh runs
it (34 ok, 0 bad).
2026-11-17 16:48:20 +00:00

113 lines
3.7 KiB
Bash
Executable File

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# test-ext-resync.sh -- tests for tools/ext-resync.sh (t0231, t0464)
#
# usage: tools/test-ext-resync.sh [EXT_RESYNC]
#
# Runs ext-resync.sh (default: the one next to this script) in a scratch tree
# with artificial archives and a stand-in bmake that answers show-var, so no
# pkgsrc, no build and no lock are touched. Cases: a changed file is copied
# and the build cookies go; an unchanged file keeps its time stamp; a work
# directory that already has the new file (a .pristine older than the
# extract) is no reason to clean; a file pkgsrc changed is; a removed file is
# removed; a configure.ac change drops the configure cookie.
# Exit 0 when all cases pass. Output: result: N ok, M bad
set -u
HERE=$(cd "$(dirname "$0")" && pwd)
RESYNC=${1:-$HERE/ext-resync.sh}
S=${TMPDIR:-/tmp}/test-ext-resync.$$
trap 'rm -rf "$S"' EXIT HUP INT TERM
ok=0 bad=0
check() { # NAME COMMAND...
n=$1; shift
if "$@"; then echo "ok $n"; ok=$((ok + 1))
else echo "BAD $n"; bad=$((bad + 1)); fi
}
P=cat/t
WD=$S/build/pkgsrc-work/$P
WRKSRC=$WD/work.T/t-1.0
DIST=$S/distfiles
setup() { # a work directory extracted from archive A, .pristine = A
rm -rf "$S"
mkdir -p "$S/tools" "$S/build/pkg/bin" "$S/pkgsrc/$P" "$DIST" "$S/a/t-1.0/src"
cp "$RESYNC" "$S/tools/ext-resync.sh"
cat > "$S/build/pkg/bin/bmake" <<EOF
#!/bin/sh
case \$2 in
VARNAME=WRKSRC) echo "$WRKSRC" ;;
VARNAME=DISTDIR) echo "$DIST" ;;
VARNAME=DISTFILES) echo t-1.0.tar.gz ;;
esac
EOF
chmod +x "$S/build/pkg/bin/bmake"
: > "$S/pkgsrc/$P/Makefile"
echo one > "$S/a/t-1.0/src/one.c"
echo two > "$S/a/t-1.0/src/two.c"
echo gone > "$S/a/t-1.0/src/gone.c"
echo 'AC_INIT' > "$S/a/t-1.0/configure.ac"
mkdir -p "$WD/.pristine" "$WD/work.T"
cp -R "$S/a/t-1.0" "$WD/.pristine/"
cp -R "$S/a/t-1.0" "$WD/work.T/"
touch "$WD/work.T/.build_done" "$WD/work.T/.install_done" \
"$WD/work.T/.package_done" "$WD/work.T/.configure_done"
touch -t 202601010000 "$WRKSRC/src/one.c" "$WRKSRC/src/two.c"
cp -R "$S/a" "$S/b"
}
pack() { # the new archive from $S/b
(cd "$S/b" && tar -czf "$DIST/t-1.0.tar.gz" t-1.0)
}
run() { (cd "$S" && sh tools/ext-resync.sh resync "$P") > "$S/out" 2>&1; }
older() { [ "$1" -ot "$S/build/pkg/bin/bmake" ]; }
# 1: one file changed, one removed
setup
echo ONE > "$S/b/t-1.0/src/one.c"
rm "$S/b/t-1.0/src/gone.c"
pack
check "changed: exit 0" run
check "changed: new content" grep -qx ONE "$WRKSRC/src/one.c"
check "unchanged: time stamp kept" older "$WRKSRC/src/two.c"
check "removed: gone" test ! -f "$WRKSRC/src/gone.c"
check "cookies: build/install/package gone" test ! -f "$WD/work.T/.build_done" -a ! -f "$WD/work.T/.install_done" -a ! -f "$WD/work.T/.package_done"
check "cookies: configure kept" test -f "$WD/work.T/.configure_done"
# 2: .pristine older than the extract: the work directory has the new file
setup
echo NEW > "$S/b/t-1.0/src/two.c"
cp "$S/b/t-1.0/src/two.c" "$WRKSRC/src/two.c"
touch -t 202601010000 "$WRKSRC/src/two.c"
echo ONE > "$S/b/t-1.0/src/one.c"
pack
check "stale pristine: no clean (exit 0)" run
check "stale pristine: file not copied again" older "$WRKSRC/src/two.c"
# 3: a file pkgsrc changed (SUBST) and the archive changed it too
setup
echo subst > "$WRKSRC/src/two.c"
echo TWO > "$S/b/t-1.0/src/two.c"
pack
run
check "pkgsrc changed: exit 1" test $? -eq 1
check "pkgsrc changed: says so" grep -q 'pkgsrc changed' "$S/out"
# 4: configure.ac changed
setup
echo 'AC_INIT([t])' > "$S/b/t-1.0/configure.ac"
pack
check "configure.ac: exit 0" run
check "configure.ac: configure cookie gone" test ! -f "$WD/work.T/.configure_done"
# 5: nothing changed
setup
pack
check "nothing: exit 0" run
check "nothing: says so" grep -q 'nothing changed' "$S/out"
echo "result: $ok ok, $bad bad"
[ "$bad" -eq 0 ]