Subject: pkg/30954: bin-install builds from source unnecessarily because PKGNAME_REQD ignored
To: None <pkg-manager@netbsd.org, gnats-admin@netbsd.org,>
From: None <nbgnats@anastigmatix.net>
List: pkgsrc-bugs
Date: 08/09/2005 22:49:00
>Number:         30954
>Category:       pkg
>Synopsis:       bin-install builds from source unnecessarily because PKGNAME_REQD ignored
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 09 22:49:00 +0000 2005
>Originator:     Chapman Flack
>Release:        2.0.0 (irrelevant to issue)
>Organization:
>Environment:
NetBSD lundestad.anastigmatix.net 2.0 NetBSD 2.0 (lundestad) #11: Sat Mar  5 14:01:49 EST 2005  xxx@xxx:/usr/src/sys/arch/i386/compile/lundestad i386 (irrelevant to issue)
>Description:
This issue is masked by pkg/30928 (bin-install always builds dependency from
source no matter what). Once that is fixed, bin-install still builds some
dependencies from source unnecessarily--that's this issue.

The problem arises when foo depends on bar (DEPENDS+= bar>=1.2nb2:../../baz/bar)
and the Makefile in baz/bar now advertises version 1.2nb3, which doesn't yet
have a binary package available, but 1.2nb2 is available and would suffice. In
bsd.pkg.mk there is a variable PKGNAME_REQD, which contains exactly the
information needed to solve this problem: when install-depends recursively makes
DEPENDS_TARGET to install a dependency, PKGNAME_REQD is set to the exact pkg
name, including version wildcard pattern, for the dependency package needed.

However, though PKGNAME_REQD is set for the recursive call, it is never used by
bin-install. The CVS log for 1.904 suggests it was intended for just this
purpose. It is easy to complete. It does not change any behavior when
bin-install is invoked directly (always build the current version if it is not
available packaged), only when it is invoked for a dependency and PKGNAME_REQD
is defined to indicate the acceptable versions:

(Note: the PR query CGI seems to double blank lines; if you cut and paste
this patch and it is unusable, try undoubling the blank lines.)

--- /tmp/bsd.pkg.mk	2005-08-09 14:32:15.000000000 -0500
+++ /tmp/bsd.pkg.mk	2005-08-09 17:22:29.000000000 -0500
@@ -3494,8 +3494,8 @@
 		for site in ${BINPKG_SITES} ; do 			\
 			${ECHO} Trying `eval ${ECHO} $$site`/All ; 	\
 			${SHCOMMENT} ${ECHO} ${SETENV} PKG_PATH="`eval ${ECHO} $$site`/All" ${PKG_ADD} ${_BIN_INSTALL_FLAGS} ${PKGNAME}${PKG_SUFX} ; \
-			if ${SETENV} PKG_PATH="`eval ${ECHO} $$site`/All" ${PKG_ADD} ${BIN_INSTALL_FLAGS} ${PKGNAME}${PKG_SUFX} ; then \
-				${ECHO} "${PKGNAME} successfully installed."; \
+			if ${SETENV} PKG_PATH="`eval ${ECHO} $$site`/All" ${PKG_ADD} ${BIN_INSTALL_FLAGS} ${PKGNAME_REQD:U${PKGNAME}:Q}${PKG_SUFX} ; then \
+				${ECHO} "`${PKG_INFO} -e ${PKGNAME_REQD:U${PKGNAME}:Q}` successfully installed."; \
 				break ; 				\
 			fi ; 						\
 		done ; 							\
@@ -3510,7 +3510,7 @@
 
 .PHONY: bin-install
 bin-install:
-	@${ECHO_MSG} "${_PKGSRC_IN}> Binary install for ${PKGNAME}"
+	@${ECHO_MSG} "${_PKGSRC_IN}> Binary install for ${PKGNAME_REQD:U${PKGNAME}:Q}"
 	${_PKG_SILENT}${_PKG_DEBUG}					\
 	realtarget="real-su-bin-install";				\
 	action="binary install";					\


However, this should really be fixed after pkg/30929, in which case the patch
would look like this:

--- /tmp/bsd.pkg.mk	2005-08-09 14:49:01.000000000 -0500
+++ /tmp/bsd.pkg.mk	2005-08-09 17:39:17.000000000 -0500
@@ -3493,8 +3493,8 @@
 	pkgpath=${PKGREPOSITORY:Q} ; \
 	for i in ${BINPKG_SITES} ; do pkgpath="$$pkgpath;$$i/All" ; done ; \
 	${ECHO} "Trying $$pkgpath" ; 	\
-	if ${SETENV} PKG_PATH="$$pkgpath" ${PKG_ADD} ${BIN_INSTALL_FLAGS} ${PKGNAME}${PKG_SUFX} ; then \
-		${ECHO} ${PKGNAME} successfully installed.; \
+	if ${SETENV} PKG_PATH="$$pkgpath" ${PKG_ADD} ${BIN_INSTALL_FLAGS} ${PKGNAME_REQD:U${PKGNAME}:Q}${PKG_SUFX} ; then \
+		${ECHO} "`${PKG_INFO} -e ${PKGNAME_REQD:U${PKGNAME}:Q}` successfully installed."; \
   	else 				 				\
 		${SHCOMMENT} Cycle through some FTP server here ;\
 		${ECHO_MSG} "Installing from source" ;		\
@@ -3505,7 +3505,7 @@
 
 .PHONY: bin-install
 bin-install:
-	@${ECHO_MSG} "${_PKGSRC_IN}> Binary install for ${PKGNAME}"
+	@${ECHO_MSG} "${_PKGSRC_IN}> Binary install for ${PKGNAME_REQD:U${PKGNAME}:Q}"
 	${_PKG_SILENT}${_PKG_DEBUG}					\
 	realtarget="real-su-bin-install";				\
 	action="binary install";					\

>How-To-Repeat:
Masked by pkg/30928. Once that is fixed, bin-install a package foo that
depends on bar>=1.2.2:baz/bar where the current baz/bar Makefile advertises version 1.2.3, no 1.2.3 package is available but a 1.2.2 package is. Available 1.2.2 package is spurned and 1.2.3 is built from source.
>Fix:
patch given above in full description.