Skip to content

Commit

Permalink
cmd/go: don't clobber go env GOGCCFLAGS
Browse files Browse the repository at this point in the history
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 golang#15457.

Change-Id: I000a1ebcc48684667e48f2b9b24605867b9e06cd
Reviewed-on: https://go-review.googlesource.com/33293
Reviewed-by: Russ Cox <[email protected]>
  • Loading branch information
ianlancetaylor committed Nov 22, 2016
1 parent 6f31abd commit e9ffda4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cmd/go/bug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/cmd/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func setExitStatus(n int) {
}

var origEnv []string
var newEnv []envVar

func main() {
_ = go11tag
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit e9ffda4

Please sign in to comment.