Skip to content

Commit e0ba7e1

Browse files
Bryan C. Millsjproberts
Bryan C. Mills
authored andcommitted
misc/cgo/testcarchive: don't rely on an erroneous install target in tests
Non-main packages in module mode should not be installed to GOPATH/pkg, but due to golang#37015 they were installed there anyway. This change switches the 'go install' command in TestPIE to instead use 'go build', and switches TestInstall and TestCachedInstall (which appear to be explicitly testing 'go install') to explicitly request GOPATH mode (which does have a well-defined install target). For golang#37015. Change-Id: Ifb24657d2781d1e35cf40078e8e3ebf56aab9cc8 Reviewed-on: https://go-review.googlesource.com/c/go/+/416954 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent daaf947 commit e0ba7e1

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

misc/cgo/testcarchive/carchive_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ func genHeader(t *testing.T, header, dir string) {
205205
func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) {
206206
t.Helper()
207207
cmd := exec.Command(buildcmd[0], buildcmd[1:]...)
208+
cmd.Env = append(cmd.Environ(), "GO111MODULE=off") // 'go install' only works in GOPATH mode
208209
t.Log(buildcmd)
209210
if out, err := cmd.CombinedOutput(); err != nil {
210211
t.Logf("%s", out)
@@ -238,7 +239,7 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) {
238239
binArgs := append(cmdToRun(exe), "arg1", "arg2")
239240
cmd = exec.Command(binArgs[0], binArgs[1:]...)
240241
if runtime.Compiler == "gccgo" {
241-
cmd.Env = append(os.Environ(), "GCCGO=1")
242+
cmd.Env = append(cmd.Environ(), "GCCGO=1")
242243
}
243244
if out, err := cmd.CombinedOutput(); err != nil {
244245
t.Logf("%s", out)
@@ -822,9 +823,15 @@ func TestPIE(t *testing.T) {
822823
t.Skipf("skipping PIE test on %s", GOOS)
823824
}
824825

826+
libgoa := "libgo.a"
827+
if runtime.Compiler == "gccgo" {
828+
libgoa = "liblibgo.a"
829+
}
830+
825831
if !testWork {
826832
defer func() {
827833
os.Remove("testp" + exeSuffix)
834+
os.Remove(libgoa)
828835
os.RemoveAll(filepath.Join(GOPATH, "pkg"))
829836
}()
830837
}
@@ -837,18 +844,13 @@ func TestPIE(t *testing.T) {
837844
// be running this test in a GOROOT owned by root.)
838845
genHeader(t, "p.h", "./p")
839846

840-
cmd := exec.Command("go", "install", "-buildmode=c-archive", "./libgo")
847+
cmd := exec.Command("go", "build", "-buildmode=c-archive", "./libgo")
841848
if out, err := cmd.CombinedOutput(); err != nil {
842849
t.Logf("%s", out)
843850
t.Fatal(err)
844851
}
845852

846-
libgoa := "libgo.a"
847-
if runtime.Compiler == "gccgo" {
848-
libgoa = "liblibgo.a"
849-
}
850-
851-
ccArgs := append(cc, "-fPIE", "-pie", "-o", "testp"+exeSuffix, "main.c", "main_unix.c", filepath.Join(libgodir, libgoa))
853+
ccArgs := append(cc, "-fPIE", "-pie", "-o", "testp"+exeSuffix, "main.c", "main_unix.c", libgoa)
852854
if runtime.Compiler == "gccgo" {
853855
ccArgs = append(ccArgs, "-lgo")
854856
}
@@ -1035,6 +1037,7 @@ func TestCachedInstall(t *testing.T) {
10351037
buildcmd := []string{"go", "install", "-buildmode=c-archive", "./libgo"}
10361038

10371039
cmd := exec.Command(buildcmd[0], buildcmd[1:]...)
1040+
cmd.Env = append(cmd.Environ(), "GO111MODULE=off") // 'go install' only works in GOPATH mode
10381041
t.Log(buildcmd)
10391042
if out, err := cmd.CombinedOutput(); err != nil {
10401043
t.Logf("%s", out)
@@ -1050,6 +1053,7 @@ func TestCachedInstall(t *testing.T) {
10501053
}
10511054

10521055
cmd = exec.Command(buildcmd[0], buildcmd[1:]...)
1056+
cmd.Env = append(cmd.Environ(), "GO111MODULE=off")
10531057
t.Log(buildcmd)
10541058
if out, err := cmd.CombinedOutput(); err != nil {
10551059
t.Logf("%s", out)

0 commit comments

Comments
 (0)