From 824b0a34b7b4fbda1de9f5dbb39c3b33458bc541 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 21 Apr 2022 11:17:16 -0400 Subject: [PATCH] cmd/go: replace some calls to base.AppendPWD with cmd.Environ With #50599 implemented, base.AppendPWD is redundant if cmd.Env would otherwise be nil, and calls to os.Environ followed by base.AppendPWD can be replaced by a simpler call to cmd.Environ. Updates #50599. Change-Id: I94a22e2a4cc8e83c815ac41702ea0b1ee5034ecc Reviewed-on: https://go-review.googlesource.com/c/go/+/401534 Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/cmd/go/internal/vcs/vcs.go | 2 -- src/cmd/go/internal/work/exec.go | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/cmd/go/internal/vcs/vcs.go b/src/cmd/go/internal/vcs/vcs.go index 77208ab7626..7dbcfb7cc48 100644 --- a/src/cmd/go/internal/vcs/vcs.go +++ b/src/cmd/go/internal/vcs/vcs.go @@ -22,7 +22,6 @@ import ( "sync" "time" - "cmd/go/internal/base" "cmd/go/internal/cfg" "cmd/go/internal/search" "cmd/go/internal/str" @@ -657,7 +656,6 @@ func (v *Cmd) run1(dir string, cmdline string, keyval []string, verbose bool) ([ cmd := exec.Command(v.Cmd, args...) cmd.Dir = dir - cmd.Env = base.AppendPWD(os.Environ(), cmd.Dir) if cfg.BuildX { fmt.Fprintf(os.Stderr, "cd %s\n", dir) fmt.Fprintf(os.Stderr, "%s %s\n", v.Cmd, strings.Join(args, " ")) diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index f0e6c800298..0b8e5d2330e 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -2116,11 +2116,10 @@ func (b *Builder) runOut(a *Action, dir string, env []string, cmdargs ...any) ([ cmd.Stderr = &buf cleanup := passLongArgsInResponseFiles(cmd) defer cleanup() - cmd.Env = os.Environ() if dir != "." { cmd.Dir = dir - cmd.Env = base.AppendPWD(cmd.Env, dir) } + cmd.Env = cmd.Environ() // Pre-allocate with correct PWD. // Add the TOOLEXEC_IMPORTPATH environment variable for -toolexec tools. // It doesn't really matter if -toolexec isn't being used. @@ -2609,8 +2608,7 @@ func (b *Builder) gccSupportsFlag(compiler []string, flag string) bool { } cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) cmd.Dir = b.WorkDir - cmd.Env = base.AppendPWD(os.Environ(), cmd.Dir) - cmd.Env = append(cmd.Env, "LC_ALL=C") + cmd.Env = append(cmd.Environ(), "LC_ALL=C") out, _ := cmd.CombinedOutput() // GCC says "unrecognized command line option". // clang says "unknown argument".