internal/buildcfg: change GOEXPERIMENT to always return non-empty string

Rather than returning "", we now return "," (which is a no-op). This
ensures that the returned string always overrides DefaultGOEXPERIMENT.

This fixes a bootstrapping issue where GOROOT_BOOTSTRAP was built with
"GOEXPERIMENT=fieldtrack ./make.bash". cmd/dist sets GOEXPERIMENT=none
during bootstrapping, which was causing cmd/go to set GOEXPERIMENT=""
when executing cmd/compile; but then cmd/compile ignores the
environment variable (because it's empty) and instead uses
DefaultGOEXPERIMENT.

Fixes #47921.

Change-Id: I657ff6cdfb294a94f6a2f58c306ceed7f104416b
Reviewed-on: https://go-review.googlesource.com/c/go/+/344511
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Matthew Dempsky 2021-08-23 11:40:56 -07:00
parent 0a7f00ae23
commit fa34678c67

View file

@ -158,7 +158,11 @@ func expList(exp, base *goexperiment.Flags, all bool) []string {
// GOEXPERIMENT is exactly what a user would set on the command line
// to get the set of enabled experiments.
func GOEXPERIMENT() string {
return strings.Join(expList(&Experiment, &experimentBaseline, false), ",")
goexp := strings.Join(expList(&Experiment, &experimentBaseline, false), ",")
if goexp == "" && DefaultGOEXPERIMENT != "" {
goexp = "," // non-empty to override DefaultGOEXPERIMENT
}
return goexp
}
// EnabledExperiments returns a list of enabled experiments, as