mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd: ensure that GOPATH is always valid in subprocesses that execute 'go build'
GOPATH/pkg contains, among other things, the module cache (and associated lockfiles). Fixes #30776 Change-Id: I305cb3c0daab8cedd2e6ad235d4733f66af18723 Reviewed-on: https://go-review.googlesource.com/c/go/+/167082 Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
49448badb6
commit
334e750917
4 changed files with 7 additions and 3 deletions
|
|
@ -82,6 +82,7 @@ func TestMain(m *testing.M) {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
os.Setenv("GOPATH", filepath.Join(dir, "_gopath"))
|
||||||
|
|
||||||
testTempDir = dir
|
testTempDir = dir
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,8 @@ func objdumpOutput(t *testing.T) []byte {
|
||||||
testenv.GoToolPath(t), "build", "-o",
|
testenv.GoToolPath(t), "build", "-o",
|
||||||
filepath.Join(tmpdir, "output"))
|
filepath.Join(tmpdir, "output"))
|
||||||
|
|
||||||
cmd.Env = append(os.Environ(), "GOARCH=amd64", "GOOS=linux")
|
cmd.Env = append(os.Environ(),
|
||||||
|
"GOARCH=amd64", "GOOS=linux", "GOPATH="+filepath.Join(tmpdir, "_gopath"))
|
||||||
cmd.Dir = tmpdir
|
cmd.Dir = tmpdir
|
||||||
|
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,8 @@ func asmOutput(t *testing.T, s string) []byte {
|
||||||
testenv.GoToolPath(t), "tool", "asm", "-S", "-dynlink",
|
testenv.GoToolPath(t), "tool", "asm", "-S", "-dynlink",
|
||||||
"-o", filepath.Join(tmpdir, "output.6"), tmpfile.Name())
|
"-o", filepath.Join(tmpdir, "output.6"), tmpfile.Name())
|
||||||
|
|
||||||
cmd.Env = append(os.Environ(), "GOARCH=amd64", "GOOS=linux")
|
cmd.Env = append(os.Environ(),
|
||||||
|
"GOARCH=amd64", "GOOS=linux", "GOPATH="+filepath.Join(tmpdir, "_gopath"))
|
||||||
asmout, err := cmd.CombinedOutput()
|
asmout, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error %s output %s", err, asmout)
|
t.Fatalf("error %s output %s", err, asmout)
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,8 @@ TEXT ·x(SB),0,$0
|
||||||
`)
|
`)
|
||||||
cmd := exec.Command(testenv.GoToolPath(t), "build")
|
cmd := exec.Command(testenv.GoToolPath(t), "build")
|
||||||
cmd.Dir = tmpdir
|
cmd.Dir = tmpdir
|
||||||
cmd.Env = append(os.Environ(), []string{"GOARCH=amd64", "GOOS=linux"}...)
|
cmd.Env = append(os.Environ(),
|
||||||
|
"GOARCH=amd64", "GOOS=linux", "GOPATH="+filepath.Join(tmpdir, "_gopath"))
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected build to fail, but it succeeded")
|
t.Fatalf("expected build to fail, but it succeeded")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue