]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/env: add GOCACHEPROG to go env output
authorMichael Matloob <matloob@golang.org>
Mon, 6 Jan 2025 19:08:53 +0000 (14:08 -0500)
committerMichael Matloob <matloob@golang.org>
Tue, 7 Jan 2025 15:48:33 +0000 (07:48 -0800)
For #71059

Change-Id: I4bbdd14d416dc2e6dae3549a84c16dbef9d4e645
Reviewed-on: https://go-review.googlesource.com/c/go/+/640755
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
Reviewed-by: Austin Clements <austin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/go/internal/cache/default.go
src/cmd/go/internal/cfg/cfg.go
src/cmd/go/internal/envcmd/env.go
src/cmd/go/testdata/script/env_gocacheprog.txt [new file with mode: 0644]

index 074f911593373900960498d6a47336995dd710bf..f8e5696cbd1e844a91296c8492594ed095e68025 100644 (file)
@@ -54,8 +54,8 @@ func initDefaultCache() Cache {
                base.Fatalf("failed to initialize build cache at %s: %s\n", dir, err)
        }
 
-       if v := cfg.Getenv("GOCACHEPROG"); v != "" {
-               return startCacheProg(v, diskCache)
+       if cfg.GOCACHEPROG != "" {
+               return startCacheProg(cfg.GOCACHEPROG, diskCache)
        }
 
        return diskCache
index 6c2af99c2dfb09be2188909cc1656fb7cd69bb99..3b9f27e91d517e765a0175290469f999f86e4ab4 100644 (file)
@@ -425,8 +425,9 @@ var (
        GOROOTpkg string
        GOROOTsrc string
 
-       GOBIN                         = Getenv("GOBIN")
-       GOMODCACHE, GOMODCACHEChanged = EnvOrAndChanged("GOMODCACHE", gopathDir("pkg/mod"))
+       GOBIN                           = Getenv("GOBIN")
+       GOCACHEPROG, GOCACHEPROGChanged = EnvOrAndChanged("GOCACHEPROG", "")
+       GOMODCACHE, GOMODCACHEChanged   = EnvOrAndChanged("GOMODCACHE", gopathDir("pkg/mod"))
 
        // Used in envcmd.MkEnv and build ID computations.
        GOARM64, goARM64Changed     = EnvOrAndChanged("GOARM64", buildcfg.DefaultGOARM64)
index 19db68e4f8f01d50a7deac3c93d00e90aa793f3b..7c370d427f9c2f81edc0ae444c1ab62542360905 100644 (file)
@@ -85,6 +85,7 @@ func MkEnv() []cfg.EnvVar {
                {Name: "GOAUTH", Value: cfg.GOAUTH, Changed: cfg.GOAUTHChanged},
                {Name: "GOBIN", Value: cfg.GOBIN},
                {Name: "GOCACHE"},
+               {Name: "GOCACHEPROG", Value: cfg.GOCACHEPROG, Changed: cfg.GOCACHEPROGChanged},
                {Name: "GODEBUG", Value: os.Getenv("GODEBUG")},
                {Name: "GOENV", Value: envFile, Changed: envFileChanged},
                {Name: "GOEXE", Value: cfg.ExeSuffix},
diff --git a/src/cmd/go/testdata/script/env_gocacheprog.txt b/src/cmd/go/testdata/script/env_gocacheprog.txt
new file mode 100644 (file)
index 0000000..f5f15ed
--- /dev/null
@@ -0,0 +1,42 @@
+# GOCACHEPROG unset
+env GOCACHEPROG=
+
+go env
+stdout 'GOCACHEPROG=''?''?'
+
+go env -changed
+! stdout 'GOCACHEPROG'
+
+go env -changed -json
+! stdout 'GOCACHEPROG'
+
+# GOCACHEPROG set
+[short] skip 'compiles and runs a go program'
+
+go build -o cacheprog$GOEXE cacheprog.go
+
+env GOCACHEPROG=$GOPATH/src/cacheprog$GOEXE
+
+go env
+stdout 'GOCACHEPROG=''?'$GOCACHEPROG'''?'
+
+go env -changed
+stdout 'GOCACHEPROG=''?'$GOCACHEPROG'''?'
+
+go env -changed -json
+stdout '"GOCACHEPROG": "'$GOCACHEPROG'"'
+
+-- cacheprog.go --
+// This is a minimal GOCACHEPROG program that can't actually do anything but exit.
+package main
+
+import (
+    "encoding/json"
+    "os"
+)
+
+func main() {
+    json.NewEncoder(os.Stdout).Encode(map[string][]string{"KnownCommands": {"close"}})
+    var res struct{}
+    json.NewDecoder(os.Stdin).Decode(&res)
+}
\ No newline at end of file