git: 0647dd427458 - main - Mk/Uses/go.mk: support v2 and higher proxy URLs

From: Enji Cooper <ngie_at_FreeBSD.org>
Date: Fri, 11 Apr 2025 02:12:16 UTC
The branch main has been updated by ngie:

URL: https://cgit.FreeBSD.org/ports/commit/?id=0647dd427458993a2a4589467d8256998c0ee649

commit 0647dd427458993a2a4589467d8256998c0ee649
Author:     Enji Cooper <ngie@FreeBSD.org>
AuthorDate: 2025-04-09 02:15:22 +0000
Commit:     Enji Cooper <ngie@FreeBSD.org>
CommitDate: 2025-04-11 02:12:05 +0000

    Mk/Uses/go.mk: support v2 and higher proxy URLs
    
    golang projects with versions greater than 2.x have different URLs
    presented for them via `${GOPROXY}` [1]. In particular, the major
    version is added to the URL and to the extracted GOPROXY provided
    DISTFILE(s).
    
    This change adjusts `MASTER_SITES` and `WRKSRC` with `USES+= go` to
    support the "Major Version Suffixes" documented in the go module
    docs [1].
    
    Reviewed by:    adamw, arrowd
    Approved by:    adamw (go)
    Differential Revision:  https://reviews.freebsd.org/D49723
    
    1. https://go.dev/ref/mod#major-version-suffixes
---
 Mk/Uses/go.mk | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/Mk/Uses/go.mk b/Mk/Uses/go.mk
index 421fd310847f..6e924e039ede 100644
--- a/Mk/Uses/go.mk
+++ b/Mk/Uses/go.mk
@@ -167,9 +167,19 @@ MASTER_SITES+=	${GO_MOD_DIST}
 DISTFILES+=	go.mod
 # Fallback to default GO_PROXY
 .        else
+
+# `GOPROXY` presents sources via the proxy service and in the downloaded
+# `WRKSRC` differently as of v2.x versions of projects. Support this different
+# directory/REST API scheme: https://go.dev/ref/mod#major-version-suffixes .
+GO_MODVERSION_MAJOR=	${GO_MODVERSION:C/^v//g:C/\..+//g}
+.if ${GO_MODVERSION_MAJOR} > 1
+WRKSRC=		${WRKDIR}/${GO_MODNAME}/v${GO_MODVERSION_MAJOR}@${GO_MODVERSION}
+MASTER_SITES+=	${GO_GOPROXY}/${GO_MODNAME:C/([A-Z])/!\1/g:tl}/v${GO_MODVERSION_MAJOR}/@v/
+.else
+WRKSRC=		${WRKDIR}/${GO_MODNAME}@${GO_MODVERSION}
 MASTER_SITES+=	${GO_GOPROXY}/${GO_MODNAME:C/([A-Z])/!\1/g:tl}/@v/
+.endif
 DISTFILES+=	${GO_MODFILE} ${GO_DISTFILE}
-WRKSRC=		${WRKDIR}/${GO_MODNAME}@${GO_MODVERSION}
 .        endif
 
 .      endif