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: 's avatarDavid Crawshaw <crawshaw@golang.org>
parent b31162d8
......@@ -137,15 +137,16 @@ var builddeps = map[string][]string{
},
"cmd/go/internal/envcmd": {
"cmd/go/internal/base", // cmd/go/internal/envcmd
"cmd/go/internal/cfg", // cmd/go/internal/envcmd
"cmd/go/internal/load", // cmd/go/internal/envcmd
"cmd/go/internal/work", // cmd/go/internal/envcmd
"encoding/json", // cmd/go/internal/envcmd
"fmt", // cmd/go/internal/envcmd
"os", // cmd/go/internal/envcmd
"runtime", // cmd/go/internal/envcmd
"strings", // 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/load", // cmd/go/internal/envcmd
"cmd/go/internal/work", // cmd/go/internal/envcmd
"encoding/json", // cmd/go/internal/envcmd
"fmt", // cmd/go/internal/envcmd
"os", // cmd/go/internal/envcmd
"runtime", // cmd/go/internal/envcmd
"strings", // cmd/go/internal/envcmd
},
"cmd/go/internal/fix": {
......
......@@ -26,52 +26,61 @@ var (
// initDefaultCache does the work of finding the default cache
// the first time Default is called.
func initDefaultCache() {
dir := os.Getenv("GOCACHE")
dir := DefaultDir()
if dir == "off" {
return
}
if dir == "" {
// Compute default location.
// TODO(rsc): This code belongs somewhere else,
// like maybe ioutil.CacheDir or os.CacheDir.
switch runtime.GOOS {
case "windows":
dir = os.Getenv("LocalAppData")
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
}
case "darwin":
dir = os.Getenv("HOME")
if dir == "" {
return
}
dir += "/Library/Caches"
// 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
}
case "plan9":
dir = os.Getenv("home")
if dir == "" {
return
}
dir += "/lib/cache"
// Compute default location.
// TODO(rsc): This code belongs somewhere else,
// like maybe ioutil.CacheDir or os.CacheDir.
switch runtime.GOOS {
case "windows":
dir = os.Getenv("LocalAppData")
default: // Unix
// https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
dir = os.Getenv("XDG_CACHE_HOME")
if dir == "" {
dir = os.Getenv("HOME")
if dir == "" {
return
}
dir += "/.cache"
}
case "darwin":
dir = os.Getenv("HOME")
if dir == "" {
return "off"
}
dir = filepath.Join(dir, "go-build")
if err := os.MkdirAll(dir, 0777); err != nil {
return
dir += "/Library/Caches"
case "plan9":
dir = os.Getenv("home")
if dir == "" {
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"
c, err := Open(dir)
if err != nil {
base.Fatalf("initializing cache in $GOCACHE: %s", err)
default: // Unix
// https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
dir = os.Getenv("XDG_CACHE_HOME")
if dir == "" {
dir = os.Getenv("HOME")
if dir == "" {
return "off"
}
dir += "/.cache"
}
}
defaultCache = c
return filepath.Join(dir, "go-build")
}
......@@ -13,6 +13,7 @@ import (
"strings"
"cmd/go/internal/base"
"cmd/go/internal/cache"
"cmd/go/internal/cfg"
"cmd/go/internal/load"
"cmd/go/internal/work"
......@@ -55,6 +56,7 @@ func MkEnv() []cfg.EnvVar {
{Name: "GORACE", Value: os.Getenv("GORACE")},
{Name: "GOROOT", Value: cfg.GOROOT},
{Name: "GOTOOLDIR", Value: base.ToolDir},
{Name: "GOCACHE", Value: cache.DefaultDir()},
// disable escape codes in clang errors
{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