Skip to content

Commit 6cdf2cc

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
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 <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 78b42a5 commit 6cdf2cc

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"os"
1111
"os/exec"
12-
"regexp"
1312
"strings"
1413

1514
"cmd/go/internal/base"
@@ -237,7 +236,6 @@ func (b *Builder) gccToolID(name, language string) (id, exe string, err error) {
237236
}
238237

239238
version := ""
240-
gccVersionRE := regexp.MustCompile(`^[0-9]+\.[0-9]+\.[0-9]+`)
241239
lines := strings.Split(string(out), "\n")
242240
for _, line := range lines {
243241
fields := strings.Fields(line)
@@ -247,9 +245,18 @@ func (b *Builder) gccToolID(name, language string) (id, exe string, err error) {
247245
// contain arbitrary substrings.
248246
break
249247
}
250-
if field == "version" && i < len(fields)-1 && gccVersionRE.MatchString(fields[i+1]) {
251-
version = line
252-
break
248+
if field == "version" && i < len(fields)-1 {
249+
// Check that the next field is plausibly a version number.
250+
// We require only that it begins with an ASCII digit,
251+
// since we don't know what version numbering schemes a given
252+
// C compiler may use. (Clang and GCC mostly seem to follow the scheme X.Y.Z,
253+
// but in https://go.dev/issue/64619 we saw "8.3 [DragonFly]", and who knows
254+
// what other C compilers like "zig cc" might report?)
255+
next := fields[i+1]
256+
if len(next) > 0 && next[0] >= '0' && next[0] <= '9' {
257+
version = line
258+
break
259+
}
253260
}
254261
}
255262
if version != "" {

0 commit comments

Comments
 (0)