Skip to content

Commit

Permalink
all: use cmd.Environ rather than os.Environ
Browse files Browse the repository at this point in the history
Added in Go 1.19, this keeps os/exec's default environment logic,
such as ensuring that $PWD is always set.
  • Loading branch information
mvdan authored and pagran committed Mar 8, 2024
1 parent 52d436d commit 20a9246
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ func BenchmarkBuild(b *testing.B) {
garbleCache := filepath.Join(tdir, "garble-cache")
qt.Assert(b, qt.IsNil(os.RemoveAll(garbleCache)))
qt.Assert(b, qt.IsNil(os.Mkdir(garbleCache, 0o777)))
env := append(os.Environ(),
env := []string{
"RUN_GARBLE_MAIN=true",
"GOCACHE="+goCache,
"GARBLE_CACHE="+garbleCache,
"GOCACHE=" + goCache,
"GARBLE_CACHE=" + garbleCache,
"GARBLE_WRITE_ALLOCS=true",
)
}
args := []string{"build", "-v", "-o=" + outputBin, sourceDir}

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

cmd := exec.Command(os.Args[0], args...)
cmd.Env = env
cmd.Env = append(cmd.Environ(), env...)
cmd.Dir = sourceDir

cachedStart := time.Now()
Expand Down
2 changes: 1 addition & 1 deletion internal/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func buildLinker(workingDir string, overlay map[string]string, outputLinkPath st
// go version -m ~/tip/pkg/tool/linux_amd64/link
//
// and which can be done from Go via debug/buildinfo.ReadFile.
cmd.Env = append(os.Environ(),
cmd.Env = append(cmd.Environ(),
"GOENV=off", "GOOS=", "GOARCH=", "GOEXPERIMENT=", "GOFLAGS=",
)
// Building cmd/link is possible from anywhere, but to avoid any possible side effects build in a temp directory
Expand Down
2 changes: 1 addition & 1 deletion scripts/bench_literals.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func main() {
garbleBin := buildTestGarble(tdir)
args := append([]string{"-seed", garbleSeed, "-literals", "test", "-bench"}, os.Args[1:]...)
cmd := exec.Command(garbleBin, args...)
cmd.Env = append(os.Environ(),
cmd.Env = append(cmd.Environ(),
// Explicitly specify package for obfuscation to avoid affecting testing package.
"GOGARBLE="+moduleName,
"GARBLE_TEST_LITERALS_OBFUSCATOR_MAP="+strings.Join(packageToObfuscatorIndex, ","),
Expand Down

0 comments on commit 20a9246

Please sign in to comment.