]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix script conditions that require cgo
authorBryan C. Mills <bcmills@google.com>
Mon, 24 Oct 2022 23:50:48 +0000 (19:50 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 25 Oct 2022 00:18:38 +0000 (00:18 +0000)
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 <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/go/scriptconds_test.go

index 676de3b353ddd42f726fd47efb953e899bca828a..6eb3e0979c629e6773080f1e1e055d3e8fc7b1a1 100644 (file)
@@ -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=<suffix>", 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 <suffix>", hasGodebug))
        add("GOEXPERIMENT", script.PrefixCondition("GOEXPERIMENT <suffix> 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
                })
 }