From c914e6160db8b6af358cad90ed7272ebc5c22dda Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 16 Apr 2021 21:45:02 -0400 Subject: [PATCH] cmd/go: drop GOEXPERIMENT in script tests TestScript sets the GOEXPERIMENT environment variable to the value of buildcfg.GOEXPERIMENT() with the intent that tests can use this to inspect the value of buildcfg.GOEXPERIMENT. This has the unfortunate side-effect of also affecting the experiments enabled for all builds done by TestScript. For the most part this is harmless, but GOEXPERIMENT can be GOOS/GOARCH-sensitive, so if a test changes GOOS or GOARCH, it will continue to use the GOEXPERIMENT from the host GOOS/GOARCH rather than what makes sense (or is even allowed) in the test's GOOS/GOARCH. In fact, prior to CL 307819, TestScript set GOEXPSTRING instead of GOEXPERIMENT because it previously captured objabi.Expstring(), so the captured value didn't affect the build. There's only one experiment that actually uses TestScript's GOEXPERIMENT and there's a much better way to write that test now such that it doesn't need to read GOEXPERIMENT at all. Hence, this CL rewrites this test and drops GOEXPERIMENT from TestScript. This should fix the *-regabi builders. Change-Id: I3fcbf1f21e1b471ebc0e953c31333645553ea24c Reviewed-on: https://go-review.googlesource.com/c/go/+/310969 Trust: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Go Bot Reviewed-by: David Chase --- src/cmd/go/script_test.go | 2 - src/cmd/go/testdata/script/README | 1 - .../script/build_tag_goexperiment.txt | 93 +++---------------- 3 files changed, 11 insertions(+), 85 deletions(-) diff --git a/src/cmd/go/script_test.go b/src/cmd/go/script_test.go index 87b5971aa7..2274335a75 100644 --- a/src/cmd/go/script_test.go +++ b/src/cmd/go/script_test.go @@ -13,7 +13,6 @@ import ( "errors" "fmt" "go/build" - "internal/buildcfg" "internal/testenv" "io/fs" "os" @@ -165,7 +164,6 @@ func (ts *testScript) setup() { "GOCACHE=" + testGOCACHE, "GODEBUG=" + os.Getenv("GODEBUG"), "GOEXE=" + cfg.ExeSuffix, - "GOEXPERIMENT=" + buildcfg.GOEXPERIMENT(), "GOOS=" + runtime.GOOS, "GOPATH=" + filepath.Join(ts.workdir, "gopath"), "GOPROXY=" + proxyURL, diff --git a/src/cmd/go/testdata/script/README b/src/cmd/go/testdata/script/README index b4dcb1f5a2..d7e67bb7b6 100644 --- a/src/cmd/go/testdata/script/README +++ b/src/cmd/go/testdata/script/README @@ -29,7 +29,6 @@ Scripts also have access to these other environment variables: GOARCH= GOCACHE= GOEXE= - GOEXPERIMENT= GOOS= GOPATH=$WORK/gopath GOPROXY= diff --git a/src/cmd/go/testdata/script/build_tag_goexperiment.txt b/src/cmd/go/testdata/script/build_tag_goexperiment.txt index dfda3d2629..bee218f4c1 100644 --- a/src/cmd/go/testdata/script/build_tag_goexperiment.txt +++ b/src/cmd/go/testdata/script/build_tag_goexperiment.txt @@ -1,83 +1,20 @@ -# compile_ext will fail if the buildtags that are enabled (or not enabled) for the -# framepointer and fieldtrack experiments are not consistent with the value of -# objabi.GOEXPERIMENT. - [short] skip +# Reset all experiments so fieldtrack is definitely off. +env GOEXPERIMENT=none go run m - --- expt_main.go -- -package main - -import ( - "os" - "strings" -) - -func main() { - fp() - ft() -} - -func hasExpEntry(s string) bool { - // script_test.go defines GOEXPERIMENT to be the enabled experiments. - g := os.Getenv("GOEXPERIMENT") - for _, f := range strings.Split(g, ",") { - if f == s { - return true - } - } - return false -} - --- fp_off.go -- -// +build !goexperiment.framepointer - -package main - -import ( - "fmt" - "os" -) - -func fp() { - if hasExpEntry("framepointer") { - fmt.Println("in !framepointer build, but objabi.GOEXPERIMENT has 'framepointer'") - os.Exit(1) - } -} - --- fp_on.go -- -// +build goexperiment.framepointer - -package main - -import ( - "fmt" - "os" -) - -func fp() { - if !hasExpEntry("framepointer") { - fmt.Println("in framepointer build, but objabi.GOEXPERIMENT does not have 'framepointer', is", os.Getenv("GOEXPERIMENT")) - os.Exit(1) - } -} +stderr 'fieldtrack off' +# Turn fieldtrack on. +env GOEXPERIMENT=none,fieldtrack +go run m +stderr 'fieldtrack on' -- ft_off.go -- // +build !goexperiment.fieldtrack package main -import ( - "fmt" - "os" -) - -func ft() { - if hasExpEntry("fieldtrack") { - fmt.Println("in !fieldtrack build, but objabi.GOEXPERIMENT has 'fieldtrack'") - os.Exit(1) - } +func main() { + println("fieldtrack off") } -- ft_on.go -- @@ -85,16 +22,8 @@ func ft() { package main -import ( - "fmt" - "os" -) - -func ft() { - if !hasExpEntry("fieldtrack") { - fmt.Println("in fieldtrack build, but objabi.GOEXPERIMENT does not have 'fieldtrack', is", os.Getenv("GOEXPERIMENT")) - os.Exit(1) - } +func main() { + println("fieldtrack on") } -- go.mod --