]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: relax version regexp from CL 547998
authorBryan C. Mills <bcmills@google.com>
Fri, 8 Dec 2023 17:20:35 +0000 (12:20 -0500)
committerGopher Robot <gobot@golang.org>
Fri, 8 Dec 2023 18:34:24 +0000 (18:34 +0000)
In CL 547998 I relaxed cmd/go's parsing of version lines to allow it
to recognize clang versions with vendor prefixes. To prevent false-positives,
I added a check for a version 3-tuple following the word "version".
However, it appears that some releases of GCC use only a 2-tuple instead.

Updates #64423.
Fixes #64619.

Change-Id: I5f1d0881b6295544a46ab958c6ad4c2155cf51fe
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/548120
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/go/internal/work/buildid.go

index 0769443712c692e2b8f236630c2e7b32cb2bb340..bf923d0d5e7d3274a52f83dc5b02fcf52aed8971 100644 (file)
@@ -9,7 +9,6 @@ import (
        "fmt"
        "os"
        "os/exec"
-       "regexp"
        "strings"
 
        "cmd/go/internal/base"
@@ -237,7 +236,6 @@ func (b *Builder) gccToolID(name, language string) (id, exe string, err error) {
        }
 
        version := ""
-       gccVersionRE := regexp.MustCompile(`^[0-9]+\.[0-9]+\.[0-9]+`)
        lines := strings.Split(string(out), "\n")
        for _, line := range lines {
                fields := strings.Fields(line)
@@ -247,9 +245,18 @@ func (b *Builder) gccToolID(name, language string) (id, exe string, err error) {
                                // contain arbitrary substrings.
                                break
                        }
-                       if field == "version" && i < len(fields)-1 && gccVersionRE.MatchString(fields[i+1]) {
-                               version = line
-                               break
+                       if field == "version" && i < len(fields)-1 {
+                               // Check that the next field is plausibly a version number.
+                               // We require only that it begins with an ASCII digit,
+                               // since we don't know what version numbering schemes a given
+                               // C compiler may use. (Clang and GCC mostly seem to follow the scheme X.Y.Z,
+                               // but in https://go.dev/issue/64619 we saw "8.3 [DragonFly]", and who knows
+                               // what other C compilers like "zig cc" might report?)
+                               next := fields[i+1]
+                               if len(next) > 0 && next[0] >= '0' && next[0] <= '9' {
+                                       version = line
+                                       break
+                               }
                        }
                }
                if version != "" {