packages: Don't create empty packages

If a package plist only contains directories, but no files, do not
create the package.

This fixes an issue where setting "package=foo" in mtree causes the
"foo" package to always be created, even if nothing else installs in
that package, because the mtree entry is always added to the plist.

This most often happens:

* With architecture-specific directories, because mtree can't install
  a directory conditionally based on architecture, and

* With packages that are completely empty when a particular src.conf
  knob is disabled, because mtree will still create the directories.

Although it's theoretically possible that we might want to create a
package that only contains directories, there are no such packages
today.

MFC after:	2 weeks (stable/15 only)
Reviewed by:	manu, des
Differential Revision:	https://reviews.freebsd.org/D55412
Sponsored by:	https://www.patreon.com/bsdivy
This commit is contained in:
Lexi Winter
2026-02-21 20:19:42 +00:00
parent fa77660a3c
commit 7965c93e4d
+18 -11
View File
@@ -2272,17 +2272,24 @@ create-world-packages-jobs: create-world-package-${pkgname}
create-world-package-${pkgname}: .PHONY
@sh ${SRCDIR}/release/packages/generate-ucl.sh -o ${pkgname} \
-s ${SRCDIR} -u ${WSTAGEDIR}/${pkgname}.ucl
@awk -F\" ' \
/^name/ { printf("===> Creating %s-", $$2); next } \
/^version/ { print $$2; next } \
' ${WSTAGEDIR}/${pkgname}.ucl
${PKG_CMD} -o ABI=${PKG_ABI} -o ALLOW_BASE_SHLIBS=yes \
-o OSVERSION="${SRCRELDATE}" \
create -f ${PKG_FORMAT} ${PKG_CLEVEL} -T${PKG_CTHREADS} \
-M ${WSTAGEDIR}/${pkgname}.ucl \
-p ${WSTAGEDIR}/${pkgname}.plist \
-r ${WSTAGEDIR} \
-o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}
@if [ "$$(grep -vc '^@dir' ${WSTAGEDIR}/${pkgname}.plist)" -gt 0 ]; then \
awk -F\" ' \
/^name/ { printf("===> Creating %s-", $$2); next } \
/^version/ { print $$2; next } \
' ${WSTAGEDIR}/${pkgname}.ucl && \
${PKG_CMD} -o ABI=${PKG_ABI} -o ALLOW_BASE_SHLIBS=yes \
-o OSVERSION="${SRCRELDATE}" \
create -f ${PKG_FORMAT} ${PKG_CLEVEL} -T${PKG_CTHREADS} \
-M ${WSTAGEDIR}/${pkgname}.ucl \
-p ${WSTAGEDIR}/${pkgname}.plist \
-r ${WSTAGEDIR} \
-o ${REPODIR}/${PKG_ABI}/${PKG_OUTPUT_DIR}; \
else \
awk -F\" ' \
/^name/ { printf("===> Skipping %s-", $$2); next } \
/^version/ { print $$2; next } \
' ${WSTAGEDIR}/${pkgname}.ucl; \
fi
.endfor
create-sets-packages-jobs: .PHONY create-sets-packages