Files
lotherkandClaude Sonnet 5.5 19a70fb37d build-stamp.sh: the kernel configuration key uses sha256_in (no sha256sum on NetBSD)
make release on the MacBook: 'tools/build-stamp.sh: sha256sum: not found'.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-23 08:39:09 +00:00

132 lines
5.3 KiB
Bash
Executable File

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
# build-stamp.sh -- incremental builds that cannot serve stale artefacts.
#
# The problem this solves, measured 2026-11-03: after a patch to sysinst,
# `build.sh -u release` left the INSTALL ramdisk and the install CD from an
# earlier run in place, because make decides by timestamps and the derived
# targets were newer than the files it looked at. The test then ran against a
# medium that did not contain the patch -- and the failure looked like a bug in
# the fix.
#
# So the derived artefacts get a CONTENT key instead: the tree of src/, the
# Makefile and the few scripts that decide what the sets hold (STAMPED below) in
# the commit, the names of modified/untracked files there, and the pkgsrc
# configuration. The other scripts of tools/ (tests, media, MCDE, logos) run
# after `release' or beside it and are not inputs of it: a change there must
# not throw a release away. If the
# key differs from the one recorded in build/obj/.makronix-stamp, the artefacts
# that are derived from the sources are removed and rebuilt. Everything else
# -- the object tree, the cross toolchain -- stays, which is where the time is.
set -u
TOP=$(cd "$(dirname "$0")/.." && pwd)
# This tool writes build/obj or releasedir: only inside the build lock.
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
echo "${0##*/}: run this through make or tools/build-lock.sh" >&2
exit 1
fi
OBJ=${OBJ:-$TOP/build/obj}
MACHINE=${MACHINE:-amd64}
STAMP=$OBJ/.makronix-stamp
# the scripts that decide what the sets hold (and this one); the rest of tools/
# is not an input of `release'
STAMPED="tools/build-stamp.sh tools/makronix-set.sh tools/pkgsrc-cross.mk.conf"
mkdir -p "$OBJ"
# sha256 of stdin, on Linux and on NetBSD (cksum(1) there; no sha256sum),
# as tools/makronix-distfiles.sh does it
sha256_in()
{
if command -v sha256sum > /dev/null 2>&1; then
sha256sum | cut -d' ' -f1
else
cksum -a sha256 | awk '{ print $NF }'
fi
}
key=$(
{
# content-based key: blob hashes from the index describe the source
# content, not the commit, so a commit that changes nothing keeps the
# same key (tasksd t0228). Uncommitted edits are caught by the diff
# below, and untracked files by listing their (sorted) contents.
git -C "$TOP" ls-files -s -- src xsrc Makefile $STAMPED 2>/dev/null
git -C "$TOP" diff -- src xsrc $STAMPED Makefile 2>/dev/null
git -C "$TOP" ls-files -o --exclude-standard -- src xsrc $STAMPED \
Makefile 2>/dev/null | sort | while read -r f; do
echo "$f"
cat "$TOP/$f" 2>/dev/null
done
cat "$TOP/tools/pkgsrc-cross.mk.conf" 2>/dev/null
} | sha256_in
)
# no key (no checksum tool, no git): never "unchanged" by accident
[ -n "$key" ] || { echo "build-stamp: cannot compute the key" >&2; exit 1; }
old=""
[ -f "$STAMP" ] && old=$(cat "$STAMP")
if [ "$key" = "$old" ]; then
exit 0
fi
# `-c' only checks. `make iso' packages what `make release' built; it must
# not be the step that throws a stale release away and then fails halfway
# ("netbsd-GENERIC.gz: stat: No such file or directory", measured 2026-11-06).
if [ "${1:-}" = "-c" ]; then
echo "build-stamp: sources changed since the last build." >&2
echo "build-stamp: run 'make release ARCH=...' first; 'make iso' only packages." >&2
exit 1
fi
# Only what is DERIVED from the sources. The object tree and the
# toolchain survive on purpose: rebuilding them is hours, and they are keyed by
# the same files make already tracks.
for d in \
"$OBJ"/releasedir/amd64 \
"$OBJ"/releasedir/images \
"$OBJ"/distrib/amd64/installimage \
"$OBJ"/distrib/amd64/installimage-bios \
"$OBJ"/distrib/amd64/cdroms \
"$OBJ"/distrib/amd64/instkernel \
"$OBJ"/distrib/amd64/ramdisks/ramdisk/ramdisk.fs \
"$OBJ"/distrib/amd64/ramdisks/ramdisk/work.spec \
"$OBJ"/distrib/amd64/ramdisks/ramdisk/work.built \
"$OBJ"/distrib/amd64/ramdisks/ramdisk-cgdroot/ramdisk-cgdroot.fs \
"$OBJ"/distrib/amd64/ramdisks/ramdisk-cgdroot/work.spec \
"$OBJ"/distrib/amd64/ramdisks/ramdisk-cgdroot/devices.spec \
"$OBJ"/distrib/amd64/ramdisks/ramdisk-cgdroot/work.built \
"$OBJ"/distrib/amd64/kmod-cgdroot/cgdroot.kmod \
"$OBJ"/distribution
do
[ -e "$d" ] && { echo "build-stamp: removing stale ${d#$OBJ/}"; rm -rf "$d"; }
done
# A kernel configuration change needs a full kernel build: config(1) writes a
# new Makefile and opt_*.h, but not every object depends on them, and an old
# one keeps the macros it was compiled with. Measured 2026-11-17: the new
# options went into the Makefile, rf_paritylogging.o stayed from 10:12 and
# the link failed on rf_ConfigureParityLogging. Keyed on the configuration
# alone: a source change still builds the kernel incrementally.
kck=$OBJ/.makronix-kernel-config-key
kckey=$( { cat "$TOP"/src/sys/conf/makronix_workstation.config
"$TOP"/src/sys/conf/makronix_devices.config 2>/dev/null
cat "$TOP"/src/sys/arch/"$MACHINE"/conf/GENERIC \
"$TOP"/src/sys/arch/"$MACHINE"/conf/INSTALL 2>/dev/null; } | sha256_in)
if [ "$(cat "$kck" 2>/dev/null)" != "$kckey" ]; then
for d in "$OBJ"/sys/arch/*/compile/*; do
[ -d "$d" ] || continue
echo "build-stamp: kernel configuration changed, removing ${d#$OBJ/}"
rm -rf "$d"
done
printf '%s\n' "$kckey" > "$kck"
fi
printf '%s\n' "$key" > "$STAMP"
echo "build-stamp: sources changed, derived artefacts rebuilt ($key)"