Repair distfiles that tools' chroot cannot fetch, and let tools list them

Natively, the first fetch in tools' distfiles chroot builds pkg, whose
GitHub patches no longer match distinfo, and tools' fetch loop records
a failure in a path outside the chroot, which under sh -e ended the
loop with no port named. patches/tools/0001 records failures inside
the chroot (as tools' ports step does); build.sh applies patches/tools
to every series. pkg's distfiles go into the set before the step, via
fetch-patch.sh; repairs are appended to the set instead of rewriting
a set of many gigabytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jeremy Karst 2026-11-19 06:45:58 -05:00
parent 23f43f6b6c
commit b59c0e41ed
4 changed files with 90 additions and 20 deletions

View file

@ -45,6 +45,7 @@ opnsense-deps/
├── rc.d/ # rc.d service scripts and syshook scripts
├── pkg/ # FreeBSD package metadata
├── patches/<series>/ # opnsense/core patches (mirror, signing key, CMM restart)
├── patches/tools/ # opnsense/tools fixes, every series
├── keys/ # mirror public key and trusted/revoked fingerprints
├── release/ # build VM, release build, device migration (+ tests)
├── mirror/ # gwmirror.py stage/verify/publish, nginx container (+ tests)

View file

@ -194,7 +194,8 @@ release/vm.sh pull-out 14.3 26.1 # -> /scratch/mono-opnsense/out/26.1
and a transfer that moves nothing for 10 minutes fails the build instead
of hanging.
2. Applies `patches/<series>/*.patch` to core with `git am`. Core's version
becomes `<release>_<patches>`.
becomes `<release>_<patches>`. Applies `patches/tools/*.patch`, fixes to
tools itself, for every series (see step 4).
3. Builds base, kernel and xtools, then this repository's kernel modules, as
an early check against the new kernel.
4. Fetches the distfiles of every port and its dependencies into the
@ -204,12 +205,21 @@ release/vm.sh pull-out 14.3 26.1 # -> /scratch/mono-opnsense/out/26.1
the object names on their `index` lines with more digits as a repository
grows, so an old patch now differs by a few bytes. FreeBSD's distfile
cache keeps the originals of FreeBSD's ports, but nothing keeps
OPNsense's own (e.g. the patches of `ports-mgmt/pkg`). The ports that
failed are fetched again on the build host with `release/fetch-patch.sh`,
which shortens the abbreviations until the size matches distinfo; the
port's `checksum` target then verifies the SHA256, so only the original
bytes are accepted. A distfile that still cannot be fetched stops the
build with the port's name.
OPNsense's own (e.g. the patches of `ports-mgmt/pkg`). Such ports are
fetched on the build host with `release/fetch-patch.sh`, which shortens
the abbreviations until the size matches distinfo; the port's `checksum`
target then verifies the SHA256, so only the original bytes are
accepted. The results are appended to the distfiles set, which tools'
step starts from.
- `ports-mgmt/pkg` is fetched this way first: tools' chroot builds pkg
before its first fetch, so every port would fail on pkg's patches.
- Then tools' step runs. The ports it reports as failed are fetched this
way, and the step runs once more. Tools 26.1.11 (and master) cannot
report them: its fetch loop runs in the chroot but records failures in
a path outside it, so the first failure ended the loop.
`patches/tools/0001` fixes that.
- A distfile that still cannot be fetched stops the build with the
port's name.
5. Builds the ports in chunks of `PORTS_CHUNK` (default 20) ports. Tools
adds the packages it built to the packages set only when a ports step
ends, and every run starts from that set, so a single step of several days

View file

@ -0,0 +1,39 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jeremy Karst <jeremy@karsttech.com>
Date: Thu, 19 Nov 2026 06:45:01 -0500
Subject: [PATCH] build/distfiles: record fetch failures inside the chroot
The fetch loop runs in the chroot, where ${STAGEDIR} does not exist,
so recording the first failed fetch failed and, under "sh -e", ended
the loop: every later port went unfetched and the step only said that
it did not finish properly. Write /.pkg-msg in the chroot, which is
the ${STAGEDIR}/.pkg-msg the step reads afterwards, as ports.sh does.
---
build/distfiles.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/build/distfiles.sh b/build/distfiles.sh
index 9ebcf6f..db9f745 100644
--- a/build/distfiles.sh
+++ b/build/distfiles.sh
@@ -81,7 +81,7 @@ echo "${PORTSLIST}" | while read PORT_ORIGIN; do
if [ -n "${PRODUCT_REBUILD}" ]; then
exit 1
fi
- echo ">>> Failed fetching \${PORT}" >> ${STAGEDIR}/.pkg-msg
+ echo ">>> Failed fetching \${PORT}" >> /.pkg-msg
fi
PORT_DEPENDS=\$(make -C ${PORTSDIR}/\${PORT} all-depends-list \
\${MAKE_ARGS})
@@ -96,7 +96,7 @@ echo "${PORTSLIST}" | while read PORT_ORIGIN; do
if [ -n "${PRODUCT_REBUILD}" ]; then
exit 1
fi
- echo ">>> Failed fetching \${PORT}" >> ${STAGEDIR}/.pkg-msg
+ echo ">>> Failed fetching \${PORT}" >> /.pkg-msg
fi
done
done
--
2.53.0

View file

@ -113,6 +113,11 @@ checkout_all()
# shellcheck disable=SC2086
git ${COMMITTER} -C /usr/core am -q --committer-date-is-author-date ${PATCHES}
echo " /usr/core: $(git -C /usr/core describe --tags) with $(echo "${PATCHES}" | wc -l | tr -d ' ') patches"
# fixes to tools itself, for every series
PATCHES=$(ls "${DEPS}"/patches/tools/*.patch) || die "no patches/tools"
# shellcheck disable=SC2086
git ${COMMITTER} -C /usr/tools am -q --committer-date-is-author-date ${PATCHES}
echo " /usr/tools: with $(echo "${PATCHES}" | wc -l | tr -d ' ') patches"
cp "${DEPS}/config/GATEWAY.conf" /usr/tools/device/
echo " /usr/deps: $(git -C "${DEPS}" describe --tags --always --dirty)"
}
@ -198,14 +203,36 @@ build_ports()
${TOOLS} ${UNSIGNED} ports-gwchunk
}
# repair_distfiles PORT...: fetch the distfiles of the PORTs on this host with
# fetch-patch.sh, which recovers the patches GitHub now generates differently from
# the ones recorded in distinfo (the ports' checksum target verifies the results),
# and add them to the distfiles set, which tools' distfiles step starts from. They
# are appended: a file the set already has is extracted twice, both copies verified.
repair_distfiles()
{
_set=$(ls "${SETS}"/distfiles-*.tar 2> /dev/null | head -1)
[ -n "${_set}" ] || _set=${SETS}/distfiles-${VERSION}.tar
_dir=$(mktemp -d /var/tmp/gwdistfiles.XXXXXX)
for _port; do
make -C "/usr/ports/${_port}" BATCH=yes ARCH=aarch64 DISTDIR="${_dir}/distfiles" \
"${FETCH_PATCH}" checksum || die "cannot fetch the distfiles of ${_port}"
done
mkdir -p "${SETS}"
if [ -f "${_set}" ]; then _op=-rf; else _op=-cf; fi
tar -C "${_dir}" ${_op} "${_set}" distfiles
rm -rf "${_dir}"
}
# fetch_distfiles [PORTSLIST=...]: tools' distfiles step, which fetches every distfile
# of the ports (and their dependencies) into the distfiles set. Some no longer download
# as recorded in distinfo, chiefly patches GitHub generates on the fly; the failed ports
# are fetched again on this host into the set with fetch-patch.sh, whose results the
# ports' checksum target verifies, and the step is run once more.
# of the ports (and their dependencies) into the distfiles set. Its chroot builds pkg
# before its first fetch, so pkg's distfiles go into the set first. The ports whose
# distfiles fail to fetch (tools lists them, patches/tools/0001) are repaired, and the
# step is run once more.
fetch_distfiles()
{
_log=/var/tmp/gwbuild-distfiles.log
step "distfiles of ports-mgmt/pkg"
repair_distfiles ports-mgmt/pkg
step "distfiles"
# shellcheck disable=SC2086
{ _rc=0; ${TOOLS} ${UNSIGNED} distfiles "$@" 2>&1 || _rc=$?; echo "${_rc}" > "${_log}.rc"; } |
@ -214,15 +241,8 @@ fetch_distfiles()
_ports=$(sed -n 's|^>>> Failed fetching \(/usr/ports/\)\{0,1\}||p' "${_log}" | sort -u)
[ -n "${_ports}" ] || die "the distfiles step failed (see above)"
step "repairing the distfiles of:" ${_ports}
_set=$(ls "${SETS}"/distfiles-*.tar) || die "no distfiles set"
_dir=$(mktemp -d /var/tmp/gwdistfiles.XXXXXX)
tar -C "${_dir}" -xf "${_set}"
for _port in ${_ports}; do
make -C "/usr/ports/${_port}" BATCH=yes ARCH=aarch64 DISTDIR="${_dir}/distfiles" \
"${FETCH_PATCH}" checksum || die "cannot fetch the distfiles of ${_port}"
done
tar -C "${_dir}" -cf "${_set}" distfiles
rm -rf "${_dir}"
# shellcheck disable=SC2086
repair_distfiles ${_ports}
step "distfiles, after the repair"
# shellcheck disable=SC2086
${TOOLS} ${UNSIGNED} distfiles "$@"