Bug 36237 - registering _real_ dependencies in bsd.port.mk
Summary: registering _real_ dependencies in bsd.port.mk
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Port Management Team
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-03-23 19:10 UTC by Mikhail T.
Modified: 2002-09-19 01:20 UTC (History)
1 user (show)

See Also:


Attachments
file.diff (1.40 KB, patch)
2002-03-23 19:10 UTC, Mikhail T.
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mikhail T. 2002-03-23 19:10:00 UTC
	The existing bsd.port.mk is fundamentally wrong in how it
	determines the packages, that the port/package being installed
	depends on. (Which is why this PR is filed as a sw-bug.)

	The packages actually installed at the build-time should be
	registered instead of those, that _would have been installed
	if none were present_. For example, if I build/install the
	libxml2 and libxsl with out PYTHON support, the actual installed
	packages on my system will be known as

		libxslt-nopython-1.0.12
		libxml2-nopython-2.4.16

	However, all of the ports that depend on libxml2 and libxslt
	will now to try register their dependency on

		libxslt-1.0.13
		libxml2-2.4.17

	(Note, that the version is different too).

Fix: Since forever, the pkg_info(1)'s -W option was available
	to find the port/package, which installed a particular file.
	Since Feb 4, the bin/34628

		http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/34628

	is there with a patch to make that option stronger by
	considering the recorded md5 checksum if multiple packages claim
	the same file.

	The patch below makes use of the pkg_info's ability and lists
	the actually installed ports/packages, that a port depends on.

	The old version of package-depends is renamed to package-depends-old
	as it may still have its uses for determining, which packages
	this one is going to depend on _by default_. Perhaps,
	package-depends-default is a better name for it...

	This patch is a slightly improved version of what was sent
	privately to will (as the prominent Portmgr member and someone,
	who, actually, expressed a desire to see something like this
	implemented) and knu -- another ports committer who has in the
	past expressed concern about the bsd.port.mk brokennes with respect
	to package dependecies registration.

	The handling of LIB_dependencies in it mirror the improvement
	proposed in ports/34126

		http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/34126

	but don't require that patch to be committed first.
How-To-Repeat: 
	See description.
Comment 1 Patrick Li freebsd_committer freebsd_triage 2002-03-23 22:11:17 UTC
Responsible Changed
From-To: freebsd-ports->portmgr

Over to maintainers
Comment 2 Mikhail T. 2002-03-27 06:19:53 UTC
This is an updated patch. It merges with the Sobomax' recent updates
to the bsd.port.mk and fixes a show-stopper bug in the original patch
-- the pkg_info was invoked after the new port's /var/db/pkg/<PACKAGE>
subdirectory was created, the /var/db/pkg/<PACKAGE>/+CONTENTS was
created.

This new version looks for the dependencies first, filters out those on
the PKG_IGNORE_DEPENDS list, caches the value, and only then creates the
new subdirectory...

	-mi

P.S. It is nice to see such a lively discussion of a proposed change,
which at least one of the PortMgr members have recently explicitly
requested.

Index: bsd.port.mk
===================================================================
RCS file: /home/ncvs/ports/Mk/bsd.port.mk,v
retrieving revision 1.404
diff -U2 -r1.404 bsd.port.mk
--- bsd.port.mk	27 Mar 2002 04:26:44 -0000	1.404
+++ bsd.port.mk	27 Mar 2002 06:17:47 -0000
@@ -1225,5 +1225,6 @@
 PKG_INFO?=		/usr/sbin/pkg_info
 .if !defined(PKG_ARGS)
-PKG_ARGS=		-v -c ${COMMENT} -d ${DESCR} -f ${TMPPLIST} -p ${PREFIX} -P "`${MAKE} package-depends | ${GREP} -v -E ${PKG_IGNORE_DEPENDS} | sort -u`" ${EXTRA_PKG_ARGS}
+PKG_ARGS=	-v -c ${COMMENT} -d ${DESCR} -f ${TMPPLIST} -p ${PREFIX} \
+		${EXTRA_PKG_ARGS}
 .if exists(${PKGINSTALL})
 PKG_ARGS+=		-i ${PKGINSTALL}
@@ -2310,5 +2311,7 @@
 	fi
 	@__softMAKEFLAGS='${__softMAKEFLAGS:S/'/'\''/g}'; \
-	if ${PKG_CMD} ${PKG_ARGS} ${PKGFILE}; then \
+	if ${PKG_CMD} -P "`${MAKE} package-depends | \
+			${GREP} -v -E ${PKG_IGNORE_DEPENDS}`" \
+			${PKG_ARGS} ${PKGFILE}; then \
 		if [ -d ${PACKAGES} ]; then \
 			eval ${MAKE} $${__softMAKEFLAGS} package-links; \
@@ -3157,7 +3160,36 @@
 # Print out package names.
 
-package-depends:
+package-depends-old:
 	@${PACKAGE-DEPENDS-LIST} | ${AWK} '{print $$1}'
 
+package-depends:
+# For LIB_DEPENDS allow the library to be specified as a regexp, and use
+# ldconfig to fine it -- see lib-depends. With RUN_DEPENDS, life is
+# easier, since pkg_info will invoke which(1) for us by itself and we
+# do not (yet?) want to be able to use regexps in RUN_DEPENDS.
+	if ! [ -z "${LIB_DEPENDS}" ]; \
+	then \
+		for i in ${LIB_DEPENDS}; do \
+			lib=$${i%%:*}; \
+			case $$lib in \
+				*.*.*)	pattern=$$lib ;;\
+				*.*)	pattern="$${lib%%.*}\.$${lib#*.}" ;;\
+				*)		pattern=$$lib ;;\
+			esac; \
+			search=$${search}`${LDCONFIG} -r | awk "\
+				/-l$$pattern[^ \t]* =>/ {\
+					print \" -W \" \\$$NF \
+				} \
+			"`; \
+		done; \
+	fi; \
+	search="$${search}${RUN_DEPENDS:C,([^:]+):[^ ]*, -W \1,g}"; \
+	if ! [ -z "$$search" ]; \
+	then \
+		${PKG_INFO} $$search | awk '\
+			/was installed by package/ { P[$$NF] = 1 } \
+			END { for (p in P) print p }'; \
+	fi
+
 ################################################################
 # Everything after here are internal targets and really
@@ -3375,8 +3407,20 @@
 	@${RM} -rf ${PKG_DBDIR}/${PKGNAME}
 .endif
-	@if [ ! -d ${PKG_DBDIR}/${PKGNAME} ]; then \
+	if [ ! -d ${PKG_DBDIR}/${PKGNAME} ]; then \
 		${ECHO_MSG} "===>   Registering installation for ${PKGNAME}"; \
+		deps=`cd ${.CURDIR} && ${MAKE} \
+			${__softMAKEFLAGS} package-depends ECHO_MSG=${TRUE} \
+			| ${GREP} -v -E ${PKG_IGNORE_DEPENDS}`; \
+		for dep in $$deps; do \
+			if [ -d ${PKG_DBDIR}/$$dep ]; then \
+				if ! ${GREP} ^${PKGNAME}$$ ${PKG_DBDIR}/$$dep/+REQUIRED_BY \
+					>/dev/null 2>&1; then \
+					${ECHO} ${PKGNAME} >> ${PKG_DBDIR}/$$dep/+REQUIRED_BY; \
+				fi; \
+			fi; \
+		done; \
 		${MKDIR} ${PKG_DBDIR}/${PKGNAME}; \
-		${PKG_CMD} ${PKG_ARGS} -O ${PKGFILE} > ${PKG_DBDIR}/${PKGNAME}/+CONTENTS; \
+		${PKG_CMD} -P "$$deps" ${PKG_ARGS} -O ${PKGFILE} \
+			> ${PKG_DBDIR}/${PKGNAME}/+CONTENTS; \
 		${CP} ${DESCR} ${PKG_DBDIR}/${PKGNAME}/+DESC; \
 		${CP} ${COMMENT} ${PKG_DBDIR}/${PKGNAME}/+COMMENT; \
@@ -3393,12 +3437,4 @@
 			${CP} ${PKGMESSAGE} ${PKG_DBDIR}/${PKGNAME}/+DISPLAY; \
 		fi; \
-		for dep in `cd ${.CURDIR} && ${MAKE} ${__softMAKEFLAGS} package-depends ECHO_MSG=${TRUE} | sort -u`; do \
-			if [ -d ${PKG_DBDIR}/$$dep -a -z `echo $$dep | ${GREP} -E ${PKG_IGNORE_DEPENDS}` ]; then \
-				if ! ${GREP} ^${PKGNAME}$$ ${PKG_DBDIR}/$$dep/+REQUIRED_BY \
-					>/dev/null 2>&1; then \
-					${ECHO} ${PKGNAME} >> ${PKG_DBDIR}/$$dep/+REQUIRED_BY; \
-				fi; \
-			fi; \
-		done; \
 	fi
 	@if [ -e /tmp/${PKGNAME}-required-by ]; then \
Comment 3 Mikhail T. 2002-03-27 07:53:40 UTC
One more attempt... Forgot to put back the silencing ``@'' signs
removed while debugging...

	-mi

Index: bsd.port.mk
===================================================================
RCS file: /home/ncvs/ports/Mk/bsd.port.mk,v
retrieving revision 1.404
diff -U2 -r1.404 bsd.port.mk
--- bsd.port.mk	27 Mar 2002 04:26:44 -0000	1.404
+++ bsd.port.mk	27 Mar 2002 07:52:50 -0000
@@ -1225,5 +1225,6 @@
 PKG_INFO?=		/usr/sbin/pkg_info
 .if !defined(PKG_ARGS)
-PKG_ARGS=		-v -c ${COMMENT} -d ${DESCR} -f ${TMPPLIST} -p ${PREFIX} -P "`${MAKE} package-depends | ${GREP} -v -E ${PKG_IGNORE_DEPENDS} | sort -u`" ${EXTRA_PKG_ARGS}
+PKG_ARGS=	-v -c ${COMMENT} -d ${DESCR} -f ${TMPPLIST} -p ${PREFIX} \
+		${EXTRA_PKG_ARGS}
 .if exists(${PKGINSTALL})
 PKG_ARGS+=		-i ${PKGINSTALL}
@@ -2310,5 +2311,7 @@
 	fi
 	@__softMAKEFLAGS='${__softMAKEFLAGS:S/'/'\''/g}'; \
-	if ${PKG_CMD} ${PKG_ARGS} ${PKGFILE}; then \
+	if ${PKG_CMD} -P "`${MAKE} package-depends | \
+			${GREP} -v -E ${PKG_IGNORE_DEPENDS}`" \
+			${PKG_ARGS} ${PKGFILE}; then \
 		if [ -d ${PACKAGES} ]; then \
 			eval ${MAKE} $${__softMAKEFLAGS} package-links; \
@@ -3157,7 +3160,36 @@
 # Print out package names.
 
-package-depends:
+package-depends-old:
 	@${PACKAGE-DEPENDS-LIST} | ${AWK} '{print $$1}'
 
+package-depends:
+# For LIB_DEPENDS allow the library to be specified as a regexp, and use
+# ldconfig to fine it -- see lib-depends. With RUN_DEPENDS, life is
+# easier, since pkg_info will invoke which(1) for us by itself and we
+# do not (yet?) want to be able to use regexps in RUN_DEPENDS.
+	@if ! [ -z "${LIB_DEPENDS}" ]; \
+	then \
+		for i in ${LIB_DEPENDS}; do \
+			lib=$${i%%:*}; \
+			case $$lib in \
+				*.*.*)	pattern=$$lib ;;\
+				*.*)	pattern="$${lib%%.*}\.$${lib#*.}" ;;\
+				*)		pattern=$$lib ;;\
+			esac; \
+			search=$${search}`${LDCONFIG} -r | awk "\
+				/-l$$pattern[^ \t]* =>/ {\
+					print \" -W \" \\$$NF \
+				} \
+			"`; \
+		done; \
+	fi; \
+	search="$${search}${RUN_DEPENDS:C,([^:]+):[^ ]*, -W \1,g}"; \
+	if ! [ -z "$$search" ]; \
+	then \
+		${PKG_INFO} $$search | awk '\
+			/was installed by package/ { P[$$NF] = 1 } \
+			END { for (p in P) print p }'; \
+	fi
+
 ################################################################
 # Everything after here are internal targets and really
@@ -3377,6 +3409,18 @@
 	@if [ ! -d ${PKG_DBDIR}/${PKGNAME} ]; then \
 		${ECHO_MSG} "===>   Registering installation for ${PKGNAME}"; \
+		deps=`cd ${.CURDIR} && ${MAKE} \
+			${__softMAKEFLAGS} package-depends ECHO_MSG=${TRUE} \
+			| ${GREP} -v -E ${PKG_IGNORE_DEPENDS}`; \
+		for dep in $$deps; do \
+			if [ -d ${PKG_DBDIR}/$$dep ]; then \
+				if ! ${GREP} ^${PKGNAME}$$ ${PKG_DBDIR}/$$dep/+REQUIRED_BY \
+					>/dev/null 2>&1; then \
+					${ECHO} ${PKGNAME} >> ${PKG_DBDIR}/$$dep/+REQUIRED_BY; \
+				fi; \
+			fi; \
+		done; \
 		${MKDIR} ${PKG_DBDIR}/${PKGNAME}; \
-		${PKG_CMD} ${PKG_ARGS} -O ${PKGFILE} > ${PKG_DBDIR}/${PKGNAME}/+CONTENTS; \
+		${PKG_CMD} -P "$$deps" ${PKG_ARGS} -O ${PKGFILE} \
+			> ${PKG_DBDIR}/${PKGNAME}/+CONTENTS; \
 		${CP} ${DESCR} ${PKG_DBDIR}/${PKGNAME}/+DESC; \
 		${CP} ${COMMENT} ${PKG_DBDIR}/${PKGNAME}/+COMMENT; \
@@ -3393,12 +3437,4 @@
 			${CP} ${PKGMESSAGE} ${PKG_DBDIR}/${PKGNAME}/+DISPLAY; \
 		fi; \
-		for dep in `cd ${.CURDIR} && ${MAKE} ${__softMAKEFLAGS} package-depends ECHO_MSG=${TRUE} | sort -u`; do \
-			if [ -d ${PKG_DBDIR}/$$dep -a -z `echo $$dep | ${GREP} -E ${PKG_IGNORE_DEPENDS}` ]; then \
-				if ! ${GREP} ^${PKGNAME}$$ ${PKG_DBDIR}/$$dep/+REQUIRED_BY \
-					>/dev/null 2>&1; then \
-					${ECHO} ${PKGNAME} >> ${PKG_DBDIR}/$$dep/+REQUIRED_BY; \
-				fi; \
-			fi; \
-		done; \
 	fi
 	@if [ -e /tmp/${PKGNAME}-required-by ]; then \
Comment 4 Mikhail T. 2002-04-02 06:53:15 UTC
To stop sending updated patches here, I'll be posting the latest version
at:

http://virtual-estates.com/~mi/port-stuff/bsd.port.mk-true-depends.patch

	-mi
Comment 5 Kris Kennaway freebsd_committer freebsd_triage 2002-09-19 01:19:35 UTC
State Changed
From-To: open->closed

Problem resolved (patch by sobomax), thanks!