Skip to content

Commit 956c81b

Browse files
committed
cmd/go: add GOEXPERIMENT to go env output
This CL adds GOEXPERIMENT to `go env` output, and also makes it configurable via `GOENV`. Thanks to Baokun Lee's CL 304350 for the test and initial work on this. Fixes #45226. Change-Id: Ie7f92a8a503b6a2a4df3f6598f0b2bf2915e2e7d Reviewed-on: https://go-review.googlesource.com/c/go/+/328751 Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Trust: Bryan C. Mills <[email protected]> Trust: Matthew Dempsky <[email protected]>
1 parent a1d2726 commit 956c81b

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-0
lines changed

src/cmd/go/alldocs.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/envcmd/env.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func MkEnv() []cfg.EnvVar {
7373
{Name: "GOCACHE", Value: cache.DefaultDir()},
7474
{Name: "GOENV", Value: envFile},
7575
{Name: "GOEXE", Value: cfg.ExeSuffix},
76+
{Name: "GOEXPERIMENT", Value: buildcfg.GOEXPERIMENT()},
7677
{Name: "GOFLAGS", Value: cfg.Getenv("GOFLAGS")},
7778
{Name: "GOHOSTARCH", Value: runtime.GOARCH},
7879
{Name: "GOHOSTOS", Value: runtime.GOOS},
@@ -364,6 +365,13 @@ func checkBuildConfig(add map[string]string, del map[string]bool) error {
364365
}
365366
}
366367

368+
goexperiment, okGOEXPERIMENT := get("GOEXPERIMENT", buildcfg.GOEXPERIMENT(), "")
369+
if okGOEXPERIMENT {
370+
if _, _, err := buildcfg.ParseGOEXPERIMENT(goos, goarch, goexperiment); err != nil {
371+
return err
372+
}
373+
}
374+
367375
return nil
368376
}
369377

src/cmd/go/internal/help/helpdoc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,12 @@ Special-purpose environment variables:
610610
GCCGOTOOLDIR
611611
If set, where to find gccgo tools, such as cgo.
612612
The default is based on how gccgo was configured.
613+
GOEXPERIMENT
614+
Comma-separated list of toolchain experiments to enable or disable.
615+
The list of available experiments may change arbitrarily over time.
616+
See src/internal/goexperiment/flags.go for currently valid values.
617+
Warning: This variable is provided for the development and testing
618+
of the Go toolchain itself. Use beyond that purpose is unsupported.
613619
GOROOT_FINAL
614620
The root of the installed Go tree, when it is
615621
installed in a location other than where it is built.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Test GOEXPERIMENT variable
2+
3+
# go env shows default empty GOEXPERIMENT
4+
go env
5+
stdout GOEXPERIMENT=
6+
7+
# go env shows valid experiments
8+
env GOEXPERIMENT=fieldtrack,staticlockranking
9+
go env GOEXPERIMENT
10+
stdout '.*fieldtrack.*staticlockranking.*'
11+
go env
12+
stdout 'GOEXPERIMENT=.*fieldtrack.*staticlockranking.*'
13+
14+
# go env rejects unknown experiments
15+
env GOEXPERIMENT=bad
16+
! go env GOEXPERIMENT
17+
stderr 'unknown GOEXPERIMENT bad'

src/cmd/go/testdata/script/env_unset.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
env GOENV=badenv
55
env GOOS=
66
env GOARCH=
7+
env GOEXPERIMENT=
8+
9+
! go env
10+
stderr '^go(\.exe)?: unknown GOEXPERIMENT badexp$'
11+
12+
go env -u GOEXPERIMENT
713

814
! go env
915
stderr '^cmd/go: unsupported GOOS/GOARCH pair bados/badarch$'
@@ -21,3 +27,4 @@ go env
2127
-- badenv --
2228
GOOS=bados
2329
GOARCH=badarch
30+
GOEXPERIMENT=badexp

src/cmd/go/testdata/script/env_write.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,9 @@ stderr 'unsupported GOOS/GOARCH.*windows/mips$'
179179
stderr 'go env -w: GOMODCACHE entry is relative; must be absolute path: "~/test"'
180180
! go env -w GOMODCACHE=./test
181181
stderr 'go env -w: GOMODCACHE entry is relative; must be absolute path: "./test"'
182+
183+
# go env -w checks validity of GOEXPERIMENT
184+
env GOEXPERIMENT=
185+
! go env -w GOEXPERIMENT=badexp
186+
stderr 'unknown GOEXPERIMENT badexp'
187+
go env -w GOEXPERIMENT=fieldtrack

0 commit comments

Comments
 (0)