From f71f3d1b861de2fcc907221931cf13679c0092dd Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 12 Jul 2022 14:41:33 -0400 Subject: [PATCH] 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 Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Auto-Submit: Bryan Mills --- misc/cgo/testshared/shared_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/misc/cgo/testshared/shared_test.go b/misc/cgo/testshared/shared_test.go index 024f084da55195..756c4baa6b3a7f 100644 --- a/misc/cgo/testshared/shared_test.go +++ b/misc/cgo/testshared/shared_test.go @@ -108,6 +108,15 @@ func testMain(m *testing.M) (int, error) { defer os.RemoveAll(workDir) } + // -buildmode=shared fundamentally does not work in module mode. + // (It tries to share package dependencies across builds, but in module mode + // each module has its own distinct set of dependency versions.) + // We would like to eliminate it (see https://go.dev/issue/47788), + // but first need to figure out a replacement that covers the small subset + // of use-cases where -buildmode=shared still works today. + // For now, run the tests in GOPATH mode only. + os.Setenv("GO111MODULE", "off") + // Some tests need to edit the source in GOPATH, so copy this directory to a // temporary directory and chdir to that. gopath := filepath.Join(workDir, "gopath")