mirror of
https://github.com/golang/go
synced 2024-11-26 14:56:47 -07:00
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 <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Bryan C. Mills <bcmills@google.com> Trust: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
a1d27269d6
commit
956c81bfe6
@ -1903,6 +1903,12 @@
|
|||||||
// GCCGOTOOLDIR
|
// GCCGOTOOLDIR
|
||||||
// If set, where to find gccgo tools, such as cgo.
|
// If set, where to find gccgo tools, such as cgo.
|
||||||
// The default is based on how gccgo was configured.
|
// The default is based on how gccgo was configured.
|
||||||
|
// GOEXPERIMENT
|
||||||
|
// Comma-separated list of toolchain experiments to enable or disable.
|
||||||
|
// The list of available experiments may change arbitrarily over time.
|
||||||
|
// See src/internal/goexperiment/flags.go for currently valid values.
|
||||||
|
// Warning: This variable is provided for the development and testing
|
||||||
|
// of the Go toolchain itself. Use beyond that purpose is unsupported.
|
||||||
// GOROOT_FINAL
|
// GOROOT_FINAL
|
||||||
// The root of the installed Go tree, when it is
|
// The root of the installed Go tree, when it is
|
||||||
// installed in a location other than where it is built.
|
// installed in a location other than where it is built.
|
||||||
|
@ -73,6 +73,7 @@ func MkEnv() []cfg.EnvVar {
|
|||||||
{Name: "GOCACHE", Value: cache.DefaultDir()},
|
{Name: "GOCACHE", Value: cache.DefaultDir()},
|
||||||
{Name: "GOENV", Value: envFile},
|
{Name: "GOENV", Value: envFile},
|
||||||
{Name: "GOEXE", Value: cfg.ExeSuffix},
|
{Name: "GOEXE", Value: cfg.ExeSuffix},
|
||||||
|
{Name: "GOEXPERIMENT", Value: buildcfg.GOEXPERIMENT()},
|
||||||
{Name: "GOFLAGS", Value: cfg.Getenv("GOFLAGS")},
|
{Name: "GOFLAGS", Value: cfg.Getenv("GOFLAGS")},
|
||||||
{Name: "GOHOSTARCH", Value: runtime.GOARCH},
|
{Name: "GOHOSTARCH", Value: runtime.GOARCH},
|
||||||
{Name: "GOHOSTOS", Value: runtime.GOOS},
|
{Name: "GOHOSTOS", Value: runtime.GOOS},
|
||||||
@ -364,6 +365,13 @@ func checkBuildConfig(add map[string]string, del map[string]bool) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
goexperiment, okGOEXPERIMENT := get("GOEXPERIMENT", buildcfg.GOEXPERIMENT(), "")
|
||||||
|
if okGOEXPERIMENT {
|
||||||
|
if _, _, err := buildcfg.ParseGOEXPERIMENT(goos, goarch, goexperiment); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,6 +610,12 @@ Special-purpose environment variables:
|
|||||||
GCCGOTOOLDIR
|
GCCGOTOOLDIR
|
||||||
If set, where to find gccgo tools, such as cgo.
|
If set, where to find gccgo tools, such as cgo.
|
||||||
The default is based on how gccgo was configured.
|
The default is based on how gccgo was configured.
|
||||||
|
GOEXPERIMENT
|
||||||
|
Comma-separated list of toolchain experiments to enable or disable.
|
||||||
|
The list of available experiments may change arbitrarily over time.
|
||||||
|
See src/internal/goexperiment/flags.go for currently valid values.
|
||||||
|
Warning: This variable is provided for the development and testing
|
||||||
|
of the Go toolchain itself. Use beyond that purpose is unsupported.
|
||||||
GOROOT_FINAL
|
GOROOT_FINAL
|
||||||
The root of the installed Go tree, when it is
|
The root of the installed Go tree, when it is
|
||||||
installed in a location other than where it is built.
|
installed in a location other than where it is built.
|
||||||
|
17
src/cmd/go/testdata/script/env_exp.txt
vendored
Normal file
17
src/cmd/go/testdata/script/env_exp.txt
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Test GOEXPERIMENT variable
|
||||||
|
|
||||||
|
# go env shows default empty GOEXPERIMENT
|
||||||
|
go env
|
||||||
|
stdout GOEXPERIMENT=
|
||||||
|
|
||||||
|
# go env shows valid experiments
|
||||||
|
env GOEXPERIMENT=fieldtrack,staticlockranking
|
||||||
|
go env GOEXPERIMENT
|
||||||
|
stdout '.*fieldtrack.*staticlockranking.*'
|
||||||
|
go env
|
||||||
|
stdout 'GOEXPERIMENT=.*fieldtrack.*staticlockranking.*'
|
||||||
|
|
||||||
|
# go env rejects unknown experiments
|
||||||
|
env GOEXPERIMENT=bad
|
||||||
|
! go env GOEXPERIMENT
|
||||||
|
stderr 'unknown GOEXPERIMENT bad'
|
7
src/cmd/go/testdata/script/env_unset.txt
vendored
7
src/cmd/go/testdata/script/env_unset.txt
vendored
@ -4,6 +4,12 @@
|
|||||||
env GOENV=badenv
|
env GOENV=badenv
|
||||||
env GOOS=
|
env GOOS=
|
||||||
env GOARCH=
|
env GOARCH=
|
||||||
|
env GOEXPERIMENT=
|
||||||
|
|
||||||
|
! go env
|
||||||
|
stderr '^go(\.exe)?: unknown GOEXPERIMENT badexp$'
|
||||||
|
|
||||||
|
go env -u GOEXPERIMENT
|
||||||
|
|
||||||
! go env
|
! go env
|
||||||
stderr '^cmd/go: unsupported GOOS/GOARCH pair bados/badarch$'
|
stderr '^cmd/go: unsupported GOOS/GOARCH pair bados/badarch$'
|
||||||
@ -21,3 +27,4 @@ go env
|
|||||||
-- badenv --
|
-- badenv --
|
||||||
GOOS=bados
|
GOOS=bados
|
||||||
GOARCH=badarch
|
GOARCH=badarch
|
||||||
|
GOEXPERIMENT=badexp
|
||||||
|
6
src/cmd/go/testdata/script/env_write.txt
vendored
6
src/cmd/go/testdata/script/env_write.txt
vendored
@ -179,3 +179,9 @@ stderr 'unsupported GOOS/GOARCH.*windows/mips$'
|
|||||||
stderr 'go env -w: GOMODCACHE entry is relative; must be absolute path: "~/test"'
|
stderr 'go env -w: GOMODCACHE entry is relative; must be absolute path: "~/test"'
|
||||||
! go env -w GOMODCACHE=./test
|
! go env -w GOMODCACHE=./test
|
||||||
stderr 'go env -w: GOMODCACHE entry is relative; must be absolute path: "./test"'
|
stderr 'go env -w: GOMODCACHE entry is relative; must be absolute path: "./test"'
|
||||||
|
|
||||||
|
# go env -w checks validity of GOEXPERIMENT
|
||||||
|
env GOEXPERIMENT=
|
||||||
|
! go env -w GOEXPERIMENT=badexp
|
||||||
|
stderr 'unknown GOEXPERIMENT badexp'
|
||||||
|
go env -w GOEXPERIMENT=fieldtrack
|
||||||
|
Loading…
Reference in New Issue
Block a user