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.
pull/846/head
Daniel Martí 2 months ago committed by pagran
parent 52d436d38a
commit 20a92460d5

@ -79,12 +79,12 @@ func BenchmarkBuild(b *testing.B) {
garbleCache := filepath.Join(tdir, "garble-cache") garbleCache := filepath.Join(tdir, "garble-cache")
qt.Assert(b, qt.IsNil(os.RemoveAll(garbleCache))) qt.Assert(b, qt.IsNil(os.RemoveAll(garbleCache)))
qt.Assert(b, qt.IsNil(os.Mkdir(garbleCache, 0o777))) qt.Assert(b, qt.IsNil(os.Mkdir(garbleCache, 0o777)))
env := append(os.Environ(), env := []string{
"RUN_GARBLE_MAIN=true", "RUN_GARBLE_MAIN=true",
"GOCACHE="+goCache, "GOCACHE=" + goCache,
"GARBLE_CACHE="+garbleCache, "GARBLE_CACHE=" + garbleCache,
"GARBLE_WRITE_ALLOCS=true", "GARBLE_WRITE_ALLOCS=true",
) }
args := []string{"build", "-v", "-o=" + outputBin, sourceDir} args := []string{"build", "-v", "-o=" + outputBin, sourceDir}
for _, cached := range []bool{false, true} { for _, cached := range []bool{false, true} {
@ -95,7 +95,7 @@ func BenchmarkBuild(b *testing.B) {
} }
cmd := exec.Command(os.Args[0], args...) cmd := exec.Command(os.Args[0], args...)
cmd.Env = env cmd.Env = append(cmd.Environ(), env...)
cmd.Dir = sourceDir cmd.Dir = sourceDir
cachedStart := time.Now() cachedStart := time.Now()

@ -196,7 +196,7 @@ func buildLinker(workingDir string, overlay map[string]string, outputLinkPath st
// go version -m ~/tip/pkg/tool/linux_amd64/link // go version -m ~/tip/pkg/tool/linux_amd64/link
// //
// and which can be done from Go via debug/buildinfo.ReadFile. // 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=", "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 // Building cmd/link is possible from anywhere, but to avoid any possible side effects build in a temp directory

@ -142,7 +142,7 @@ func main() {
garbleBin := buildTestGarble(tdir) garbleBin := buildTestGarble(tdir)
args := append([]string{"-seed", garbleSeed, "-literals", "test", "-bench"}, os.Args[1:]...) args := append([]string{"-seed", garbleSeed, "-literals", "test", "-bench"}, os.Args[1:]...)
cmd := exec.Command(garbleBin, args...) 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. // Explicitly specify package for obfuscation to avoid affecting testing package.
"GOGARBLE="+moduleName, "GOGARBLE="+moduleName,
"GARBLE_TEST_LITERALS_OBFUSCATOR_MAP="+strings.Join(packageToObfuscatorIndex, ","), "GARBLE_TEST_LITERALS_OBFUSCATOR_MAP="+strings.Join(packageToObfuscatorIndex, ","),

Loading…
Cancel
Save