diff --git a/tools/srctree-stage.sh b/tools/srctree-stage.sh index 5e72d8a277..c8f3a3dab1 100755 --- a/tools/srctree-stage.sh +++ b/tools/srctree-stage.sh @@ -21,7 +21,9 @@ # 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. +# 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 @@ -68,11 +70,39 @@ 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. -(cd "$TOP" && git ls-files | grep -v '^refs/' ; echo refs/AGENTS.md) | - (cd "$TOP" && "$PAX" -rw -pm "$DIR") \ +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.