Allow both prefix-goVERSION and goVERSION-suffix for custom toolchains.
Also make sure that a tie in the toolchain and min version goes to the
toolchain line.
For #57001.
Change-Id: Ibeea5f47db7349cfdf36da188bb43e195e196f5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/498076
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
} else if toolchain != "" {
// Accept toolchain only if it is >= our min.
toolVers := gover.ToolchainVersion(toolchain)
- if gover.Compare(toolVers, minVers) > 0 {
+ if gover.Compare(toolVers, minVers) >= 0 {
gotoolchain = toolchain
}
} else {
"internal/goversion"
"runtime"
"strconv"
- "strings"
)
// TestVersion is initialized in the go command test binary
if TestVersion != "" {
v = TestVersion
}
- if strings.HasPrefix(v, "go") {
- v := strings.TrimPrefix(v, "go")
- // Some builds use custom suffixes; strip them.
- if i := strings.IndexAny(v, " \t+-"); i >= 0 {
- v = v[:i]
- }
- if IsValid(v) {
- return v
- }
+ if v := ToolchainVersion(v); v != "" {
+ return v
}
+
// Development branch. Use "Dev" version with just 1.N, no rc1 or .0 suffix.
return "1." + strconv.Itoa(goversion.Version)
}
// ToolchainVersion returns the Go version for the named toolchain,
// derived from the name itself (not by running the toolchain).
// A toolchain is named "goVERSION" or "anything-goVERSION".
+// A suffix after the VERSION introduced by a +, -, space, or tab is removed.
// Examples:
//
// ToolchainVersion("go1.2.3") == "1.2.3"
+// ToolchainVersion("go1.2.3+bigcorp") == "1.2.3"
+// ToolchainVersion("go1.2.3-bigcorp") == "1.2.3"
// ToolchainVersion("gccgo-go1.23rc4") == "1.23rc4"
// ToolchainVersion("invalid") == ""
func ToolchainVersion(name string) string {
var v string
- if strings.HasPrefix(name, "go") && IsValid(name[2:]) {
+ if strings.HasPrefix(name, "go") {
v = name[2:]
- } else if i := strings.Index(name, "-go"); i >= 0 && IsValid(name[i+3:]) {
+ } else if i := strings.Index(name, "-go"); i >= 0 {
v = name[i+3:]
}
+ // Some builds use custom suffixes; strip them.
+ if i := strings.IndexAny(v, " \t+-"); i >= 0 {
+ v = v[:i]
+ }
+ if !IsValid(v) {
+ return ""
+ }
return v
}
[!GOOS:plan9] env PATH=$WORK/bin${:}$PATH
[GOOS:plan9] env path=$WORK/bin${:}$path
go build -o $WORK/bin/ ./go1.999testpath.go # adds .exe extension implicitly on Windows
+cp $WORK/bin/go1.999testpath$GOEXE $WORK/bin/custom-go1.999.0$GOEXE
+cp $WORK/bin/go1.999testpath$GOEXE $WORK/bin/go1.999.0-custom$GOEXE
# GOTOOLCHAIN from PATH
env GOTOOLCHAIN=go1.999testpath
go version
stdout go1.999
+# custom toolchain line in go.mod
+env TESTGO_VERSION=go1.999
+go version
+stdout testpath # go1.999 < go1.999testpath
+
+env TESTGO_VERSION=go1.999.0
+go version
+! stdout testpath # go1.999testpath < go1.999.0
+
+cp go119customtoolchain1999 go.mod
+go version
+stdout go1.999testpath # custom-go1.999.0 >= go1.999.0
+
+cp go119customtoolchain1999b go.mod
+go version
+stdout go1.999testpath # go1.999.0-custom >= go1.999.0
+
+env TESTGO_VERSION=go1.100
+
# toolchain local in go.mod
cp go1999toolchainlocal go.mod
! go build
go 1.19
toolchain go1.999testpath
+-- go119customtoolchain1999 --
+go 1.19
+toolchain custom-go1.999.0
+
+-- go119customtoolchain1999b --
+go 1.19
+toolchain go1.999.0-custom
+
-- go1999toolchainlocal --
go 1.999
toolchain local