Subject: Re: pkg/24188: A utility for removing leaf packages
To: Daniel Carosone <dan@geek.com.au>
From: Greg A. Woods <woods@weird.com>
List: netbsd-bugs
Date: 01/24/2004 00:00:11
[ On Saturday, January 24, 2004 at 07:33:31 (+1100), Daniel Carosone wrote: ]
> Subject: Re: pkg/24188: A utility for removing leaf packages
>
> On Fri, Jan 23, 2004 at 03:42:53AM -0500, Greg A. Woods wrote:
> > Try using "pkg_delete -R" when you remove packages that may depend on
> > other packages.
> 
> Almost - it works fine for recorded dependencies, but there are also
> build dependencies (stuff like libtool or gmake) that sometimes you
> don't want hanging around.

Hmmm.... I suppose.  It seems kinda silly to me to be wanting to delete
any of those kinds of tools -- they'll be needed next time the package
is updated anyway.

I also use the following changes (which may or may not be complete, but
what I show here should give you some idea what I'm talking about) to
make sure that non-critically out-of-date build-only dependencies are
warned about (which is far more important to me since I use static
builds almost universally and so my binary packages don't have many
run-time dependencies at all):

@@ -4055,6 +4306,32 @@
 # Dependency checking
 ################################################################
 
+_QUOTED_BUILD_DEPENDS=
+.for dep in ${BUILD_DEPENDS}
+_QUOTED_BUILD_DEPENDS+=	${dep:Q}
+.endfor
+
+.PHONY: show-install-depends
+.if !target(show-install-depends)
+show-install-depends:
+. if defined(DEPENDS) || defined(BUILD_DEPENDS)
+.  if defined(NO_DEPENDS)
+	@${DO_NADA}
+.  else # !NO_DEPENDS
+.   for dep in ${DEPENDS} ${BUILD_DEPENDS}
+	${_PKG_SILENT}${_PKG_DEBUG}					\
+	pkg_type="runtime";						\
+	for bpkg in ${_QUOTED_BUILD_DEPENDS} ; do			\
+		if [ '${dep}' = "$${bpkg}" ] ; then			\
+			pkg_type="build-only";				\
+		fi;							\
+	done;								\
+	${ECHO_MSG} "=====> $${pkg_type} :	'${dep}'"
+.   endfor
+.  endif # NO_DEPENDS
+. endif # DEPENDS || BUILD_DEPENDS
+.endif # target
+
 .PHONY: install-depends
 .if !target(install-depends)
 # Tells whether to halt execution if the object formats differ
@@ -4071,10 +4348,16 @@
 	pkg="${dep:C/:.*//}";						\
 	dir="${dep:C/[^:]*://:C/:.*$//}";				\
 	found=`${PKG_BEST_EXISTS} "$$pkg" || ${TRUE}`;			\
+	pkgname=`cd $$dir && ${MAKE} ${MAKEFLAGS} show-var VARNAME=PKGNAME`; \
+	pkg_type="runtime";						\
+	for bpkg in ${_QUOTED_BUILD_DEPENDS} ; do			\
+		if [ '${dep}' = "$${bpkg}" ] ; then			\
+			pkg_type="build-only";				\
+		fi;							\
+	done;								\
 	if [ "X$$REBUILD_DOWNLEVEL_DEPENDS" != "X" ]; then		\
-		pkgname=`cd $$dir ; ${MAKE} ${MAKEFLAGS} show-var VARNAME=PKGNAME`; \
 		if [ "X$$found" != "X" -a "X$$found" != "X$${pkgname}" ]; then \
-			${ECHO_MSG} "ignoring old installed package \"$$found\""; \
+			${ECHO_MSG} "NOTICE:  ignoring old installed $${pkg_type} package \"$$found\"";	\
 			found="";					\
 		fi;							\
 	fi;								\
@@ -4092,15 +4375,37 @@
 				exit 1;					\
 			fi;						\
 		fi;							\
-		${ECHO_MSG} "${_PKGSRC_IN}> Required installed package $$pkg: $${found} found"; \
+		if [ `${ECHO} $$found | ${WC} -w` -gt 1 ]; then	\
+			${ECHO} '***' "WARNING:  Dependency on '$$pkg' expands to several installed packages " ; \
+			${ECHO} "    (" `${ECHO} $$found` ")." ; 	\
+			${ECHO} "    Please check if this is really intended!" ; \
+			sleep 2 ;					\
+		else 							\
+			if [ "X$$found" != "X" -a "X$$found" != "X$${pkgname}" ]; then \
+				case "${ALLOW_DOWNLEVEL_DEPENDS}" in	\
+				[Nn][Oo])				\
+					${ECHO_MSG} "${_PKGSRC_IN}==> ERROR:  $$found needs upgrade -> $$pkgname" ; \
+					exit 1 ;			\
+					;;				\
+				*)					\
+					${ECHO_MSG} "${_PKGSRC_IN}==> WARNING:  $$found should be upgraded -> $$pkgname" ; \
+					;;				\
+				esac ; 					\
+			fi ; 						\
+			${ECHO_MSG} "${_PKGSRC_IN}> Required $${pkg_type} package $${found} installed OK (need $${pkg})"; \
+		fi ; 							\
 	else								\
-		${ECHO_MSG} "${_PKGSRC_IN}> Required package $$pkg: NOT found"; \
+		${ECHO_MSG} "${_PKGSRC_IN}> Required $${pkg_type} package NOT found: $${pkg}"; \
 		target=${DEPENDS_TARGET};				\
-		${ECHO_MSG} "${_PKGSRC_IN}> Verifying $$target for $$dir"; 	\
+		${ECHO_MSG} "${_PKGSRC_IN}> Attempting '$${target}' for $${pkg} in $${dir}"; \
 		if [ ! -d $$dir ]; then					\
-			${ECHO_MSG} "=> No directory for $$dir.  Skipping.."; \
+			${ECHO_MSG} "=> No directory '$${dir}' for $${pkg}.  Skipping...."; \
 		else							\
 			cd $$dir ;					\
+			if [ -f ${EXTRACT_COOKIE} ]; then		\
+				${ECHO_MSG} "${_PKGSRC_IN}> WARNING!!!  Starting with unclean work directory for $${target}"; \
+				sleep 2 ;				\
+			fi ;						\
 			${SETENV} _PKGSRC_DEPS=", ${PKGNAME}${_PKGSRC_DEPS}" ${MAKE} ${MAKEFLAGS} $$target PKGNAME_REQD=\'$$pkg\'; \
 			${ECHO_MSG} "${_PKGSRC_IN}> Returning to build of ${PKGNAME}"; \
 		fi;							\

> There's also the case of pkgs that were
> dependencies for earlier versions of this pkg, but no more, and which
> didn't get cleaned out by "make update".

I had the impression "make update" used "pkg_delete -R" and so would in
fact clean up old dependencies that were no longer dependencies
(provided it was used consistenly), but since I've only read about it in
bsd.pkgs.mk, I may not have got that right.  Hmmm... no, that's
something I was hacking on myself but I didn't go to far with it because
I never use "make update" and I only use it now for meta-packages (such
as libtool):

-DEINSTALLDEPENDS?=	NO	# add -R to pkg_delete
+DEINSTALLDEPENDS?=	NO	# pass -r -R to pkg_delete if "ALL", else -R if "DEPENDS", else pass -r if defined

@@ -3345,12 +3594,15 @@
 	${_SU_TARGET}
 
 .  if (${DEINSTALLDEPENDS} != "NO")
-.    if (${DEINSTALLDEPENDS} != "ALL")
+.    if (${DEINSTALLDEPENDS} == "ALL")
+# used for "update" target to remove all the packages that depend on this one
+real-su-deinstall-flags+=	-r
+.    elif (${DEINSTALLDEPENDS} == "DEPENDS")
+# used by meta packages to remove all their dependents
+real-su-deinstall-flags+=	-R
+.    else
 # used for removing stuff in bulk builds
 real-su-deinstall-flags+=	-r -R
-# used for "update" target
-.    else
-real-su-deinstall-flags+=	-r
 .    endif
 .  endif
 .  ifdef PKG_VERBOSE

-- 
						Greg A. Woods

+1 416 218-0098                  VE3TCP            RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>          Secrets of the Weird <woods@weird.com>