1
0
mirror of https://github.com/golang/go synced 2024-09-23 09:33:31 -06:00

cmd/go: set environment LANG=C when getting compiler version

Compiler's version will not work well if gcc output have
different language. Like 'gcc -v', it may not output:
'gcc version xx.xx.x'

 Fixes #69221

Change-Id: I4adcea79dfaaf5853dfb6e718468f8530c67da6a
GitHub-Last-Rev: 069787c083
GitHub-Pull-Request: golang/go#69223
Reviewed-on: https://go-review.googlesource.com/c/go/+/610215
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: DING HU <huzuzong123@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
jokemanfire 2024-09-06 13:42:49 +00:00 committed by Michael Matloob
parent 30f3931c54
commit c1fe637eda

View File

@ -357,7 +357,9 @@ func compilerVersion() (version, error) {
compiler.err = func() error {
compiler.name = "unknown"
cc := os.Getenv("CC")
out, err := exec.Command(cc, "--version").Output()
cmd := exec.Command(cc, "--version")
cmd.Env = append(cmd.Environ(), "LANG=C")
out, err := cmd.Output()
if err != nil {
// Compiler does not support "--version" flag: not Clang or GCC.
return err
@ -366,7 +368,9 @@ func compilerVersion() (version, error) {
var match [][]byte
if bytes.HasPrefix(out, []byte("gcc")) {
compiler.name = "gcc"
out, err := exec.Command(cc, "-v").CombinedOutput()
cmd := exec.Command(cc, "-v")
cmd.Env = append(cmd.Environ(), "LANG=C")
out, err := cmd.CombinedOutput()
if err != nil {
// gcc, but does not support gcc's "-v" flag?!
return err