cmd/go: only print GOCACHE value in env -changed if it's not the default

When other environment variables are set to default values,
we will not print it in go env -changed,
GOCACHE should do the same.

For #69994

Change-Id: I16661803cf1f56dd132b4db1c2d5cb4823fc0e58
Reviewed-on: https://go-review.googlesource.com/c/go/+/621997
Reviewed-by: Sean Liao <sean@liao.dev>
Auto-Submit: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
qiulaidongfeng 2024-10-23 22:45:58 +08:00 committed by Gopher Robot
parent 4820816b0d
commit 8898450841
2 changed files with 19 additions and 13 deletions

View File

@ -78,9 +78,20 @@ func DefaultDir() (string, bool, error) {
// otherwise distinguish between an explicit "off" and a UserCacheDir error.
defaultDirOnce.Do(func() {
defaultDir = cfg.Getenv("GOCACHE")
if defaultDir != "" {
defaultDirChanged = true
// Compute default location.
dir, err := os.UserCacheDir()
if err != nil {
defaultDir = "off"
defaultDirErr = fmt.Errorf("GOCACHE is not defined and %v", err)
} else {
defaultDir = filepath.Join(dir, "go-build")
}
newDir := cfg.Getenv("GOCACHE")
if newDir != "" {
defaultDirErr = nil
defaultDirChanged = newDir != defaultDir
defaultDir = newDir
if filepath.IsAbs(defaultDir) || defaultDir == "off" {
return
}
@ -88,16 +99,6 @@ func DefaultDir() (string, bool, error) {
defaultDirErr = fmt.Errorf("GOCACHE is not an absolute path")
return
}
// Compute default location.
dir, err := os.UserCacheDir()
if err != nil {
defaultDir = "off"
defaultDirChanged = true
defaultDirErr = fmt.Errorf("GOCACHE is not defined and %v", err)
return
}
defaultDir = filepath.Join(dir, "go-build")
})
return defaultDir, defaultDirChanged, defaultDirErr

View File

@ -67,6 +67,11 @@ env GOROOT=./b
go env -changed
! stdout 'GOTOOLCHAIN=''?local''?'
[GOOS:windows] env LocalAppData=C:\
[GOOS:windows] env GOCACHE=C:\go-build
[GOOS:windows] go env -changed
[GOOS:windows] ! stdout 'GOCACHE'
-- a/go.env --
GOPROXY=s
GOAMD64=v1