]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't clobber `go env GOGCCFLAGS`
authorIan Lance Taylor <iant@golang.org>
Tue, 15 Nov 2016 22:48:54 +0000 (14:48 -0800)
committerIan Lance Taylor <iant@golang.org>
Tue, 22 Nov 2016 04:27:49 +0000 (04:27 +0000)
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 <rsc@golang.org>
src/cmd/go/bug.go
src/cmd/go/env.go
src/cmd/go/go_test.go
src/cmd/go/main.go

index 5506b3a0ba314a969dcdf1f235cf1f8caff2eff1..2977c94c149329f8e689bb14cf39bd169d2b9f2e 100644 (file)
@@ -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)
index cf614bb3569951e67e402b0ff954e8323a863782..7de72ef28970215290aa4dcd6219f4b30c643736 100644 (file)
@@ -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 {
index 632a1a5e6a2e9f5c255df4e8f956ca76fb63adf1..0eef6eef0400053cc491a8a9e80962800980539f 100644 (file)
@@ -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 (
index 27d02924c0ee7d0fada1015eacea3ffbbe7135ce..07fc4e2a9050d836efba2df98be15d40218ed29f 100644 (file)
@@ -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)
                }