userland: check out the submodules before anything reads them

A fresh clone has none of pkgsrc, ext/src/* checked out, and the release dies
in step 2 with 'no pkgsrc/bootstrap (pkgsrc submodule, PINS)'.  The tree
carries everything it needs, so the build fetches it: the pinned submodules
are checked out at the start of userland, pkgsrc and the ext/ forks are then
required to be there, and the private trees the build does not read only warn.

Test: git submodule status marks the five private trees '-' (krang, sshcrypt,
kidstube, mikronix, CNCL) and the awk selects exactly those; a missing
pkgsrc/bootstrap dies with the message above.
This commit is contained in:
lotherk committed 2026-11-23 13:46:28 +00:00
1 parent c64b502ad8
commit 7b02c454f6
1 file changed
+41
+41
View File
@@ -421,6 +421,47 @@ fork_reconfigure()
(cd "$PKGSRC/$1" && "$BMAKE" tools) || return 1
}
# The tree carries pkgsrc, the forks of ext/ and the reference trees as git
# submodules (git submodule status). A fresh clone has none of them checked
# out, and the release cannot run without them: PKGSRC/bootstrap, the recipes
# in ext/src/*/pkgsrc, tools/ext-dist.sh's archives. Doing it here, before
# anything reads those paths, is what makes `make release` on a bare clone the
# same command as on a tree that was prepared by hand (Konrad, 2026-11-23:
# makronix carries everything it needs, in the repository, always complete).
#
# --depth 1 is not used: PINS records a commit per submodule and a shallow
# clone cannot check out anything but the tip. A submodule that is already at
# its pinned commit costs one `git submodule update` that does nothing.
ensure_submodules()
{
[ -f "$TOP/.gitmodules" ] || return 0
# `git submodule status' prefixes the commit: '-' for one that is not
# checked out, '+' for one at the wrong commit, ' ' for the pinned one.
# (The prefix is glued to the hash, so the test is on the first character
# of the line, not on a field.)
need=$(cd "$TOP" && git submodule status 2>/dev/null |
awk 'substr($0, 1, 1) == "-" || substr($0, 1, 1) == "+" { print $2 }')
[ -n "$need" ] || return 0
echo "userland: submodules at their pin: $(echo $need)"
# A submodule that cannot be fetched (a private tree this build does not
# use, no credentials on the host) must not stop the release: it is only
# needed when something reads it, and that read fails with a clear message.
# The ones that matter -- pkgsrc and the ext/ forks -- are checked below.
for sub in $need; do
(cd "$TOP" && git submodule update --init -- "$sub") ||
echo "userland: warning: $sub is not checked out" >&2
done
[ -d "$PKGSRC/bootstrap" ] ||
die "$PKGSRC is not checked out (git submodule update --init pkgsrc)"
for w in "$TOP"/ext/src/*/pkgsrc; do
[ -d "$w" ] || continue
p=${w%/pkgsrc}; p=${p##*/}
[ -n "$(ls -A "$w" 2>/dev/null)" ] ||
die "ext/src/$p is not checked out (its recipe is needed)"
done
}
ensure_submodules
ensure_bootstrap
echo "userland: $MODE build on $(uname -s)"
[ $MODE = cross ] && ensure_mkconf