Commit c604792d authored by Russ Cox's avatar Russ Cox

cmd/go: add "go env GOCACHE"

This lets users see the effective GOCACHE setting.

Change-Id: I0b6dd2945d54611be89ed68fe2fd99110b9a25f6
Reviewed-on: https://go-review.googlesource.com/75293Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
parent b31162d8
...@@ -138,6 +138,7 @@ var builddeps = map[string][]string{ ...@@ -138,6 +138,7 @@ var builddeps = map[string][]string{
"cmd/go/internal/envcmd": { "cmd/go/internal/envcmd": {
"cmd/go/internal/base", // cmd/go/internal/envcmd "cmd/go/internal/base", // cmd/go/internal/envcmd
"cmd/go/internal/cache", // cmd/go/internal/envcmd
"cmd/go/internal/cfg", // cmd/go/internal/envcmd "cmd/go/internal/cfg", // cmd/go/internal/envcmd
"cmd/go/internal/load", // cmd/go/internal/envcmd "cmd/go/internal/load", // cmd/go/internal/envcmd
"cmd/go/internal/work", // cmd/go/internal/envcmd "cmd/go/internal/work", // cmd/go/internal/envcmd
......
...@@ -26,11 +26,28 @@ var ( ...@@ -26,11 +26,28 @@ var (
// initDefaultCache does the work of finding the default cache // initDefaultCache does the work of finding the default cache
// the first time Default is called. // the first time Default is called.
func initDefaultCache() { func initDefaultCache() {
dir := os.Getenv("GOCACHE") dir := DefaultDir()
if dir == "off" { if dir == "off" {
return return
} }
if dir == "" { if err := os.MkdirAll(dir, 0777); err != nil {
base.Fatalf("initializing cache in $GOCACHE: %s", err)
}
c, err := Open(dir)
if err != nil {
base.Fatalf("initializing cache in $GOCACHE: %s", err)
}
defaultCache = c
}
// DefaultDir returns the effective GOCACHE setting.
// It returns "off" if the cache is disabled.
func DefaultDir() string {
dir := os.Getenv("GOCACHE")
if dir != "" {
return dir
}
// Compute default location. // Compute default location.
// TODO(rsc): This code belongs somewhere else, // TODO(rsc): This code belongs somewhere else,
// like maybe ioutil.CacheDir or os.CacheDir. // like maybe ioutil.CacheDir or os.CacheDir.
...@@ -41,15 +58,17 @@ func initDefaultCache() { ...@@ -41,15 +58,17 @@ func initDefaultCache() {
case "darwin": case "darwin":
dir = os.Getenv("HOME") dir = os.Getenv("HOME")
if dir == "" { if dir == "" {
return return "off"
} }
dir += "/Library/Caches" dir += "/Library/Caches"
case "plan9": case "plan9":
dir = os.Getenv("home") dir = os.Getenv("home")
if dir == "" { if dir == "" {
return return "off"
} }
// Plan 9 has no established per-user cache directory,
// but $home/lib/xyz is the usual equivalent of $HOME/.xyz on Unix.
dir += "/lib/cache" dir += "/lib/cache"
default: // Unix default: // Unix
...@@ -58,20 +77,10 @@ func initDefaultCache() { ...@@ -58,20 +77,10 @@ func initDefaultCache() {
if dir == "" { if dir == "" {
dir = os.Getenv("HOME") dir = os.Getenv("HOME")
if dir == "" { if dir == "" {
return return "off"
} }
dir += "/.cache" dir += "/.cache"
} }
} }
dir = filepath.Join(dir, "go-build") return filepath.Join(dir, "go-build")
if err := os.MkdirAll(dir, 0777); err != nil {
return
}
}
c, err := Open(dir)
if err != nil {
base.Fatalf("initializing cache in $GOCACHE: %s", err)
}
defaultCache = c
} }
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"strings" "strings"
"cmd/go/internal/base" "cmd/go/internal/base"
"cmd/go/internal/cache"
"cmd/go/internal/cfg" "cmd/go/internal/cfg"
"cmd/go/internal/load" "cmd/go/internal/load"
"cmd/go/internal/work" "cmd/go/internal/work"
...@@ -55,6 +56,7 @@ func MkEnv() []cfg.EnvVar { ...@@ -55,6 +56,7 @@ func MkEnv() []cfg.EnvVar {
{Name: "GORACE", Value: os.Getenv("GORACE")}, {Name: "GORACE", Value: os.Getenv("GORACE")},
{Name: "GOROOT", Value: cfg.GOROOT}, {Name: "GOROOT", Value: cfg.GOROOT},
{Name: "GOTOOLDIR", Value: base.ToolDir}, {Name: "GOTOOLDIR", Value: base.ToolDir},
{Name: "GOCACHE", Value: cache.DefaultDir()},
// disable escape codes in clang errors // disable escape codes in clang errors
{Name: "TERM", Value: "dumb"}, {Name: "TERM", Value: "dumb"},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment