Files
makronix/tools/ext-sync.sh
T
lotherk 974603f8a6 pkgsrc: the forks of ext/ build from their tree, not from an archive
Each fork kept a recipe beside its source and a tarball in distfiles/ whose
distinfo had to be regenerated after every commit (tools/ext-dist.sh,
tools/mcde-dist.sh), and the work directory of a build could not see a later
commit at all (tools/ext-resync.sh merged an archive into it).  Three tools,
one artefact per fork in git, and the failure mode that cost the 2026-11-23
release: mcde 288d1383 built from the commit of the day before, because the
recipe's mtime said "not stale".

Now the recipe builds the source tree itself, which is how pkgsrc's own
net/fetch and pkgtools/pkg_install do it: DISTFILES= # empty, do-extract
fills WRKSRC.  What is gone with that:

  - the tarballs (distfiles/{mcde,splinter,junction,wikid,skilld,memoryd,
    tasksd}-*) and their .key
  - tools/ext-dist.sh, tools/mcde-dist.sh, tools/ext-resync.sh and its test
  - fork_archives in tools/makronix-distfiles.sh (nothing to fetch or stage)
  - the distinfo files of the eight recipes

What replaces it: tools/ext-extract.sh, called from do-extract.  It hashes
the tree, copies only the files that differ, keeps the time stamp of the rest
(so a commit rebuilds what it touched and not 27 minutes of MCDE) and
removes the copy when a file left the tree.  The build key of a fork carries
the source commit for the same reason: a commit does not change the recipe.

The recipes keep $Makronix$ as their header; afpfs-ng keeps its upstream
$NetBSD: ...$ line and its real distfile, and fork_src() leaves it alone.

Verified:
  - bmake package built all eight recipes from the tree with no distinfo:
    splinter, junction, wikid, skilld, memoryd, tasksd, mcde (16 MB), and
    mcde-motif's shared tree
  - tools/test-tools.sh: 38 ok, 0 bad (5 new cases for ext-extract.sh)
  - tools/makronix-distfiles.sh check: 0 missing, 0 wrong hash
  - tools/makronix-pins.sh check: PINS matches
2026-11-23 19:49:07 +00:00

86 lines
3.0 KiB
Bash
Executable File

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# ext-sync.sh -- make the recipe of a fork in ext/ visible to pkgsrc
#
# usage: tools/ext-sync.sh [PKGSRCDIR]
#
# A fork under ext/src/<name>/ keeps its recipe beside its source
# (ext/src/<name>/pkgsrc/, ext/AGENTS.md): that is the file a person edits and
# the file git tracks. pkgsrc builds a recipe only from inside its own tree --
# the recipe includes ../../mk/bsd.pkg.mk, and bmake resolves that relative to
# the *directory of the file* -- so the recipe is mirrored to
# PKGSRCDIR/<category>/<name>, the category being the first word of its
# CATEGORIES.
#
# A mirror, not a copy that lives on its own: each file is a symlink to the
# tracked original (files only -- a directory symlink would move .CURDIR out of
# the tree and break the ../../mk includes). One file to edit, one file to
# commit; the mirror is build output and pkgsrc's .git/info/exclude names it.
#
# The target is only ever replaced when upstream pkgsrc does not own that path
# (`git ls-files' of the pkgsrc import is empty for it): an upstream package of
# the same name is never touched.
#
# wkdir/ of the mirror is a small Makefile that points pkgsrc's work directory
# at the source tree the recipe builds from (no archive, no extraction), so a
# build compiles ext/src/<name> itself.
#
# Prints one line, "ext-sync: <category>/<name> ...", per recipe mirrored;
# tools/userland.sh reads the list back from it.
set -eu
TOP=$(cd "$(dirname "$0")/.." && pwd)
PKGSRCDIR=${1:-$TOP/pkgsrc}
[ -d "$PKGSRCDIR/mk" ] || { echo "ext-sync: no pkgsrc at $PKGSRCDIR" >&2; exit 1; }
mirror_one()
{
recipe=$1
name=$(basename "$(dirname "$recipe")")
part=
case ${recipe##*/} in
pkgsrc-*) part=-${recipe##*/pkgsrc-} ;;
esac
cat=$(sed -n 's/^CATEGORIES=[[:space:]]*\([^[:space:]]*\).*/\1/p' \
"$recipe/Makefile")
[ -n "$cat" ] || { echo "ext-sync: no CATEGORIES= in $recipe/Makefile" >&2; return 1; }
pkg=$name$part
dst=$PKGSRCDIR/$cat/$pkg
# upstream's own package of this name is never overwritten
if [ -n "$(git -C "$PKGSRCDIR" ls-files "$cat/$pkg" 2>/dev/null)" ]; then
echo "ext-sync: $cat/$pkg belongs to upstream pkgsrc; not mirrored" >&2
return 0
fi
rm -rf "$dst"
mkdir -p "$dst"
# every file of the recipe, by name; a directory ($FILESDIR, patches/)
# is mirrored file by file the same way
(cd "$recipe" && find . -type f | sed 's|^\./||') | while read -r f; do
mkdir -p "$dst/$(dirname "$f")"
rel=$(cd "$dst/$(dirname "$f")" && realpath -m --relative-to=. "$recipe/$f")
ln -s "$rel" "$dst/$f"
done
echo "ext-sync: $cat/$pkg from ${recipe#$TOP/}"
}
for recipe in "$TOP"/ext/src/*/pkgsrc "$TOP"/ext/src/*/pkgsrc-*; do
[ -f "$recipe/Makefile" ] || continue
mirror_one "$recipe" || exit 1
done
# a recipe that was removed from ext/ leaves nothing behind
for d in "$PKGSRCDIR"/*/*/; do
d=${d%/}
[ -L "$d/Makefile" ] || continue
tgt=$(readlink -f "$d/Makefile") || continue
case $tgt in
"$TOP"/ext/src/*) [ -f "$tgt" ] || { rm -rf "$d"; echo "ext-sync: removed stale $d"; } ;;
esac
done