From: Ian Lance Taylor Date: Tue, 15 Nov 2016 22:48:54 +0000 (-0800) Subject: cmd/go: don't clobber `go env GOGCCFLAGS` X-Git-Tag: go1.8beta1~78 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e9ffda45c8b7d409a5b951d6a74b8241c026fad5;p=gostls13.git cmd/go: don't clobber `go env GOGCCFLAGS` When CC is set in the environment, the mkEnv function sets its version of CC to the first word $CC and sets GOGCCFLAGS to the remainder. That worked since Go 1 but was broken accidentally by https://golang.org/cl/6409, which changed the code such that `go env` calls mkEnv twice. The second call to mkEnv would clobber GOGCCFLAGS based on the value of CC set by the first call. Go back to the old handling by only calling mkEnv once. Fixes #15457. Change-Id: I000a1ebcc48684667e48f2b9b24605867b9e06cd Reviewed-on: https://go-review.googlesource.com/33293 Reviewed-by: Russ Cox --- diff --git a/src/cmd/go/bug.go b/src/cmd/go/bug.go index 5506b3a0ba..2977c94c14 100644 --- a/src/cmd/go/bug.go +++ b/src/cmd/go/bug.go @@ -39,7 +39,7 @@ func runBug(cmd *Command, args []string) { fmt.Fprint(&buf, "#### System details\n\n") fmt.Fprintln(&buf, "```") fmt.Fprintf(&buf, "go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH) - env := mkEnv() + env := newEnv env = append(env, extraEnvVars()...) for _, e := range env { fmt.Fprintf(&buf, "%s=\"%s\"\n", e.name, e.value) diff --git a/src/cmd/go/env.go b/src/cmd/go/env.go index cf614bb356..7de72ef289 100644 --- a/src/cmd/go/env.go +++ b/src/cmd/go/env.go @@ -104,7 +104,7 @@ func extraEnvVars() []envVar { } func runEnv(cmd *Command, args []string) { - env := mkEnv() + env := newEnv env = append(env, extraEnvVars()...) if len(args) > 0 { for _, name := range args { diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 632a1a5e6a..0eef6eef04 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -3586,6 +3586,12 @@ func TestGoEnv(t *testing.T) { tg.setenv("CGO_CFLAGS", "-foobar") tg.run("env", "CGO_CFLAGS") tg.grepStdout("^-foobar$", "CGO_CFLAGS not honored") + + tg.setenv("CC", "gcc -fmust -fgo -ffaster") + tg.run("env", "CC") + tg.grepStdout("gcc", "CC not found") + tg.run("env", "GOGCCFLAGS") + tg.grepStdout("-ffaster", "CC arguments not found") } const ( diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index 27d02924c0..07fc4e2a90 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -115,6 +115,7 @@ func setExitStatus(n int) { } var origEnv []string +var newEnv []envVar func main() { _ = go11tag @@ -164,7 +165,8 @@ func main() { // but in practice there might be skew // This makes sure we all agree. origEnv = os.Environ() - for _, env := range mkEnv() { + newEnv = mkEnv() + for _, env := range newEnv { if os.Getenv(env.name) != env.value { os.Setenv(env.name, env.value) }