aboutsummaryrefslogtreecommitdiff
path: root/test/run.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2021-04-14 13:25:31 -0400
committerRuss Cox <rsc@golang.org>2021-04-16 03:16:55 +0000
commitd26fc68aa10dc8eda5ccdcc80d790e7df2fd9823 (patch)
tree13fa355e29d55de5b536f56fa85e4073a0a00025 /test/run.go
parentcf2396c70e7213570c69ca155203c25c960cc10c (diff)
downloadgo-d26fc68aa10dc8eda5ccdcc80d790e7df2fd9823.tar.gz
go-d26fc68aa10dc8eda5ccdcc80d790e7df2fd9823.zip
cmd/internal/objabi,test: use correct GOEXPERIMENT build tags in test/run.go
Currently, run.go sets GOEXPERIMENT build tags based on the *difference* from the baseline experiment configuration, rather than the absolute experiment configuration. This differs from cmd/go. As a result, if we set a baseline configuration and don't override it with a GOEXPERIMENT setting, run.go won't set any GOEXPERIMENT build tags, instead of setting the tags corresponding to the baseline configuration. Fix this by making compile -V=goexperiment produce the full GOEXPERIMENT configuration, which run.go can then use to set exactly the right set of build tags. For #40724. Change-Id: Ieda6ea62f1a1fabbe8d749d6d09c198fd5ca8377 Reviewed-on: https://go-review.googlesource.com/c/go/+/310171 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'test/run.go')
-rw-r--r--test/run.go35
1 files changed, 19 insertions, 16 deletions
diff --git a/test/run.go b/test/run.go
index feab88338c..feec2b50be 100644
--- a/test/run.go
+++ b/test/run.go
@@ -376,6 +376,7 @@ type context struct {
GOARCH string
cgoEnabled bool
noOptEnv bool
+ expTags map[string]bool // Set lazily
}
// shouldTest looks for build tags in a source file and returns
@@ -445,26 +446,28 @@ func (ctxt *context) match(name string) bool {
}
}
- exp := os.Getenv("GOEXPERIMENT")
- if exp == "" {
- // If GOEXPERIMENT environment variable is unset, get the default value
- // that is baked into the toolchain.
- cmd := exec.Command(goTool(), "tool", "compile", "-V")
- out, err := cmd.CombinedOutput()
- if err == nil {
+ if strings.HasPrefix(name, "goexperiment.") {
+ // Query goexperiment tags from the toolchain.
+ if ctxt.expTags == nil {
+ ctxt.expTags = make(map[string]bool)
+ cmd := exec.Command(goTool(), "tool", "compile", "-V=goexperiment")
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ log.Fatalf("failed to get GOEXPERIMENT configuration:\n%s", out)
+ }
i := bytes.Index(out, []byte("X:"))
if i != -1 {
- exp = string(out[i+2:])
- }
- }
- }
- if exp != "" {
- experiments := strings.Split(exp, ",")
- for _, e := range experiments {
- if name == "goexperiment."+e {
- return true
+ for _, exp := range strings.Split(string(out[i+2:]), ",") {
+ v := true
+ if strings.HasPrefix(exp, "no") {
+ v, exp = false, exp[2:]
+ }
+ ctxt.expTags["goexperiment."+exp] = v
+ }
}
}
+
+ return ctxt.expTags[name]
}
if name == "cgo" && ctxt.cgoEnabled {