Skip to content

Commit

Permalink
mk: Add mktool support to fetch.
Browse files Browse the repository at this point in the history
mktool is an optional external tool, available from pkgtools/mktool or
"cargo install mktool", that provides significant performance improvements
and an improved progress bar compared to other fetch commands.

After installing, set both:

  FETCH_USING=			mktool
  TOOLS_PLATFORM.mktool=	/path/to/mktool

to enable it.  This is so that an alternate fetch command can still be used
if required, while still using mktool elsewhere in the infrastructure, as
not all network access methods (e.g. proxies) have been fully tested.

When testing the performance of "bmake fetch" inside wip/grafana on an M1
MacBook Pro running macOS, fetching distfiles from http://localhost/ backed
by www/caddy, FETCH_USING=curl took 47m 58s while FETCH_USING=mktool took
just 4 seconds, well over 500x faster!

This can be seen in realtime along with an example of the streamlined
progress bar at <https://asciinema.org/a/S4MWXHLSJmL4GKYAhOBIIHE31>.
  • Loading branch information
jperkin committed Oct 11, 2024
1 parent b1ad5d6 commit 0ff749d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion mk/fetch/fetch.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $NetBSD: fetch.mk,v 1.76 2024/02/21 10:53:28 jperkin Exp $
# $NetBSD: fetch.mk,v 1.77 2024/10/11 11:52:23 jperkin Exp $

.if empty(INTERACTIVE_STAGE:Mfetch) && empty(FETCH_MESSAGE:U)
_MASTER_SITE_BACKUP= ${MASTER_SITE_BACKUP:=${DIST_SUBDIR}${DIST_SUBDIR:D/}}
Expand Down Expand Up @@ -94,7 +94,15 @@ fetch: ${_FETCH_TARGETS}
.if !target(do-fetch)
. if !empty(_ALLFILES)
do-fetch: ${_ALLFILES:S/^/${DISTDIR}\//}
. if ${FETCH_USING} == "mktool" && !empty(TOOLS_PLATFORM.mktool)
@{ ${_ALLFILES:@file@ \
unsorted_sites="${SITES.${file:T}}"; \
sites="${_ORDERED_SITES} ${_MASTER_SITE_BACKUP}"; \
echo ${file} ${DISTDIR} $$sites; \
@} } | ${TOOLS_PLATFORM.mktool} fetch -I - ${_MKTOOL_FETCH_ARGS}
. else
@${DO_NADA}
. endif
. else
do-fetch:
@${DO_NADA}
Expand All @@ -120,7 +128,11 @@ ${DISTDIR}/${_file_}:
. if empty(IGNORE_INTERACTIVE_FETCH:Uno:M[yY][eE][sS])
${DISTDIR}/${_file_}: fetch-check-interactive
. endif
. if ${FETCH_USING} == "mktool" && !empty(TOOLS_PLATFORM.mktool)
${DISTDIR}/${_file_}: error-check
. else
${DISTDIR}/${_file_}: do-fetch-file error-check
. endif
. endif
.endfor
Expand Down Expand Up @@ -299,10 +311,13 @@ _FETCH_CMD= ${PKGSRC_SETENV} CHECKSUM=${_CHECKSUM_CMD:Q} \
WC=${TOOLS_WC:Q} \
${SH} ${PKGSRCDIR}/mk/fetch/fetch
_MKTOOL_FETCH_ARGS= -d ${DISTDIR}
_FETCH_ARGS+= ${PKG_VERBOSE:D-v}
.if exists(${DISTINFO_FILE}) && !make(distinfo) && !make(makesum) \
&& !make(makedistinfo) && !make(mdi)
_FETCH_ARGS+= ${FAILOVER_FETCH:D-c} -f ${DISTINFO_FILE:tA:Q}
_MKTOOL_FETCH_ARGS+= -f ${DISTINFO_FILE:tA:Q}
.endif
.if !empty(PKG_RESUME_TRANSFERS:M[yY][eE][sS])
_FETCH_ARGS+= -r
Expand Down

0 comments on commit 0ff749d

Please sign in to comment.