Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Sep 2005 20:01:27 -0400
From:      Mikhail Teterin <mi+kde@aldan.algebra.com>
To:        ports@freebsd.org
Subject:   please, review the attached bsd.port.mk patch
Message-ID:  <200509112001.27578@aldan>

next in thread | raw e-mail | index | archive | help
--Boundary-00=_XVMJDi6UlakwZXA
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello!

The attached patch aims to replace the deep recursion in the
bsd.port.mk's ALL-DEPENDS-LIST script with a shallow one (not sure if
that's the right term, though).

The new version handles circular dependencies nicely and (being shallow)
will never require more than one sub-make to do the job. The existing
algorithm stacks as many make processes as there are dependency-levels
and is thus prone to hitting make's recursion and the kernel's maxproc
limits on occasion. The existing algoritm also passes the already
visited directories on command line, running the risk of hitting the
maximum number of command-line arguments.

An extra bonus is the substantially smaller number of subprocesses
required for every iteration (no sed, grep, cut invokations) --
everything is done by the same single shell subprocess (plus make).

Portmgr is being cautious in adopting this patch, even though the
current implemention's use of grep may miss some dependencies (kde3
misses print/teTeX for example). It needs more testing -- please,
oblige.

To test simply merge the patch into your bsd.port.mk and try various
recursive targets like clean, and fetch-recursive, or simply
all-depends-list.

Note that the list of directories is no longer sort-ed (the current
version uses "sort -u" to get rid of duplicates), so the exact order in
which directories are listed/visited may be different -- that's normal.

Thanks for your time!

	-mi



--Boundary-00=_XVMJDi6UlakwZXA
Content-Type: text/x-diff;
  charset="us-ascii";
  name="bsd.port.mk.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="bsd.port.mk.diff"

Index: bsd.port.mk
===================================================================
RCS file: /home/pcvs/ports/Mk/bsd.port.mk,v
retrieving revision 1.516
diff -U2 -r1.516 bsd.port.mk
--- bsd.port.mk	28 Aug 2005 18:47:56 -0000	1.516
+++ bsd.port.mk	11 Sep 2005 14:55:17 -0000
@@ -4464,23 +4464,40 @@
 # Dependency lists: both build and runtime, recursive.  Print out directory names.
 
+_DEPENDS=${EXTRACT_DEPENDS} ${PATCH_DEPENDS} ${FETCH_DEPENDS} ${BUILD_DEPENDS} ${LIB_DEPENDS} ${RUN_DEPENDS}
+_DEPEND_DIRS=	${_DEPENDS:C,^[^:]*:([^:]*),\1,} ${DEPENDS:C,:.*,,}
+
 all-depends-list:
-.if defined(EXTRACT_DEPENDS) || defined(PATCH_DEPENDS) || defined(FETCH_DEPENDS) || defined(BUILD_DEPENDS) || defined(LIB_DEPENDS) || defined(RUN_DEPENDS) || defined(DEPENDS)
 	@${ALL-DEPENDS-LIST}
-.endif
 
 ALL-DEPENDS-LIST= \
-	checked="${PARENT_CHECKED}"; \
-	for dir in $$(${ECHO_CMD} "${EXTRACT_DEPENDS} ${PATCH_DEPENDS} ${FETCH_DEPENDS} ${BUILD_DEPENDS} ${LIB_DEPENDS} ${RUN_DEPENDS}" | ${SED} -e 'y/ /\n/' | ${CUT} -f 2 -d ':') $$(${ECHO_CMD} ${DEPENDS} | ${SED} -e 'y/ /\n/' | ${CUT} -f 1 -d ':'); do \
-		if [ -d $$dir ]; then \
-			if (${ECHO_CMD} $$checked | ${GREP} -qwv "$$dir"); then \
-				child=$$(cd $$dir; ${MAKE} PARENT_CHECKED="$$checked" all-depends-list); \
-				for d in $$child; do ${ECHO_CMD} $$d; done; \
-				${ECHO_CMD} $$dir; \
-				checked="$$dir $$child $$checked"; \
-			fi; \
-		else \
-			${ECHO_MSG} "${PKGNAME}: \"$$dir\" non-existent -- dependency list incomplete" >&2; \
-		fi; \
-	done | ${SORT} -u
+	L="${_DEPEND_DIRS}";						\
+	checked="";							\
+	while [ -n "$$L" ]; do						\
+		l="";							\
+		for d in $$L; do					\
+			case $$checked in				\
+			$$d\ *|*\ $$d\ *|*\ $$d)			\
+				continue;;				\
+			esac;						\
+			checked="$$checked $$d";			\
+			if [ ! -d $$d ]; then				\
+				${ECHO_MSG} "${PKGNAME}: \"$$d\" non-existent -- dependency list incomplete" >&2; \
+				continue;				\
+			fi;						\
+			${ECHO_CMD} $$d;				\
+			if ! children=$$(${MAKE} -C $$d -V _DEPEND_DIRS); then\
+				${ECHO_MSG} "${PKGNAME}: \"$$d\" erroneous -- dependency list incomplete" >&2; \
+				continue;				\
+			fi;						\
+			for child in $$children; do			\
+				case "$$checked $$l" in			\
+				$$child\ *|*\ $$child\ *|*\ $$child)	\
+					continue;;			\
+				esac;					\
+				l="$$l $$child";			\
+			done;						\
+		done;							\
+		L=$$l;							\
+	done
 
 .if !target(clean-depends)

--Boundary-00=_XVMJDi6UlakwZXA--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200509112001.27578>