Files
makronix/tools/srctree-stage.sh
lotherk 2d909814ae srctree-stage: the recipe mirror is part of the source set
The recipes of the forks are tracked in their submodules and the set carries
them, but a recipe builds only from inside pkgsrc's own tree, so
tools/ext-sync.sh places a mirror at pkgsrc/<category>/<name>.  That mirror is
named in pkgsrc's .git/info/exclude, so `git ls-files --others' does not list
it and the copy left it out: a tree built from the set had the recipe in
ext/src/<name>/pkgsrc and no way for pkgsrc to build it.  It is written into
the set now, with the symlinks resolved -- a link copied as a link would point
out of the set once it is unpacked somewhere else.

Verified: the staging loop writes pkgsrc/misc/splinter/Makefile and the other
seven mirrors as files, 0 symlinks below the staged pkgsrc, and the content is
the recipe (# $Makronix$ as the first line).
2026-11-23 20:24:10 +00:00

181 lines
8.2 KiB
Bash
Executable File

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
# srctree-stage.sh -- assemble the one source tree the source set carries.
#
# usage: srctree-stage.sh DIR
#
# DIR becomes the root of the set: makesrctars -m DIR packs it as
# usr/src/... (src/distrib/sets/makesrctars). That is the whole point: the
# set is the repository as it is, unpacked to /usr/src, so a Makronix system
# rebuilds itself from exactly the tree it was built from. There is no
# second tree at /usr/xsrc and no /usr/msrc any more (Konrad, 2026-11-15):
#
# src/ xsrc/ ext/ pkgsrc/ mobile/ www/ docs/ tools/ the repository
# Makefile GOAL.md AGENTS.md LICENSE ROADMAP.md ... its root files
# packages.list PINS distfiles.lst packages, pins, archives
# distfiles/ only the archives of
# distfiles.lst
#
# The file list is git's: every tracked file of the root repository and of
# pkgsrc (its own repository, pinned) is copied from the working tree, so a
# change that is not committed yet is in the set the running build uses. No
# .git and no build output is carried. refs/ is a set of reference
# checkouts (netbsd, linux, openbsd, 11 GB) and only its AGENTS.md is part of
# the tree a rebuild needs. A submodule (ext/src/*) is copied the same way:
# its tracked files, no .git, no build output -- git ls-files names it as one
# gitlink and pax would otherwise take the whole working tree behind it.
#
# Refuses a pkgsrc that has local edits, a stale PINS, and distfiles that are
# not complete. ustar limit: pkgsrc patch names longer than 100 characters
# (or 155 in the directory part) are not in the tree but in
# pkgsrc-longnames.cpio, which the installer puts back (sysinst setup.c).
set -eu
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
[ $# -eq 1 ] || { echo "usage: $0 DIR" >&2; exit 1; }
DIR=$1
# absolute: the copy runs in subshells that change directory (pkgsrc/)
case $DIR in
/*) ;;
*) DIR=$(pwd)/$DIR ;;
esac
die()
{
echo "srctree-stage: $*" >&2
exit 1
}
"$TOP/tools/makronix-pins.sh" check || die "PINS is stale"
# pkgsrc must be what the pin says, with nothing changed (our AGENTS.md at its
# root is untracked on purpose)
[ -z "$(git -C "$TOP/pkgsrc" status --porcelain --untracked-files=no)" ] \
|| die "pkgsrc has local edits; the set carries the pinned commit"
# pax of the tooldir keeps the modes (0655 is wrong on scripts) and the links;
# the host's pax may not exist (the build host is Linux for the cross build).
PAX=$(ls "$TOP"/build/obj/tooldir.*/bin/nbpax 2>/dev/null | head -1)
[ -n "$PAX" ] && [ -x "$PAX" ] || PAX=pax
command -v "$PAX" >/dev/null 2>&1 || die "no pax (nbpax, or pax in PATH)"
rm -rf "$DIR"
mkdir -p "$DIR"
# The submodule paths: git ls-files names each one as a single gitlink, and
# pax -rw would copy the whole working tree behind it -- .git and build output
# included. The root copy leaves them out and each submodule's tracked files
# are copied below, so the set carries the source and nothing else.
SUBMODULES=
if [ -f "$TOP/.gitmodules" ]; then
SUBMODULES=$(git -C "$TOP" config --file .gitmodules --get-regexp \
'^submodule\..*\.path$' | awk '{ print $2 }' | sed '/^refs\//d')
fi
# The root repository, tracked files only, from the working tree.
rootlist=$(mktemp) || die "no mktemp"
trap 'rm -f "$rootlist" "$rootlist.new"' EXIT HUP INT TERM
(cd "$TOP" && git ls-files | grep -v '^refs/' ; echo refs/AGENTS.md) > "$rootlist"
for sub in $SUBMODULES; do
grep -v -F -x "$sub" "$rootlist" > "$rootlist.new"
rc=$?
[ "$rc" -eq 0 ] || [ "$rc" -eq 1 ] ||
die "filtering $sub from the file list failed"
mv "$rootlist.new" "$rootlist"
done
(cd "$TOP" && "$PAX" -rw -pm "$DIR") < "$rootlist" \
|| die "copying the repository into $DIR failed"
# Each submodule: its tracked files, no .git, no build output. A submodule
# that is not checked out is left out of the set: the ones the build needs are
# the forks of ext/ (ext/AGENTS.md) and pkgsrc, and the rest (krang, sshcrypt,
# kidstube, CNCL, mikronix) carry no file the release reads. A fresh clone
# that did not run `git submodule update --init' for them must not stop the
# release in this step (measured 2026-11-23: `git submodule update --recursive'
# on the MacBook aborted on ext/src/mikronix, whose remote wants a password).
for sub in $SUBMODULES; do
if [ ! -d "$TOP/$sub" ] || [ -z "$(ls -A "$TOP/$sub" 2>/dev/null)" ]; then
echo "srctree-stage: $sub is not checked out, not in the source set" >&2
continue
fi
mkdir -p "$DIR/$sub"
(cd "$TOP/$sub" && git ls-files) |
(cd "$TOP/$sub" && "$PAX" -rw -pm "$DIR/$sub") \
|| die "copying submodule $sub into $DIR/$sub failed"
done
# pkgsrc: its own repository, pinned, plus what is ours and untracked there
# (AGENTS.md and the recipes of the Makronix packages, tools/ext-sync.sh copies
# them in; git ignores neither). build/ and other ignored work is not carried.
mkdir -p "$DIR/pkgsrc"
(cd "$TOP/pkgsrc" && git ls-files && git ls-files --others --exclude-standard) |
(cd "$TOP/pkgsrc" && "$PAX" -rw -pm "$DIR/pkgsrc") \
|| die "copying pkgsrc into $DIR/pkgsrc failed"
# The recipes of the forks (ext/src/<name>/pkgsrc) are tracked files of the
# submodules, so the set already has them. What is missing is the mirror that
# makes pkgsrc build one: a recipe builds only from inside pkgsrc's own tree,
# so tools/ext-sync.sh places it at pkgsrc/<category>/<name>. That mirror is
# named in pkgsrc's .git/info/exclude, so the copy above does not carry it --
# and without it a tree built from this set rebuilds itself without splinter,
# mcde and the servers. The files are written, not linked: a link that stayed
# a link would point out of the set once it is unpacked somewhere else.
if [ -x "$TOP/tools/ext-sync.sh" ]; then
"$TOP/tools/ext-sync.sh" >/dev/null || die "tools/ext-sync.sh failed"
for d in "$TOP"/pkgsrc/*/*/; do
d=${d%/}
[ -L "$d/Makefile" ] || continue
rel=${d#$TOP/pkgsrc/}
mkdir -p "$DIR/pkgsrc/$rel"
(cd "$d" && find . \( -type f -o -type l \) | sed 's|^\./||') |
while read -r f; do
mkdir -p "$DIR/pkgsrc/$rel/$(dirname "$f")"
cp -pL "$d/$f" "$DIR/pkgsrc/$rel/$f" ||
die "copying $rel/$f into the source set failed"
done
done
fi
"$TOP/tools/makronix-distfiles.sh" stage "$DIR"
# ustar is the format of every set, and the installer's tar (bin/pax built
# -DSMALL -DNO_CPIO, distrib/amd64/ramdisks) reads nothing else: a pathname is
# stored only if its last component has at most 100 characters and the
# directory part at most 155 (pax(1), -x ustar). pax drops the rest and the
# set is still made, exit 0: 235 patch files of eleven packages (www/firefox,
# mail/thunderbird, devel/bazel ...) on 2026-11-14
# (build/logs/sourcesets-2026-11-14b.log). pkgsrc names a patch after the file
# it patches and records the name in distinfo, so the files cannot be renamed.
# They go into pkgsrc-longnames.cpio instead (cpio has no such limit; the
# installed system's pax reads it, only the installer's does not): the files
# are taken out of the ustar tree, and the installation puts them back
# (sysinst setup.c: `pax -r -pp -f pkgsrc-longnames.cpio` in usr/src/pkgsrc).
(cd "$DIR/pkgsrc" && find . -path ./.git -prune -o -type f -print | sed 's|^\./||') |
awk '{
full = "usr/src/pkgsrc/" $0
n = split(full, c, "/"); last = c[n]
dir = substr(full, 1, length(full) - length(last) - 1)
if (length(last) > 100 || length(dir) > 155)
print $0
}' | LC_ALL=C sort > "$DIR/pkgsrc-longnames.txt"
if [ -s "$DIR/pkgsrc-longnames.txt" ]; then
(cd "$DIR/pkgsrc" && "$PAX" -w -x cpio -d < "$DIR/pkgsrc-longnames.txt") \
> "$DIR/pkgsrc-longnames.cpio" || die "pax -x cpio failed"
while read -r f; do
rm -f "$DIR/pkgsrc/$f"
done < "$DIR/pkgsrc-longnames.txt"
echo "srctree-stage: $(wc -l < "$DIR/pkgsrc-longnames.txt" | tr -d ' ') files with names ustar cannot store are in pkgsrc-longnames.cpio"
fi
rm -f "$DIR/pkgsrc-longnames.txt"
echo "srctree-stage: $DIR ready: $(find "$DIR" | wc -l | tr -d ' ') entries," \
"$(du -sh "$DIR" | cut -f1)"