]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[release-branch.go1.22] go/version: fix package to accept go1.21.0-bigcorp
authorRuss Cox <rsc@golang.org>
Wed, 24 Jan 2024 21:29:20 +0000 (16:29 -0500)
committerMichael Knyszek <mknyszek@google.com>
Thu, 1 Feb 2024 18:32:47 +0000 (18:32 +0000)
The proposal discussion made clear that suffixes should be accepted,
so that people who use custom VERSION files can still pass runtime.Version()
to this code. But we forgot to do that in the CL. Do that.

Note that cmd/go also strips space- and tab-prefixed suffixes,
but go.dev/doc/toolchain only mentions dash, so this code only
strips dash.

Fixes #65061.

Change-Id: I6a427b78f964eb41c024890dae30223beaef13eb
Cq-Include-Trybots: luci.golang.try:go1.22-linux-amd64-longtest,go1.22-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/559796
TryBot-Bypass: Russ Cox <rsc@golang.org>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/559802
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/go/version/version.go
src/go/version/version_test.go

index 466c8091ea6c0fcc5b762d37817412ed163b3279..6b8ee6744239d5d9d7c8a167a69c0250dfb70459 100644 (file)
@@ -2,9 +2,12 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Package version provides operations on [Go versions].
+// Package version provides operations on [Go versions]
+// in [Go toolchain name syntax]: strings like
+// "go1.20", "go1.21.0", "go1.22rc2", and "go1.23.4-bigcorp".
 //
 // [Go versions]: https://go.dev/doc/toolchain#version
+// [Go toolchain name syntax]: https://go.dev/doc/toolchain#name
 package version // import "go/version"
 
 import (
@@ -12,9 +15,10 @@ import (
        "strings"
 )
 
-// stripGo converts from a "go1.21" version to a "1.21" version.
+// stripGo converts from a "go1.21-bigcorp" version to a "1.21" version.
 // If v does not start with "go", stripGo returns the empty string (a known invalid version).
 func stripGo(v string) string {
+       v, _, _ = strings.Cut(v, "-") // strip -bigcorp suffix.
        if len(v) < 2 || v[:2] != "go" {
                return ""
        }
@@ -50,8 +54,6 @@ func Lang(x string) string {
 // valid versions and equal to each other.
 // The language version "go1.21" compares less than the
 // release candidate and eventual releases "go1.21rc1" and "go1.21.0".
-// Custom toolchain suffixes are ignored during comparison:
-// "go1.21.0" and "go1.21.0-bigcorp" are equal.
 func Compare(x, y string) int {
        return gover.Compare(stripGo(x), stripGo(y))
 }
index 7c12e7ffd96f8d2c9017a7669d88181efc4f32ec..ad83a258614f6f71fb309226fb6e506b0fb830c0 100644 (file)
@@ -23,13 +23,16 @@ var compareTests = []testCase2[string, string, int]{
        {"go1.19", "go1.19.0", 0},
        {"go1.19rc1", "go1.19", -1},
        {"go1.20", "go1.20.0", 0},
+       {"go1.20", "go1.20.0-bigcorp", 0},
        {"go1.20rc1", "go1.20", -1},
        {"go1.21", "go1.21.0", -1},
+       {"go1.21", "go1.21.0-bigcorp", -1},
        {"go1.21", "go1.21rc1", -1},
        {"go1.21rc1", "go1.21.0", -1},
        {"go1.6", "go1.19", -1},
        {"go1.19", "go1.19.1", -1},
        {"go1.19rc1", "go1.19", -1},
+       {"go1.19rc1", "go1.19", -1},
        {"go1.19rc1", "go1.19.1", -1},
        {"go1.19rc1", "go1.19rc2", -1},
        {"go1.19.0", "go1.19.1", -1},