From 6cdf2ccae8a30b20c82bf01e7989f0971d1a4764 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Fri, 8 Dec 2023 12:20:35 -0500 Subject: [PATCH] cmd/go: relax version regexp from CL 547998 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 Reviewed-by: Michael Matloob Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills LUCI-TryBot-Result: Go LUCI --- src/cmd/go/internal/work/buildid.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/cmd/go/internal/work/buildid.go b/src/cmd/go/internal/work/buildid.go index 0769443712..bf923d0d5e 100644 --- a/src/cmd/go/internal/work/buildid.go +++ b/src/cmd/go/internal/work/buildid.go @@ -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 != "" { -- 2.48.1