Subject: Top-level fetch and fetch-list (patch, long)
To: None <tech-pkg@NetBSD.ORG>
From: Frederick Bruckman <fredb@immanent.net>
List: tech-pkg
Date: 02/20/2002 09:40:57
I think the top-level fetch and fetch-list are not very useful in their
present form. "fetch" will do an actual "make fetch" in each package
directory, which means it will try to install all dependencies. That may
(or may not) be desirable in a package directory, but it's certainly not
what was intended if invoked at the top-level. "fetch-list", in the
package directory, now recurses over all dependencies, which is also
inappropriate for the top-level (as you'll get them all anyway without
that, only faster).

I propose to give the two top-level fetch targets special handling;
patch follows. I've also included my work-in-progess fix for pkg/15539,
without which the awk post-processing in the top-level fetch-list
doesn't make sense.

Comments?

Frederick


Index: mk/bsd.pkg.subdir.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.subdir.mk,v
retrieving revision 1.45
diff -u -r1.45 bsd.pkg.subdir.mk
--- mk/bsd.pkg.subdir.mk	2001/11/28 10:21:47	1.45
+++ mk/bsd.pkg.subdir.mk	2002/02/20 02:47:56
@@ -26,7 +26,7 @@
 #		Creating README.html for package.
 #
 #	afterinstall, all, beforeinstall, build, checksum, clean,
-#	configure, deinstall, depend, describe, extract, fetch, fetch-list,
+#	configure, deinstall, depend, describe, extract, fetch-list-one-pkg,
 #	install, package, readmes, realinstall, reinstall, tags,
 #	mirror-distfiles, bulk-install, bulk-package, ${PKG_MISC_TARGETS}
 #
@@ -93,7 +93,7 @@
 	fi; \
 	${MAKE} ${MAKEFLAGS} all

-.for __target in all fetch fetch-list package extract configure build clean \
+.for __target in all fetch-list-one-pkg package extract configure build clean \
 		cleandir distclean depend describe reinstall tags checksum \
 		makepatchsum mirror-distfiles deinstall show-downlevel \
 		show-pkgsrc-dir show-var show-vars bulk-install bulk-package \
Index: Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/Makefile,v
retrieving revision 1.46
diff -u -r1.46 Makefile
--- Makefile	2001/12/17 02:33:46	1.46
+++ Makefile	2002/02/20 02:47:56
@@ -155,3 +155,31 @@
 	@${ECHO} "HOST_SPECIFIC_PKGS= \\";					\
 	${MAKE} show-pkgsrc-dir | awk '/^===/ { next; } { printf("%s \\\n", $$1) }'; \
 	${ECHO} ""
+
+# It makes no sense to actually run "fetch-list" in each directory
+# from the top, as the recursion is useless for this case.
+#
+fetch-list:
+	@${ECHO} '#!/bin/sh'
+	@${ECHO} '#'
+	@${ECHO} '# This is an auto-generated script, the result of running'
+	@${ECHO} '# "make fetch-list" in '"`pwd`"' on host ${HOSTNAME}.'
+	@${ECHO} '#'
+	@${MAKE} ${MAKEFLAGS} fetch-list-one-pkg		\
+	| ${AWK} '						\
+	function do_block () {					\
+		if (FoundSomething) {				\
+			for (line = 0; line < c; line++)	\
+				print block[line];		\
+			FoundSomething = 0 }			\
+		c = 0 }						\
+	/^[^#=]/ { FoundSomething = 1 }				\
+	/^unsorted/ { gsub(/[[:space:]]+/, " \\\n\t") }		\
+	!/^=/ { block[c++] = $$0 }				\
+	/^=/ { do_block() }					\
+	END { do_block() }'
+
+# Do what I mean. Just fetch; don't install anything!
+#
+fetch:
+	${MAKE} ${MAKEFLAGS} checksum
Index: bsd.pkg.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.928
diff -u -r1.928 bsd.pkg.mk
--- bsd.pkg.mk	2002/02/18 15:14:34	1.928
+++ bsd.pkg.mk	2002/02/20 02:45:15
@@ -1272,7 +1272,7 @@
 .endif

 #
-# Complete macro for the do-fetch and fetch-list-one-package targets.
+# Complete macro for the do-fetch target.
 #
 .if !defined(_FETCH_ALLFILES)
 .  if !empty(_DISTFILES)
@@ -2699,7 +2699,12 @@

 .if !target(fetch-list)
 fetch-list:
-	@${MAKE} ${MAKEFLAGS} fetch-list-recursive RECURSIVE_FETCH_LIST=${RECURSIVE_FETCH_LIST} | ${SORT} -u
+	@${ECHO} '#!/bin/sh'
+	@${ECHO} '#'
+	@${ECHO} '# This is an auto-generated script, the result of running'
+	@${ECHO} '# "make fetch-list" in '"`pwd`"' on host ${HOSTNAME}.'
+	@${ECHO} '#'
+	@${MAKE} ${MAKEFLAGS} fetch-list-recursive RECURSIVE_FETCH_LIST=${RECURSIVE_FETCH_LIST}
 .endif # !target(fetch-list)

 .if !target(fetch-list-recursive)
@@ -2718,7 +2723,29 @@

 .if !target(fetch-list-one-pkg)
 fetch-list-one-pkg:
-	@${ECHO} ${_FETCH_ALLFILES:Q}
+.  if !empty(_ALLFILES)
+	@${ECHO}
+	@${ECHO} '#'
+	@${ECHO} '# Fetch files for ${PKGNAME}:'
+	@${ECHO} '#'
+	@${MKDIR} ${_DISTDIR}
+.    for fetchfile in ${_ALLFILES}
+	@(cd ${_DISTDIR};						\
+	if [ ! -f ${fetchfile} -a ! -f ${fetchfile:T} ]; then		\
+		${ECHO};						\
+		${ECHO} '# Fetch ${fetchfile}:';			\
+		${ECHO} '#';						\
+		${ECHO} 'unsorted_sites="${SITES_${fetchfile:T}} ${_MASTER_SITE_BACKUP}"'; \
+		${ECHO} sites='"'${ORDERED_SITES:Q}'"';			\
+		${ECHO} "${MKDIR} ${_DISTDIR}";				\
+		${ECHO} 'cd ${_DISTDIR} && [ -f ${fetchfile} -o -f ${fetchfile:T} ] ||'; \
+		${ECHO}	'for site in "" $$sites; do';			\
+		${ECHO} '	${FETCH_CMD} ${FETCH_BEFORE_ARGS} "$${site}${fetchfile:T}" ${FETCH_AFTER_ARGS} && break ||'; \
+		${ECHO} '	${ECHO} ${fetchfile} not fetched';	\
+		${ECHO}	done;						\
+	fi)
+.    endfor
+.  endif # !empty(_ALLFILES)
 .endif # !target(fetch-list-one-pkg)

 # Checksumming utilities