git: 6e236e189653 - main - Mk/Uses/go.mk: Try to tidy up go.sum after fetch, fix EXTRACT_ONLY

From: Dmitri Goutnik <dmgk_at_FreeBSD.org>
Date: Mon, 09 May 2022 11:15:30 UTC
The branch main has been updated by dmgk:

URL: https://cgit.FreeBSD.org/ports/commit/?id=6e236e18965327f6100473770e4edb78c94fb1d4

commit 6e236e18965327f6100473770e4edb78c94fb1d4
Author:     Dmitri Goutnik <dmgk@FreeBSD.org>
AuthorDate: 2022-05-08 20:49:05 +0000
Commit:     Dmitri Goutnik <dmgk@FreeBSD.org>
CommitDate: 2022-05-09 11:15:14 +0000

    Mk/Uses/go.mk: Try to tidy up go.sum after fetch, fix EXTRACT_ONLY
    
    Make a best effort attempt (without network access) to add missing
    go.sum entries using local module cache prepared by the fetch stage.
    
    Set EXTRACT_ONLY dynamically from DISTFILES, repair
    USE_{GITHUB,GITLAB}.
    
    PR:             258210
    PR:             262981
    PR:             263866
---
 Mk/Uses/go.mk | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/Mk/Uses/go.mk b/Mk/Uses/go.mk
index 0b5f48ed8e07..b73e198e29fe 100644
--- a/Mk/Uses/go.mk
+++ b/Mk/Uses/go.mk
@@ -118,6 +118,7 @@ GO_ENV+=	CGO_ENABLED=${CGO_ENABLED} \
 GO_BUILDFLAGS+=	-mod=vendor
 GO_TESTFLAGS+=	-mod=vendor
 GO_GOPATH=	${DISTDIR}/go/${PKGORIGIN:S,/,_,g}
+GO_MODCACHE=	file://${GO_GOPATH}/pkg/mod/cache/download
 GO_WRKSRC=	${WRKSRC}
 GO_ENV+=	GOPATH="${GO_GOPATH}" \
 		GOBIN="${GO_WRKDIR_BIN}" \
@@ -126,15 +127,15 @@ GO_ENV+=	GOPATH="${GO_GOPATH}" \
 		GOSUMDB=${GO_GOSUMDB}
 .    if defined(GO_MODULE)
 GO_MODNAME=	${GO_MODULE:C/^([^@]*)(@([^@]*)?)/\1/}
-.      if empty(DISTFILES:Mgo.mod*)
+.      if empty(DISTFILES:Mgo.mod\:*) && empty(DISTFILES:Mgo.mod)
 GO_MODVERSION=	${GO_MODULE:C/^([^@]*)(@([^@]*)?)/\2/:M@*:S/^@//:S/^$/${DISTVERSIONFULL}/}
 GO_MODFILE=	${GO_MODVERSION}.mod
 GO_DISTFILE=	${GO_MODVERSION}.zip
 MASTER_SITES+=	${GO_GOPROXY}/${GO_MODNAME:C/([A-Z])/!\1/g:tl}/@v/
 DISTFILES+=	${GO_MODFILE} ${GO_DISTFILE}
-EXTRACT_ONLY+=	${GO_DISTFILE}
 WRKSRC=		${WRKDIR}/${GO_MODNAME}@${GO_MODVERSION}
 .      endif
+EXTRACT_ONLY+=	${DISTFILES:N*.mod\:*:N*.mod:C/:.*//}
 DIST_SUBDIR=	go/${PKGORIGIN:S,/,_,g}/${DISTNAME}
 FETCH_DEPENDS+=	${GO_CMD}:${GO_PORT} \
 		ca_root_nss>0:security/ca_root_nss
@@ -166,7 +167,7 @@ post-fetch:
 	@${ECHO_MSG} "===> Fetching ${GO_MODNAME} dependencies";
 	@(cd ${DISTDIR}/${DIST_SUBDIR}; \
 		[ -e go.mod ] || ${RLN} ${GO_MODFILE} go.mod; \
-		${SETENV} ${GO_ENV} GOPROXY=${GO_GOPROXY} ${GO_CMD} mod download -x)
+		${SETENV} ${GO_ENV} GOPROXY=${GO_GOPROXY} ${GO_CMD} mod download -x all)
 .  endif
 
 .  if !target(post-extract)
@@ -176,7 +177,10 @@ post-extract:
 	@${LN} -sf ${WRKSRC} ${GO_WRKSRC}
 .    elif ${go_ARGS:Mmodules} && defined(GO_MODULE)
 post-extract:
-	@(cd ${GO_WRKSRC}; ${SETENV} ${GO_ENV} GOPROXY=off ${GO_CMD} mod vendor -e)
+	@${ECHO_MSG} "===> Tidying ${GO_MODNAME} dependencies";
+	@(cd ${GO_WRKSRC}; ${SETENV} ${GO_ENV} GOPROXY=${GO_MODCACHE} ${GO_CMD} mod tidy -e)
+	@${ECHO_MSG} "===> Vendoring ${GO_MODNAME} dependencies";
+	@(cd ${GO_WRKSRC}; ${SETENV} ${GO_ENV} GOPROXY=${GO_MODCACHE} ${GO_CMD} mod vendor -e)
 .    endif 
 .  endif