build: skip distfiles the set already has; retry GitHub patches
The restarted build stopped at seeding pkg's distfiles: GitHub answered "Service Unavailable" for a patch the distfiles set already held. repair_distfiles now skips a port whose distfiles and patch files are all in the set (distfiles_in_set), and fetch-patch.sh tries GitHub's current patch three times, a minute apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9eceff0663
commit
d8bba11344
4 changed files with 114 additions and 7 deletions
|
|
@ -220,8 +220,11 @@ release/vm.sh pull-out 14.3 26.1 # -> /scratch/mono-opnsense/out/26.1
|
|||
- 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 extracts into every ports step's chroot.
|
||||
bytes are accepted. GitHub turns automated requests away now and then
|
||||
("Service Unavailable"), so the current patch is tried three times, a
|
||||
minute apart. The results are appended to the distfiles set, which
|
||||
tools extracts into every ports step's chroot. A port whose distfiles
|
||||
the set has already is skipped, so a rerun downloads nothing for it.
|
||||
- `ports-mgmt/pkg` is fetched this way before the ports step: its
|
||||
chroot builds pkg before anything else.
|
||||
- Any other port whose distfiles fail to fetch ("Couldn't fetch it" in
|
||||
|
|
|
|||
|
|
@ -199,22 +199,43 @@ fetch_failures()
|
|||
# the ones recorded in distinfo (the ports' checksum target verifies the results),
|
||||
# and add them to the distfiles set, which tools extracts into the ports step's
|
||||
# chroot. They are appended: a file the set already has is extracted twice, both
|
||||
# copies verified.
|
||||
# copies verified. A PORT whose distfiles the set has already is skipped, so a
|
||||
# rerun needs no download for it.
|
||||
repair_distfiles()
|
||||
{
|
||||
_set=$(ls "${SETS}"/distfiles-*.tar 2> /dev/null | head -1)
|
||||
[ -n "${_set}" ] || _set=${SETS}/distfiles-${VERSION}.tar
|
||||
_have=
|
||||
[ ! -f "${_set}" ] || _have=$(tar -tf "${_set}")
|
||||
_dir=$(mktemp -d /var/tmp/gwdistfiles.XXXXXX)
|
||||
for _rport; do
|
||||
if distfiles_in_set "${_rport}" "${_have}"; then
|
||||
echo ">>> the distfiles set has the distfiles of ${_rport}"
|
||||
continue
|
||||
fi
|
||||
make -C "/usr/ports/${_rport}" BATCH=yes ARCH=aarch64 DISTDIR="${_dir}/distfiles" \
|
||||
"${FETCH_PATCH}" checksum || die "cannot fetch the distfiles of ${_rport}"
|
||||
done
|
||||
mkdir -p "${SETS}"
|
||||
if [ -f "${_set}" ]; then _op=-rf; else _op=-cf; fi
|
||||
tar -C "${_dir}" ${_op} "${_set}" distfiles
|
||||
if [ -d "${_dir}/distfiles" ]; then
|
||||
mkdir -p "${SETS}"
|
||||
if [ -f "${_set}" ]; then _op=-rf; else _op=-cf; fi
|
||||
tar -C "${_dir}" ${_op} "${_set}" distfiles
|
||||
fi
|
||||
rm -rf "${_dir}"
|
||||
}
|
||||
|
||||
# distfiles_in_set PORT LISTING: whether LISTING, the distfiles set's "tar -t", has
|
||||
# every distfile and patch file of PORT (distfiles/[DIST_SUBDIR/]NAME)
|
||||
distfiles_in_set()
|
||||
{
|
||||
_sub=$(make -C "/usr/ports/${1}" ARCH=aarch64 -V DIST_SUBDIR) || return 1
|
||||
_files=$(make -C "/usr/ports/${1}" ARCH=aarch64 -V ALLFILES) || return 1
|
||||
printf '%s\n' "${2}" | awk -v want="${_files}" -v pre="distfiles/${_sub:+${_sub}/}" '
|
||||
BEGIN { n = split(want, w, /[ \t]+/); for (i = 1; i <= n; i++) if (w[i] != "") need[pre w[i]] = 1 }
|
||||
{ delete need[$0] }
|
||||
END { for (f in need) exit 1 }'
|
||||
}
|
||||
|
||||
# the board package is cross-compiled against the base set's headers and libraries
|
||||
sysroot_base()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -47,7 +47,12 @@ esac
|
|||
|
||||
TMP=$(mktemp "./.fetch-patch.XXXXXX") || exit 1
|
||||
trap 'rm -f "${TMP}" "${TMP}.n"' EXIT
|
||||
fetch -q -o "${TMP}" "${URL}" || exit 1
|
||||
# GitHub turns requests away now and then ("Service Unavailable")
|
||||
for TRY in 1 2 3; do
|
||||
fetch -q -o "${TMP}" "${URL}" && break
|
||||
[ "${TRY}" -lt 3 ] || exit 1
|
||||
sleep 60
|
||||
done
|
||||
for N in 7 8 9 10 11 12; do
|
||||
sed -E "s/^index ([0-9a-f]{${N}})[0-9a-f]*\.\.([0-9a-f]{${N}})[0-9a-f]*/index \1..\2/" \
|
||||
"${TMP}" > "${TMP}.n" || exit 1
|
||||
|
|
|
|||
|
|
@ -444,12 +444,15 @@ class FetchPatchTest(unittest.TestCase):
|
|||
# framework's attempt ("fetch -Fpr ...") fails on the size unless FAKE_DIRECT
|
||||
self.fx.make_fake("fetch", """if [ "$1 $2" = "-q -o" ]; then
|
||||
[ -z "${FAKE_DOWNLOAD_FAIL:-}" ] || exit 1
|
||||
n=$(grep -c '^fetch -q -o' "$FAKE_LOG")
|
||||
[ "$n" -gt "${FAKE_DOWNLOAD_FAILS:-0}" ] || exit 1
|
||||
exec cp "$FAKE_SERVED" "$3"
|
||||
fi
|
||||
[ -n "${FAKE_DIRECT:-}" ] || exit 1
|
||||
for a; do last=$a; done
|
||||
echo direct > "${last##*/}"
|
||||
""")
|
||||
self.fx.make_fake("sleep", "exit 0")
|
||||
|
||||
def fetch(self, *args, **env):
|
||||
e = {"PATH": f"{self.fx.bin}:/usr/bin:/bin", "FAKE_LOG": self.fx.log, "FAKE_SERVED": self.served}
|
||||
|
|
@ -516,6 +519,22 @@ echo direct > "${last##*/}"
|
|||
r = self.fetch("-S", str(len(PATCH_9)), GH_URL, FAKE_DOWNLOAD_FAIL="1")
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertEqual(self.files(), [])
|
||||
downloads = [c for c in self.fx.calls() if c.startswith("fetch -q -o")]
|
||||
self.assertEqual(len(downloads), 3, "three attempts")
|
||||
self.assertEqual([c for c in self.fx.calls() if c.startswith("sleep")], ["sleep 60"] * 2)
|
||||
|
||||
def test_download_retried(self):
|
||||
# GitHub turned the first two requests away
|
||||
r = self.fetch("-S", str(len(PATCH_9)), GH_URL, FAKE_DOWNLOAD_FAILS="2")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertEqual(self.files(), ["a54ea1a2f7d858fe6eb2976d688c251e64acf8f8.patch"])
|
||||
self.assertEqual(len([c for c in self.fx.calls() if c.startswith("sleep")]), 2)
|
||||
|
||||
def test_direct_fetch_is_not_retried(self):
|
||||
# the framework's own attempt fails and moves on to its next site
|
||||
r = self.fetch("-S", "123", "https://example.org/x.tar.gz")
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertEqual(len(self.fx.calls()), 1)
|
||||
|
||||
def test_rejects_unsafe_output_names(self):
|
||||
for out in ("../evil.patch", "/tmp/evil.patch", "a/../../evil.patch", "..", ".", "dir/"):
|
||||
|
|
@ -624,5 +643,64 @@ class FetchFailuresTest(unittest.TestCase):
|
|||
self.assertEqual(self.failures(log), ["devel/libstdc++_stldoc_4.2.2", "devel/py-setuptools"])
|
||||
|
||||
|
||||
class DistfilesInSetTest(unittest.TestCase):
|
||||
"""build.sh's distfiles_in_set: whether a port's distfiles need no download."""
|
||||
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.mkdtemp(prefix="gw-dist-")
|
||||
self.addCleanup(shutil.rmtree, self.tmp)
|
||||
self.fx = Fixture(self.tmp)
|
||||
# the ports tree's answers for "make -C /usr/ports/PORT ARCH=aarch64 -V VAR"
|
||||
self.fx.make_fake("make", """case "$1 $2 $3 $4 $5" in
|
||||
"-C /usr/ports/cat/port ARCH=aarch64 -V DIST_SUBDIR") echo "${FAKE_SUB:-}";;
|
||||
"-C /usr/ports/cat/port ARCH=aarch64 -V ALLFILES") echo "${FAKE_FILES:-}";;
|
||||
*) exit 2;;
|
||||
esac""")
|
||||
self.func = subprocess.run(["sed", "-n", "/^distfiles_in_set()/,/^}/p", BUILD],
|
||||
capture_output=True, text=True, check=True).stdout
|
||||
self.assertIn("distfiles_in_set()", self.func)
|
||||
|
||||
def in_set(self, listing, files, sub="", port="cat/port"):
|
||||
r = subprocess.run(["sh", "-c", self.func + '\ndistfiles_in_set "$1" "$2"', "sh", port, listing],
|
||||
env={"PATH": f"{self.fx.bin}:/usr/bin:/bin", "FAKE_LOG": self.fx.log,
|
||||
"FAKE_FILES": files, "FAKE_SUB": sub},
|
||||
cwd=self.tmp, capture_output=True, text=True)
|
||||
self.assertIn(r.returncode, (0, 1), r.stderr)
|
||||
return r.returncode == 0
|
||||
|
||||
LISTING = "distfiles/\ndistfiles/a-1.0.tar.gz\ndistfiles/x.patch\ndistfiles/perl/perl-5.42.2.tar.xz\n"
|
||||
|
||||
def test_all_present(self):
|
||||
self.assertTrue(self.in_set(self.LISTING, "a-1.0.tar.gz x.patch"))
|
||||
|
||||
def test_one_missing(self):
|
||||
self.assertFalse(self.in_set(self.LISTING, "a-1.0.tar.gz x.patch y.patch"))
|
||||
|
||||
def test_dist_subdir(self):
|
||||
self.assertTrue(self.in_set(self.LISTING, "perl-5.42.2.tar.xz ", sub="perl"))
|
||||
self.assertFalse(self.in_set(self.LISTING, "perl-5.42.2.tar.xz"), "not without the subdirectory")
|
||||
self.assertFalse(self.in_set(self.LISTING, "a-1.0.tar.gz", sub="perl"))
|
||||
|
||||
def test_port_without_distfiles(self):
|
||||
self.assertTrue(self.in_set(self.LISTING, ""))
|
||||
self.assertTrue(self.in_set("", ""))
|
||||
|
||||
def test_empty_set(self):
|
||||
self.assertFalse(self.in_set("", "a-1.0.tar.gz"))
|
||||
|
||||
def test_whole_names_only(self):
|
||||
listing = "distfiles/a-1.0.tar.gz.part\ndistfiles/xa-1.0.tar.gz\ndistfiles/aX1.0.tar.gz\na-1.0.tar.gz\n"
|
||||
for name in ("a-1.0.tar.gz", "a.1.0.tar.gz", "a-1.0"):
|
||||
self.assertFalse(self.in_set(listing, name), name)
|
||||
|
||||
def test_glob_characters_are_not_expanded(self):
|
||||
open(os.path.join(self.tmp, "a-1.0.tar.gz"), "w").close()
|
||||
self.assertFalse(self.in_set(self.LISTING, "*.tar.gz"))
|
||||
self.assertTrue(self.in_set("distfiles/*.tar.gz\n", "*.tar.gz"))
|
||||
|
||||
def test_make_failure_means_missing(self):
|
||||
self.assertFalse(self.in_set(self.LISTING, "", port="cat/unknown"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue