git: 227980df3979 - stable/13 - pkgbase: accommodate pkg < 1.17

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Tue, 10 Oct 2023 13:36:31 UTC
The branch stable/13 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=227980df397969bd844aa582ef248909651bebb0

commit 227980df397969bd844aa582ef248909651bebb0
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2021-07-27 16:44:45 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2023-10-10 13:36:10 +0000

    pkgbase: accommodate pkg < 1.17
    
    6cafdee71d2b adapted the pkgbase build for 1.17, but broke Cirrus-CI's
    use of PKG_FORMAT=tar (the quarterly package set still has pkg 1.16).
    Because of this I disabled the pkgbase build and test in 2bfba2a04b05.
    
    Now, check `pkg --version` and use the old logic for < 1.17.
    
    To be reverted once we no longer encounter pkg 1.16 in Cirrus-CI (i.e.,
    via GCP cloud images) to avoid keeping this extra complexity around.
    
    PR:             257422
    Reviewed by:    manu
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D31324
    
    (cherry picked from commit 4e224e4be7c37052567ec4cd2481f299487fc222)
    (cherry picked from commit 4dbac528db6040694cd57c42a64e036daa91db86)
    (cherry picked from commit 54247ce1f96f04d16f1429007bac3607c8a0a39e)
---
 Makefile.inc1 | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/Makefile.inc1 b/Makefile.inc1
index e0f5d9cae72d..d648be2f3064 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -1907,9 +1907,16 @@ _pkgbootstrap: .PHONY
 	@env ASSUME_ALWAYS_YES=YES pkg bootstrap
 .endif
 
-.if make(create-world-packages-jobs) || make(create-kernel-packages*) || make(real-update-packages)
+.if make(create-world-packages-jobs) || make(create-kernel-packages*) || make(real-update-packages) || make(sign-packages)
 PKG_ABI!=${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI
 .endif
+PKG_BIN_VERSION!=${PKG_CMD} --version </dev/null 2>/dev/null |\
+    awk -F. '/^[0-9.]+$$/ {print $$1 * 10000 + $$2 * 100 + $$3}'
+.if ${PKG_BIN_VERSION} < 11700
+PKG_EXT=	${PKG_FORMAT}
+.else
+PKG_EXT=	pkg
+.endif
 
 .if !defined(PKG_VERSION_FROM) && make(real-update-packages)
 .if defined(PKG_ABI)
@@ -1949,14 +1956,14 @@ real-update-packages: stage-packages .PHONY
 	@echo "==> Checking for new packages (comparing ${PKG_VERSION} to ${PKG_VERSION_FROM})"
 	@for pkg in ${PKG_VERSION_FROM_DIR}/${PKG_NAME_PREFIX}-*; do \
 	  pkgname=$$(pkg query -F $${pkg} '%n' | sed 's/${PKG_NAME_PREFIX}-\(.*\)/\1/') ; \
-	  newpkgname=${PKG_NAME_PREFIX}-$${pkgname}-${PKG_VERSION}.pkg ; \
+	  newpkgname=${PKG_NAME_PREFIX}-$${pkgname}-${PKG_VERSION}.${PKG_EXT} ; \
 	  oldsum=$$(pkg query -F $${pkg} '%X') ; \
 	  if [ ! -f ${REPODIR}/${PKG_ABI}/${PKG_VERSION}/$${newpkgname} ]; then \
 	    continue; \
 	  fi ; \
 	  newsum=$$(pkg query -F ${REPODIR}/${PKG_ABI}/${PKG_VERSION}/$${newpkgname} '%X') ; \
 	  if [ "$${oldsum}" == "$${newsum}" ]; then \
-	   echo "==> Keeping old ${PKG_NAME_PREFIX}-$${pkgname}-${PKG_VERSION_FROM}.pkg" ; \
+	   echo "==> Keeping old ${PKG_NAME_PREFIX}-$${pkgname}-${PKG_VERSION_FROM}.${PKG_EXT}" ; \
 	   rm ${REPODIR}/${PKG_ABI}/${PKG_VERSION}/$${newpkgname} ; \
 	   cp $${pkg} ${REPODIR}/${PKG_ABI}/${PKG_VERSION} ; \
 	  else \
@@ -2114,6 +2121,9 @@ create-kernel-packages-extra-flavor${flavor:C,^""$,${_default_flavor},}-${_kerne
 
 sign-packages:	_pkgbootstrap .PHONY
 	printf "version = 2;\n" > ${WSTAGEDIR}/meta
+.if ${PKG_BIN_VERSION} < 11700
+	printf "packing_format = \"${PKG_FORMAT}\";\n" >> ${WSTAGEDIR}/meta
+.endif
 	@[ -L "${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/latest" ] && \
 		unlink ${REPODIR}/$$(${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname config ABI)/latest ; \
 	${PKG_CMD} -o ABI_FILE=${WSTAGEDIR}/usr/bin/uname repo \