Skip to content

Commit f71f3d1

Browse files
Bryan C. Millsgopherbot
authored andcommitted
misc/cgo/testshared: run tests only in GOPATH mode
-buildmode=shared installs shared libraries into GOROOT and expects to reuse them across builds. Builds in module mode, however, each have their own set of dependencies (determined by the module's requirements), so in general cannot share dependencies with a single GOROOT. Ideally in the long term we would like to eliminate -buildmode=shared entirely (see #47788), but first we need a replacement for the subset of use-cases where it still works today. In the meantime, we should run these tests only in GOPATH mode. Non-main packages in module mode should not be installed to GOPATH/pkg, but due to #37015 they were installed there anyway, and this test heavily relies on installing non-main packages. For #37015. Change-Id: I7c5d90b4075d6f33e3505d6a8f12752309ae5c03 Reviewed-on: https://go-review.googlesource.com/c/go/+/417194 Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Bryan Mills <[email protected]>
1 parent feada53 commit f71f3d1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

misc/cgo/testshared/shared_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ func testMain(m *testing.M) (int, error) {
108108
defer os.RemoveAll(workDir)
109109
}
110110

111+
// -buildmode=shared fundamentally does not work in module mode.
112+
// (It tries to share package dependencies across builds, but in module mode
113+
// each module has its own distinct set of dependency versions.)
114+
// We would like to eliminate it (see https://go.dev/issue/47788),
115+
// but first need to figure out a replacement that covers the small subset
116+
// of use-cases where -buildmode=shared still works today.
117+
// For now, run the tests in GOPATH mode only.
118+
os.Setenv("GO111MODULE", "off")
119+
111120
// Some tests need to edit the source in GOPATH, so copy this directory to a
112121
// temporary directory and chdir to that.
113122
gopath := filepath.Join(workDir, "gopath")

0 commit comments

Comments
 (0)