]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: enable GOCACHEPROG by default, without GOEXPERIMENT
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 6 Nov 2024 18:14:17 +0000 (10:14 -0800)
committerGopher Robot <gobot@golang.org>
Wed, 13 Nov 2024 19:09:01 +0000 (19:09 +0000)
Fixes #64876

Change-Id: I2c0e1ed22f8e13d00dfb5fededbc84038cd7ff8e
Reviewed-on: https://go-review.googlesource.com/c/go/+/626035
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Sam Thanawalla <samthanawalla@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
doc/next/3-tools.md
src/cmd/go/internal/cache/default.go
src/cmd/go/internal/cache/prog.go

index c23b204e91442707551ed5ad5eed5f4124acd9b1..9017b53b1008cde78840caad9d340a18fbf94814 100644 (file)
@@ -20,3 +20,11 @@ non-existent identifiers. Some of these mistakes may cause tests not
 to run.
 
 This analyzer is among the subset of analyzers that are run by `go test`.
+
+### GOCACHEPROG
+
+The `cmd/go` internal binary and test caching mechanism can now be implemented
+by child processes implementing a JSON protocol between the `cmd/go` tool
+and the child process named by the `GOCACHEPROG` environment variable.
+This was previously behind a GOEXPERIMENT.
+For protocol details, see [#59719](/issue/59719).
index b0f442517358ebb8e2477da0fc87c6a89d6c5024..09814f0f174b027707dad03e31b5ce99040fc800 100644 (file)
@@ -12,7 +12,6 @@ import (
 
        "cmd/go/internal/base"
        "cmd/go/internal/cfg"
-       "internal/goexperiment"
 )
 
 // Default returns the default cache to use.
@@ -55,7 +54,7 @@ func initDefaultCache() Cache {
                base.Fatalf("failed to initialize build cache at %s: %s\n", dir, err)
        }
 
-       if v := cfg.Getenv("GOCACHEPROG"); v != "" && goexperiment.CacheProg {
+       if v := cfg.Getenv("GOCACHEPROG"); v != "" {
                return startCacheProg(v, diskCache)
        }
 
index 8d826f0b99b6f00ca02c523cd14d4359030a643e..e09620bac86c48376c7fe1c1c27a6f1c02705d95 100644 (file)
@@ -14,6 +14,7 @@ import (
        "encoding/json"
        "errors"
        "fmt"
+       "internal/goexperiment"
        "io"
        "log"
        "os"
@@ -91,8 +92,11 @@ type ProgRequest struct {
        // ActionID is non-nil for get and puts.
        ActionID []byte `json:",omitempty"` // or nil if not used
 
-       // ObjectID is set for Type "put" and "output-file".
-       ObjectID []byte `json:",omitempty"` // or nil if not used
+       // OutputID is set for Type "put".
+       //
+       // Prior to Go 1.24, when GOCACHEPROG was still an experiment, this was
+       // accidentally named ObjectID. It was renamed to OutputID in Go 1.24.
+       OutputID []byte `json:",omitempty"` // or nil if not used
 
        // Body is the body for "put" requests. It's sent after the JSON object
        // as a base64-encoded JSON string when BodySize is non-zero.
@@ -104,6 +108,14 @@ type ProgRequest struct {
 
        // BodySize is the number of bytes of Body. If zero, the body isn't written.
        BodySize int64 `json:",omitempty"`
+
+       // ObjectID is the accidental spelling of OutputID that was used prior to Go
+       // 1.24.
+       //
+       // Deprecated: use OutputID. This field is only populated temporarily for
+       // backwards compatibility with Go 1.23 and earlier when
+       // GOEXPERIMENT=gocacheprog is set. It will be removed in Go 1.25.
+       ObjectID []byte `json:",omitempty"`
 }
 
 // ProgResponse is the JSON response from the child process to cmd/go.
@@ -302,8 +314,8 @@ func (c *ProgCache) writeToChild(req *ProgRequest, resc chan<- *ProgResponse) (e
                        return nil
                }
                if wrote != req.BodySize {
-                       return fmt.Errorf("short write writing body to GOCACHEPROG for action %x, object %x: wrote %v; expected %v",
-                               req.ActionID, req.ObjectID, wrote, req.BodySize)
+                       return fmt.Errorf("short write writing body to GOCACHEPROG for action %x, output %x: wrote %v; expected %v",
+                               req.ActionID, req.OutputID, wrote, req.BodySize)
                }
                if _, err := c.bw.WriteString("\"\n"); err != nil {
                        return err
@@ -388,10 +400,18 @@ func (c *ProgCache) Put(a ActionID, file io.ReadSeeker) (_ OutputID, size int64,
                return out, size, nil
        }
 
+       // For compatibility with Go 1.23/1.24 GOEXPERIMENT=gocacheprog users, also
+       // populate the deprecated ObjectID field. This will be removed in Go 1.25.
+       var deprecatedValue []byte
+       if goexperiment.CacheProg {
+               deprecatedValue = out[:]
+       }
+
        res, err := c.send(c.ctx, &ProgRequest{
                Command:  cmdPut,
                ActionID: a[:],
-               ObjectID: out[:],
+               OutputID: out[:],
+               ObjectID: deprecatedValue, // TODO(bradfitz): remove in Go 1.25
                Body:     file,
                BodySize: size,
        })