]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: accept non-standard versions like go1.21-20230523-foo in latest
authorRuss Cox <rsc@golang.org>
Tue, 23 May 2023 15:00:37 +0000 (11:00 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 23 May 2023 16:31:31 +0000 (16:31 +0000)
Some custom toolchain builds add extra suffixes to the version.
Strip those off (cutting at - or +) to find the underlying Go version.

For #57001.

Change-Id: I234fb2d069aaf0922c0a2c848e4a4c38e4adf9bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/497415
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>

src/cmd/go/internal/gover/latest.go
src/cmd/go/testdata/script/gotoolchain.txt

index 7cfce47aef6d35efb5d6ede6a294749a088fac69..05ee4401b5566a7a38e807ab0e733b0a5a1714c5 100644 (file)
@@ -23,7 +23,14 @@ func Local() string {
                v = TestVersion
        }
        if strings.HasPrefix(v, "go") {
-               return strings.TrimPrefix(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
+               }
        }
        // Development branch. Use "Dev" version with just 1.N, no rc1 or .0 suffix.
        return "1." + strconv.Itoa(goversion.Version)
index a202901ef30fd6ebe5f1cf774f97c0bf54b6bed2..505317d2834c91d2995140754ce8ecc6b3bb3a6c 100644 (file)
@@ -87,6 +87,37 @@ go version
 ! stdout go1.999
 rm go.work
 
+# go1.999 should handle go1.998 without a download
+env TESTGO_VERSION=go1.999
+cp go1998 go.mod
+go version
+! stdout go1.998 # local toolchain instead
+
+# go1.998 should handle go1.998 without a download too
+env TESTGO_VERSION=go1.999
+go version
+! stdout go1.998 # local toolchain instead
+
+# go1.998+foo should handle go1.998 without a download too
+env TESTGO_VERSION=go1.998+foo
+go version
+! stdout go1.998 # local toolchain instead
+
+# go1.998-foo should handle go1.998 without a download too
+env TESTGO_VERSION=go1.998-foo
+go version
+! stdout go1.998 # local toolchain instead
+
+# 'go1.998 foo' should handle go1.998 without a download too
+env TESTGO_VERSION='go1.998 foo'
+go version
+! stdout go1.998 # local toolchain instead
+
+# go1.997-foo should download go1.998
+env TESTGO_VERSION=go1.997-foo
+! go version
+stderr go1.998
+
 # GOTOOLCHAIN=auto+go1.1000 falls back to go1.1000 if newer than go line
 env TESTGO_VERSION=go1.1
 env GOTOOLCHAIN=auto+go1.1000
@@ -132,6 +163,9 @@ stderr '^go: cannot find "go1.999mod" in PATH$'
 -- go1999 --
 go 1.999testpath
 
+-- go1998 --
+go 1.998
+
 -- go1999mod --
 go 1.999mod
 
@@ -152,5 +186,5 @@ package main
 import "os"
 
 func main() {
-       os.Stdout.WriteString("go1.999testpath here!")
+       os.Stdout.WriteString("go1.999testpath here!\n")
 }