diff --git a/tools/pkgchroot.sh b/tools/pkgchroot.sh index 72aeaecc9e..dc29ff9070 100755 --- a/tools/pkgchroot.sh +++ b/tools/pkgchroot.sh @@ -99,33 +99,50 @@ sandbox_index() # (tools/pkgsrc-cross.mk.conf), this one accepts it by name (measured # 2026-11-23: five recipes stopped on "unacceptable license condition"). `install' builds the package and installs it # into /usr/pkg -- which, inside the chroot, is the sysroot's /usr/pkg. -# pkgsrc keeps a work directory until it is told otherwise: the cookies -# (.build_done, .package_done) say the work is done, and `install' then takes -# the binary package that the last build produced. On this host that meant the -# release shipped MCDE and splinter as they were on 2026-11-22 21:39, while the -# distfiles of 2026-11-23 08:38 were never extracted -- pkg_add printed -# "already recorded as installed" and the step counted as done -# (build/logs/release-2026-11-23e.log:30,44). A work directory older than the -# recipe or the archive is not that package's build any more: it goes. -# -# The comparison is by mtime, not by content: the archive is written by -# tools/ext-dist.sh from the fork's HEAD, so a new commit gives it a new time, -# and a recipe edit touches its Makefile. -- 2026-11-23 +# A work directory is only that package's build if it was built from the recipe +# and archive that are in the tree now: pkgsrc keeps its cookies (.build_done, +# .package_done) until it is told otherwise, and `install' then takes the +# binary package of the last build. On the MacBook that shipped MCDE and +# splinter as they were on 2026-11-22 21:39 while their archives of 2026-11-23 +# 08:38 were never extracted -- pkg_add printed "already recorded as installed" +# and the step counted as done (build/logs/release-2026-11-23e.log:30,44). +# -- 2026-11-23 +# sha256 of stdin, on Linux and on NetBSD (cksum(1) there; no sha256sum), the +# same helper tools/userland.sh carries -- see the note there. +sha256_in() +{ + if command -v sha256sum > /dev/null 2>&1; then + sha256sum | cut -d' ' -f1 + else + cksum -a sha256 | awk '{ print $NF }' + fi +} + sandbox_stale() { sr_path=$1 w=$(ls -d "$SB/work/$sr_path"/work.* 2>/dev/null | head -1) [ -n "$w" ] || w=$SB/work/$sr_path/work [ -d "$w" ] || return 1 - # Everything pkgsrc reads before it builds: the Makefile, distinfo (which - # changes with the archive, tools/ext-dist.sh writes both), options, - # patches and the PLIST. No parsing of DISTFILES/DISTNAME: a recipe may - # name its archive either way, and a file in the recipe directory that is - # newer than the work directory is the one fact that matters. - newer=$(find "$TOP/pkgsrc/$sr_path" -newer "$w" -print -quit 2>/dev/null) - [ -n "$newer" ] || return 1 - echo "pkgchroot: $sr_path: ${newer#$TOP/pkgsrc/$sr_path/} is newer than the work directory -- rebuilding" + # What the work directory was built from, by content: a git checkout does + # not give a file a new mtime when the file's content changes only in the + # commit that touches it (measured 2026-11-23 on the MacBook: the recipe + # of mcde 288d1383 kept the time of 2026-11-22 10:27, so an mtime test + # said "not stale" and the release shipped the binary of the day before). + # The key covers the recipe (Makefile, options, patches, PLIST) and the + # archive that tools/ext-dist.sh names in distinfo. + key=$( { cat "$TOP/pkgsrc/$sr_path"/Makefile \ + "$TOP/pkgsrc/$sr_path"/options.mk 2>/dev/null + find "$TOP/pkgsrc/$sr_path" -type f \( -name '*.patch' -o -name 'PLIST*' \) \ + -exec cat {} + 2>/dev/null + cat "$TOP/pkgsrc/$sr_path"/distinfo 2>/dev/null; } | sha256_in ) + kf=$TOP/build/pkgsrc-work/$sr_path/.makronix-build-key + if [ "$(cat "$kf" 2>/dev/null)" = "$key" ]; then + return 1 + fi + echo "pkgchroot: $sr_path: recipe or archive changed since the last build -- rebuilding" rm -rf "$w" + mkdir -p "${kf%/*}" && printf '%s\n' "$key" > "$kf" return 0 }