From b60f88d81022e4172e44aef2f0bdade87ed6916d Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Mon, 29 Jul 2024 17:40:10 +0000 Subject: cmd/internal/script: new hook for adding in toolchain script conditions Introduce a new function AddToolChainScriptConditions that augments a default "script.Cond" set with a collection of useful conditions, including godebug/goexperiment, cgo, race support, buildmode, asan, msan, and so on. Having these conditions available makes it easier to write script tests that deal with specific build-flavor corner cases. The functions backing the new conditions are helper functions migrated over from the Go command's script test setup. Updates #68606. Change-Id: I14def1115b54dc47529c983abcd2c5ea9326b9de Reviewed-on: https://go-review.googlesource.com/c/go/+/601715 LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui --- src/cmd/internal/script/scripttest/run.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/cmd/internal/script/scripttest/run.go') diff --git a/src/cmd/internal/script/scripttest/run.go b/src/cmd/internal/script/scripttest/run.go index d2f3ed8ca9..29eb6f88f2 100644 --- a/src/cmd/internal/script/scripttest/run.go +++ b/src/cmd/internal/script/scripttest/run.go @@ -71,13 +71,6 @@ func RunToolScriptTest(t *testing.T, repls []ToolReplacement, pattern string) { cmds[name] = cmd } - addcond := func(name string, cond script.Cond) { - if _, ok := conds[name]; ok { - panic(fmt.Sprintf("condition %q is already registered", name)) - } - conds[name] = cond - } - prependToPath := func(env []string, dir string) { found := false for k := range env { @@ -135,7 +128,10 @@ func RunToolScriptTest(t *testing.T, repls []ToolReplacement, pattern string) { cccmd := script.Program(goEnv("CC"), interrupt, gracePeriod) addcmd("go", gocmd) addcmd("cc", cccmd) - addcond("cgo", script.BoolCondition("host CGO_ENABLED", testenv.HasCGO())) + + // Add various helpful conditions related to builds and toolchain use. + goHostOS, goHostArch := goEnv("GOHOSTOS"), goEnv("GOHOSTARCH") + AddToolChainScriptConditions(t, conds, goHostOS, goHostArch) // Environment setup. env := os.Environ() -- cgit v1.3