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
This commit is contained in:
Enji Cooper 2025-04-08 19:15:22 -07:00
parent 892ce98277
commit 0647dd4274

View file

@ -167,9 +167,19 @@ MASTER_SITES+= ${GO_MOD_DIST}
DISTFILES+= go.mod
# Fallback to default GO_PROXY
. else
MASTER_SITES+= ${GO_GOPROXY}/${GO_MODNAME:C/([A-Z])/!\1/g:tl}/@v/
DISTFILES+= ${GO_MODFILE} ${GO_DISTFILE}
# `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}
. endif
. endif