Files
makronix/tools/srctree-stage.sh
T
lotherk ce2d3211e1 srctree-stage: submodules go into the source set as tracked files
Since ext/src/mcde and the other projects are submodules, `git ls-files` names
each one as a single gitlink -- and pax -rw, given that path, copied the whole
working tree behind it: .git and build output included.  The root copy leaves
the gitlinks out now, and each submodule's tracked files are copied on their
own, so the source set carries the source and nothing else.

refs/ stays out as before: its five submodules are the 11 GB reference
checkouts, and only refs/AGENTS.md is part of a rebuild (the header says why).

Measured on the MacBook-built tree here:
- 7 submodules copied: splinter, krang, sshcrypt, kidstube, CNCL, mikronix,
  mcde (~303 MB together, mcde 286 MB).
- mcde alone: 19,591 files copied == `git -C ext/src/mcde ls-files | wc -l`,
  `find -name .git` = 0.
- sh -n tools/srctree-stage.sh rc=0.
2026-11-22 11:44:22 +01:00

148 lines
6.5 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.
for sub in $SUBMODULES; do
[ -d "$TOP/$sub" ] || die "submodule $sub is not checked out"
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"
"$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)"