Commit e9ffda45 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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/33293Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 6f31abd2
...@@ -39,7 +39,7 @@ func runBug(cmd *Command, args []string) { ...@@ -39,7 +39,7 @@ func runBug(cmd *Command, args []string) {
fmt.Fprint(&buf, "#### System details\n\n") fmt.Fprint(&buf, "#### System details\n\n")
fmt.Fprintln(&buf, "```") fmt.Fprintln(&buf, "```")
fmt.Fprintf(&buf, "go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH) fmt.Fprintf(&buf, "go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
env := mkEnv() env := newEnv
env = append(env, extraEnvVars()...) env = append(env, extraEnvVars()...)
for _, e := range env { for _, e := range env {
fmt.Fprintf(&buf, "%s=\"%s\"\n", e.name, e.value) fmt.Fprintf(&buf, "%s=\"%s\"\n", e.name, e.value)
......
...@@ -104,7 +104,7 @@ func extraEnvVars() []envVar { ...@@ -104,7 +104,7 @@ func extraEnvVars() []envVar {
} }
func runEnv(cmd *Command, args []string) { func runEnv(cmd *Command, args []string) {
env := mkEnv() env := newEnv
env = append(env, extraEnvVars()...) env = append(env, extraEnvVars()...)
if len(args) > 0 { if len(args) > 0 {
for _, name := range args { for _, name := range args {
......
...@@ -3586,6 +3586,12 @@ func TestGoEnv(t *testing.T) { ...@@ -3586,6 +3586,12 @@ func TestGoEnv(t *testing.T) {
tg.setenv("CGO_CFLAGS", "-foobar") tg.setenv("CGO_CFLAGS", "-foobar")
tg.run("env", "CGO_CFLAGS") tg.run("env", "CGO_CFLAGS")
tg.grepStdout("^-foobar$", "CGO_CFLAGS not honored") 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 ( const (
......
...@@ -115,6 +115,7 @@ func setExitStatus(n int) { ...@@ -115,6 +115,7 @@ func setExitStatus(n int) {
} }
var origEnv []string var origEnv []string
var newEnv []envVar
func main() { func main() {
_ = go11tag _ = go11tag
...@@ -164,7 +165,8 @@ func main() { ...@@ -164,7 +165,8 @@ func main() {
// but in practice there might be skew // but in practice there might be skew
// This makes sure we all agree. // This makes sure we all agree.
origEnv = os.Environ() origEnv = os.Environ()
for _, env := range mkEnv() { newEnv = mkEnv()
for _, env := range newEnv {
if os.Getenv(env.name) != env.value { if os.Getenv(env.name) != env.value {
os.Setenv(env.name, env.value) os.Setenv(env.name, env.value)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment