Skip to content

Commit

Permalink
cmd/go/internal/envcmd: show GODEBUG in 'go env' output
Browse files Browse the repository at this point in the history
Fixes #65777

Change-Id: I62067d8212bfd9f9475ecad036a1218ffc5c2130
GitHub-Last-Rev: a395b02
GitHub-Pull-Request: #65888
Reviewed-on: https://go-review.googlesource.com/c/go/+/566097
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
  • Loading branch information
suntala authored and gopherbot committed Feb 29, 2024
1 parent 2589a89 commit 038fbf9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/cmd/go/internal/envcmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func MkEnv() []cfg.EnvVar {
{Name: "GOTOOLDIR", Value: build.ToolDir},
{Name: "GOVCS", Value: cfg.GOVCS},
{Name: "GOVERSION", Value: runtime.Version()},
{Name: "GODEBUG", Value: os.Getenv("GODEBUG")},
}

if work.GccgoBin != "" {
Expand Down Expand Up @@ -530,7 +531,7 @@ func checkEnvWrite(key, val string) error {
switch key {
case "GOEXE", "GOGCCFLAGS", "GOHOSTARCH", "GOHOSTOS", "GOMOD", "GOWORK", "GOTOOLDIR", "GOVERSION":
return fmt.Errorf("%s cannot be modified", key)
case "GOENV":
case "GOENV", "GODEBUG":
return fmt.Errorf("%s can only be set using the OS environment", key)
}

Expand Down
6 changes: 4 additions & 2 deletions src/cmd/go/testdata/script/env_write.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ go env -u GOPATH
! stderr .+

# go env -w rejects unknown or bad variables
! go env -w GODEBUG=gctrace=1
stderr 'unknown go command variable GODEBUG'
! go env -w GOGC=off
stderr 'unknown go command variable GOGC'
! go env -w GOEXE=.bat
stderr 'GOEXE cannot be modified'
! go env -w GOVERSION=customversion
stderr 'GOVERSION cannot be modified'
! go env -w GOENV=/env
stderr 'GOENV can only be set using the OS environment'
! go env -w GODEBUG=gctrace=1
stderr 'GODEBUG can only be set using the OS environment'

# go env -w can set multiple variables
env CC=
Expand Down

0 comments on commit 038fbf9

Please sign in to comment.