From 9fffcde118ee3d2522744661b1af1eafb1008667 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Mon, 24 Oct 2022 19:50:48 -0400 Subject: [PATCH] cmd/go: fix script conditions that require cgo This fixes a regression introduced in CL 419875 that causes features that require cgo to be tested on the nocgo builders. For #27494. Change-Id: Iee61225c98c1275810256ab002a698fc4b42c053 Reviewed-on: https://go-review.googlesource.com/c/go/+/445235 Auto-Submit: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Jonathan Amsterdam Reviewed-by: Cherry Mui --- src/cmd/go/scriptconds_test.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cmd/go/scriptconds_test.go b/src/cmd/go/scriptconds_test.go index 676de3b353..6eb3e0979c 100644 --- a/src/cmd/go/scriptconds_test.go +++ b/src/cmd/go/scriptconds_test.go @@ -34,21 +34,21 @@ func scriptConditions() map[string]script.Cond { return script.OnceCondition(summary, func() (bool, error) { return f(), nil }) } - add("asan", sysCondition("-asan", platform.ASanSupported)) + add("asan", sysCondition("-asan", platform.ASanSupported, true)) add("buildmode", script.PrefixCondition("go supports -buildmode=", hasBuildmode)) add("case-sensitive", script.OnceCondition("$WORK filesystem is case-sensitive", isCaseSensitive)) add("cgo", script.BoolCondition("host CGO_ENABLED", canCgo)) add("cross", script.BoolCondition("cmd/go GOOS/GOARCH != GOHOSTOS/GOHOSTARCH", goHostOS != runtime.GOOS || goHostArch != runtime.GOARCH)) - add("fuzz", sysCondition("-fuzz", platform.FuzzSupported)) - add("fuzz-instrumented", sysCondition("-fuzz with instrumentation", platform.FuzzInstrumented)) + add("fuzz", sysCondition("-fuzz", platform.FuzzSupported, false)) + add("fuzz-instrumented", sysCondition("-fuzz with instrumentation", platform.FuzzInstrumented, false)) add("git", lazyBool("the 'git' executable exists and provides the standard CLI", hasWorkingGit)) add("GODEBUG", script.PrefixCondition("GODEBUG contains ", hasGodebug)) add("GOEXPERIMENT", script.PrefixCondition("GOEXPERIMENT is enabled", hasGoexperiment)) add("link", lazyBool("testenv.HasLink()", testenv.HasLink)) add("mismatched-goroot", script.Condition("test's GOROOT_FINAL does not match the real GOROOT", isMismatchedGoroot)) - add("msan", sysCondition("-msan", platform.MSanSupported)) + add("msan", sysCondition("-msan", platform.MSanSupported, true)) add("net", lazyBool("testenv.HasExternalNetwork()", testenv.HasExternalNetwork)) - add("race", sysCondition("-race", platform.RaceDetectorSupported)) + add("race", sysCondition("-race", platform.RaceDetectorSupported, true)) add("symlink", lazyBool("testenv.HasSymlink()", testenv.HasSymlink)) add("trimpath", script.OnceCondition("test binary was built with -trimpath", isTrimpath)) @@ -63,13 +63,14 @@ func isMismatchedGoroot(s *script.State) (bool, error) { return gorootFinal != testGOROOT, nil } -func sysCondition(flag string, f func(goos, goarch string) bool) script.Cond { +func sysCondition(flag string, f func(goos, goarch string) bool, needsCgo bool) script.Cond { return script.Condition( "GOOS/GOARCH supports "+flag, func(s *script.State) (bool, error) { GOOS, _ := s.LookupEnv("GOOS") GOARCH, _ := s.LookupEnv("GOARCH") - return f(GOOS, GOARCH), nil + cross := goHostOS != GOOS || goHostArch != GOARCH + return (!needsCgo || (canCgo && !cross)) && f(GOOS, GOARCH), nil }) } -- 2.48.1