Skip to content

Commit 20a9246

Browse files
mvdanpagran
authored andcommitted
all: use cmd.Environ rather than os.Environ
Added in Go 1.19, this keeps os/exec's default environment logic, such as ensuring that $PWD is always set.
1 parent 52d436d commit 20a9246

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

bench_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ func BenchmarkBuild(b *testing.B) {
7979
garbleCache := filepath.Join(tdir, "garble-cache")
8080
qt.Assert(b, qt.IsNil(os.RemoveAll(garbleCache)))
8181
qt.Assert(b, qt.IsNil(os.Mkdir(garbleCache, 0o777)))
82-
env := append(os.Environ(),
82+
env := []string{
8383
"RUN_GARBLE_MAIN=true",
84-
"GOCACHE="+goCache,
85-
"GARBLE_CACHE="+garbleCache,
84+
"GOCACHE=" + goCache,
85+
"GARBLE_CACHE=" + garbleCache,
8686
"GARBLE_WRITE_ALLOCS=true",
87-
)
87+
}
8888
args := []string{"build", "-v", "-o=" + outputBin, sourceDir}
8989

9090
for _, cached := range []bool{false, true} {
@@ -95,7 +95,7 @@ func BenchmarkBuild(b *testing.B) {
9595
}
9696

9797
cmd := exec.Command(os.Args[0], args...)
98-
cmd.Env = env
98+
cmd.Env = append(cmd.Environ(), env...)
9999
cmd.Dir = sourceDir
100100

101101
cachedStart := time.Now()

internal/linker/linker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func buildLinker(workingDir string, overlay map[string]string, outputLinkPath st
196196
// go version -m ~/tip/pkg/tool/linux_amd64/link
197197
//
198198
// and which can be done from Go via debug/buildinfo.ReadFile.
199-
cmd.Env = append(os.Environ(),
199+
cmd.Env = append(cmd.Environ(),
200200
"GOENV=off", "GOOS=", "GOARCH=", "GOEXPERIMENT=", "GOFLAGS=",
201201
)
202202
// Building cmd/link is possible from anywhere, but to avoid any possible side effects build in a temp directory

scripts/bench_literals.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func main() {
142142
garbleBin := buildTestGarble(tdir)
143143
args := append([]string{"-seed", garbleSeed, "-literals", "test", "-bench"}, os.Args[1:]...)
144144
cmd := exec.Command(garbleBin, args...)
145-
cmd.Env = append(os.Environ(),
145+
cmd.Env = append(cmd.Environ(),
146146
// Explicitly specify package for obfuscation to avoid affecting testing package.
147147
"GOGARBLE="+moduleName,
148148
"GARBLE_TEST_LITERALS_OBFUSCATOR_MAP="+strings.Join(packageToObfuscatorIndex, ","),

0 commit comments

Comments
 (0)