Subject: Proposed fix for PR pkg/15539: broken fetch-list target
To: Bernd Ernesti <netbsd@arresum.inka.de>
From: Frederick Bruckman <fredb@immanent.net>
List: tech-pkg
Date: 02/18/2002 16:04:31
Here's a proposed change to the fetch-list target. I revived the old
fetch-list-one-pkg handling with changes, including adding some
comments and windows dressing to the generated script, so that it
produces much nicer output now, I think, than even the old target.

Most of the change is actually in fetch-list-one-pkg. It now checks
properly for the file on the host running make, before generating any
substantial output.

With packages with very hairy dependency trees, such as "gnome", it
still takes too much time, and produces too much output, as
fetch-list-one-pkg gets run for packages at the ends of the graph over
and over, every single time they're reached through walking of another
package's dependency tree. It's been like that for a while, though:
the only change is, I've had to drop the "sort -u" which was
heretofore masking the problem, as "fetch-list-one-pkg" no longer
produces a single line of output. I could do the equivalent multi-line
sort with sed or awk, but the underlying problem of how the recursive
targets should be better handled would remain, so I'd rather not.

Feedback welcome.


Frederick

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/18 21:25:39
@@ -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,13 @@

 .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, to fetch all missing files'
+	@${ECHO} '# needed to build ${PKGNAME} on host ${HOSTNAME},'
+	@${ECHO} '# including files needed to build all dependencies.'
+	@${ECHO} '#'
+	@${MAKE} ${MAKEFLAGS} fetch-list-recursive RECURSIVE_FETCH_LIST=${RECURSIVE_FETCH_LIST}
 .endif # !target(fetch-list)

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

 .if !target(fetch-list-one-pkg)
 fetch-list-one-pkg:
-	@${ECHO} ${_FETCH_ALLFILES:Q}
+	@${MKDIR} ${_DISTDIR}
+	@${ECHO}
+	@${ECHO} '# Fetch files for ${PKGNAME}:'
+	@${ECHO} '#'
+	@[ -z "${_DISTDIR}" ] || ${ECHO} "${MKDIR} ${_DISTDIR}"
+.  if !empty(_ALLFILES)
+.    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} 'cd ${_DISTDIR} && [ -f ${fetchfile} -o -f ${fetchfile:T} ] ||'; \
+		${ECHO}	'for site in "" $$sites; do';			\
+		${ECHO} '	if [ "X$$site" = X"" ]; then continue; fi'; \
+		${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