git: b318a7cadc57 - main - Uses/go.mk: Add support for requesting a minimum version
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 15 Dec 2025 13:43:51 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/ports/commit/?id=b318a7cadc57d35a4dfdc1db90048b5e7b194501
commit b318a7cadc57d35a4dfdc1db90048b5e7b194501
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-12-15 13:42:57 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-12-15 13:43:24 +0000
Uses/go.mk: Add support for requesting a minimum version
This adds support for requesting a minimum Go version instead of an
exact one. If USES contains something like go:X.Y+, we walk the list
of valid Go versions backward and pick the first element that matches
either the requested version or the default version. Assuming the
list of valid versions is sorted semantically, this means we will
pick the requested version if it is newer than the default version,
and the default version otherwise.
This is somewhat imprecise, but it's hard to do better without a
comparison operator that understands semantic versioning, which bmake
lacks. Simply comparing versions lexicographically or numerically
would produce incorrect results, since e.g. 1.3 precedes 1.29 but is
both lexicographically and numerically larger.
Note that specifying a version that does not yet exist in the ports tree
will have the same effect as specifying a version that has been retired:
silently fall back to the default version.
This also drops support for pinning to -devel. This is currently unused
and doesn't work as implemented; furthermore, the current -devel port is
wildly out of date and is expected to be removed rather than updated.
MFH: 2025Q4
Reviewed by: fuz, adamw
Differential Revision: https://reviews.freebsd.org/D54104
---
Mk/Uses/go.mk | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/Mk/Uses/go.mk b/Mk/Uses/go.mk
index 872546e6fd01..3d34f15508cd 100644
--- a/Mk/Uses/go.mk
+++ b/Mk/Uses/go.mk
@@ -3,10 +3,11 @@
#
# Feature: go
# Usage: USES=go
-# Valid ARGS: (none), N.NN, N.NN-devel, modules, no_targets, run
+# Valid ARGS: (none), N.NN+, N.NN, modules, no_targets, run
#
# (none) Setup GOPATH and build in GOPATH mode using default Go version.
-# N.NN Specify Go version
+# N.NN+ Specify minimum Go version
+# N.NN Specify exact Go version (should be avoided)
# modules If the upstream uses Go modules, this can be set to build
# in modules-aware mode.
# no_targets Indicates that Go is needed at build time as a part of
@@ -83,19 +84,30 @@ _INCLUDE_USES_GO_MK= yes
# When adding a version, please keep the comment in
# Mk/bsd.default-versions.mk in sync.
-GO_VALID_VERSIONS= 1.20 1.21 1.22 1.23 1.24 1.25 1.26-devel
+GO_VALID_VERSIONS= 1.20 1.21 1.22 1.23 1.24 1.25
# Check arguments sanity
-. if !empty(go_ARGS:N[1-9].[0-9][0-9]:N*-devel:Nmodules:Nno_targets:Nrun)
-IGNORE= USES=go has invalid arguments: ${go_ARGS:N[1-9].[0-9][0-9]:N*-devel:Nmodules:Nno_targets:Nrun}
+. if !empty(go_ARGS:N[1-9].[0-9][0-9]+:N[1-9].[0-9][0-9]:Nmodules:Nno_targets:Nrun)
+IGNORE= USES=go has invalid arguments: ${go_ARGS:N[1-9].[0-9][0-9]+:N[1-9].[0-9][0-9]:Nmodules:Nno_targets:Nrun}
. endif
# Parse Go version
-GO_VERSION= ${go_ARGS:Nmodules:Nno_targets:Nrun:C/^$/${GO_DEFAULT}/}
-. if empty(GO_VALID_VERSIONS:M${GO_VERSION})
+. if !empty(go_ARGS:M*+)
+GO_MIN_VERSION= ${go_ARGS:M*+:S/+//}
+. for version in ${GO_VALID_VERSIONS:[-1..1]}
+. if empty(GO_VERSION)
+. if ${version} == ${GO_DEFAULT} || ${version} == ${GO_MIN_VERSION}
+GO_VERSION:= ${version}
+. endif
+. endif
+. endfor
+. else
+GO_VERSION:= ${go_ARGS:Nmodules:Nno_targets:Nrun:C/^$/${GO_DEFAULT}/}
+. if empty(GO_VALID_VERSIONS:M${GO_VERSION})
IGNORE?= USES=go has invalid version number: ${GO_VERSION}
+. endif
. endif
-GO_SUFFIX= ${GO_VERSION:S/.//:C/.*-devel/-devel/}
+GO_SUFFIX= ${GO_VERSION:S/.//}
GO_PORT= lang/go${GO_SUFFIX}
# Settable variables