packages: Make create-sets.sh more robust during release

Commit d1c176fedf made create-sets.sh exit when it encounters an
error, instead of creating an empty repository.  However, this turns
out to cause some issues:

1. A package not having any sets is considered an error, but during
   the release build, we stuff a 'pkg' package into the repository
   which doesn't have any sets, which causes a failure.  Avoid this
   by simply ignoring the pkg package.

2. No error was printed in this case, which made the problem hard
   to diagnose.  Add an explicit error message.

3. A similar problem occurred running on a repository which already
   contained sets, which is not usually done during the build, but
   is not necessarly an inappropriate thing to do.  Fix this one by
   ignoring set packages when looking for sets.

While here, fix another issue that might cause packages to be wrongly
skipped if the path to the repository contains a '-' character, since
we didn't strip the path before testing the package name.

PR:	294966
Fixes:	d1c176fedf ("packages: Make create-sets.sh more robust")
MFC after:	2 weeks
Reported by:	Alastair Hogge <agh@riseup.net>
Reviewed by:	emaste
Sponsored by:	https://www.patreon.com/bsdivy
Differential Revision:	https://reviews.freebsd.org/D56792
This commit is contained in:
Lexi Winter
2026-05-05 01:31:20 +01:00
parent 03e9e83f35
commit 8e8d878562
+48 -4
View File
@@ -35,17 +35,61 @@ repodir="$1"; shift
# generate-set-ucl.lua. # generate-set-ucl.lua.
UCL_VARS="$@" UCL_VARS="$@"
# Extract PKG_NAME_PREFIX so we can use it later.
PKG_NAME_PREFIX=""
set -- $UCL_VARS
while [ -n "$1" ]; do
case "$1" in
PKG_NAME_PREFIX)
shift
PKG_NAME_PREFIX="$1"
break;;
*)
shift; shift;;
esac
done
if [ -z "$PKG_NAME_PREFIX" ]; then
printf >&2 '%s: PKG_NAME_PREFIX must be specified\n' "$0"
exit 1
fi
# Nothing is explicitly added to set-base, so it wouldn't get built unless # Nothing is explicitly added to set-base, so it wouldn't get built unless
# we list it here. # we list it here.
SETS="base base-dbg base-jail base-jail-dbg" SETS="base base-dbg base-jail base-jail-dbg"
for pkg in "$repodir"/*.pkg; do for pkg in "$repodir"/*.pkg; do
# If the package name doesn't containing a '-', then it's # Check if we should process this package.
# probably data.pkg or packagesite.pkg, which are not real case "${pkg##*/}" in
# packages.
{ echo "$pkg" | grep -q '-'; } || continue
# When building release, we add a 'pkg' package to the repository,
# but this isn't a base package and doesn't have a set. To avoid
# this causing an error, skip it.
pkg-*) continue;;
# Any existing set packages may also have no sets (and even if they
# do, they shouldn't be included here).
${PKG_NAME_PREFIX}-set-*)
continue;;
# If the package name contains a '-', process it. All "real"
# packages contain a '-', because the package filename format
# is <pkgname>-<version>.pkg, so this skips files which aren't
# really packages, like data.pkg or packagesite.pkg.
#
*-*) ;;
*) continue;;
esac
# Print a useful error message instead of failing silently if
# grep doesn't find any sets here.
set +e
_tmp="$(${PKG_CMD} query -F "$pkg" '%At %n %Av' | grep '^set ')" _tmp="$(${PKG_CMD} query -F "$pkg" '%At %n %Av' | grep '^set ')"
if [ -z "$_tmp" ]; then
printf >&2 '%s: package has no sets: %s\n' "$0" "$pkg"
exit 1
fi
set -e
set -- $_tmp set -- $_tmp
pkgname="$2" pkgname="$2"
sets="$(echo "$3" | tr , ' ')" sets="$(echo "$3" | tr , ' ')"