Skip to content

Commit c196d38

Browse files
4a6f656cianlancetaylor
authored andcommitted
cmd/dist: pass cgotest linkmode via GOFLAGS
cgotest attempts to exercise various linkmodes, however with recent refactoring TestCrossPackageTests is no longer running tests with these linkmodes. Specifying the linkmode via GOFLAGS restores previous behaviour. Note that the -ldflags="-linkmode=external -s" case cannot be passed through as GOFLAGS does not permit spaces in values and -ldflags can only be specified once. Fixes #31083. Change-Id: I2ce6c60da3f3d60495af283ea9122fb68a7a4f41 Reviewed-on: https://go-review.googlesource.com/c/go/+/169779 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent b2f19da commit c196d38

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/cmd/dist/test.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -1002,10 +1002,12 @@ func (t *tester) runHostTest(dir, pkg string) error {
10021002
}
10031003

10041004
func (t *tester) cgoTest(dt *distTest) error {
1005-
t.addCmd(dt, "misc/cgo/test", t.goTest(), "-ldflags", "-linkmode=auto")
1005+
cmd := t.addCmd(dt, "misc/cgo/test", t.goTest())
1006+
cmd.Env = append(os.Environ(), "GOFLAGS=-ldflags=-linkmode=auto")
10061007

10071008
if t.internalLink() {
1008-
t.addCmd(dt, "misc/cgo/test", t.goTest(), "-tags=internal", "-ldflags", "-linkmode=internal")
1009+
cmd := t.addCmd(dt, "misc/cgo/test", t.goTest(), "-tags=internal")
1010+
cmd.Env = append(os.Environ(), "GOFLAGS=-ldflags=-linkmode=internal")
10091011
}
10101012

10111013
pair := gohostos + "-" + goarch
@@ -1017,18 +1019,22 @@ func (t *tester) cgoTest(dt *distTest) error {
10171019
if !t.extLink() {
10181020
break
10191021
}
1020-
t.addCmd(dt, "misc/cgo/test", t.goTest(), "-ldflags", "-linkmode=external")
1021-
t.addCmd(dt, "misc/cgo/test", t.goTest(), "-ldflags", "-linkmode=external -s")
1022+
cmd := t.addCmd(dt, "misc/cgo/test", t.goTest())
1023+
cmd.Env = append(os.Environ(), "GOFLAGS=-ldflags=-linkmode=external")
1024+
1025+
cmd = t.addCmd(dt, "misc/cgo/test", t.goTest(), "-ldflags", "-linkmode=external -s")
1026+
10221027
case "aix-ppc64",
10231028
"android-arm",
10241029
"dragonfly-amd64",
10251030
"freebsd-386", "freebsd-amd64", "freebsd-arm",
10261031
"linux-386", "linux-amd64", "linux-arm", "linux-ppc64le", "linux-s390x",
10271032
"netbsd-386", "netbsd-amd64":
10281033

1029-
cmd := t.addCmd(dt, "misc/cgo/test", t.goTest(), "-ldflags", "-linkmode=external")
1034+
cmd := t.addCmd(dt, "misc/cgo/test", t.goTest())
1035+
cmd.Env = append(os.Environ(), "GOFLAGS=-ldflags=-linkmode=external")
10301036
// A -g argument in CGO_CFLAGS should not affect how the test runs.
1031-
cmd.Env = append(os.Environ(), "CGO_CFLAGS=-g0")
1037+
cmd.Env = append(cmd.Env, "CGO_CFLAGS=-g0")
10321038

10331039
t.addCmd(dt, "misc/cgo/testtls", t.goTest(), "-ldflags", "-linkmode=auto")
10341040
t.addCmd(dt, "misc/cgo/testtls", t.goTest(), "-ldflags", "-linkmode=external")

0 commit comments

Comments
 (0)