From 83a7626687c790b3770592794ba12e06fbc87a35 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 6 Nov 2024 10:14:17 -0800 Subject: [PATCH] cmd/go: enable GOCACHEPROG by default, without GOEXPERIMENT Fixes #64876 Change-Id: I2c0e1ed22f8e13d00dfb5fededbc84038cd7ff8e Reviewed-on: https://go-review.googlesource.com/c/go/+/626035 LUCI-TryBot-Result: Go LUCI Auto-Submit: Sam Thanawalla Reviewed-by: Michael Matloob Reviewed-by: Sam Thanawalla --- doc/next/3-tools.md | 8 ++++++++ src/cmd/go/internal/cache/default.go | 3 +-- src/cmd/go/internal/cache/prog.go | 30 +++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/doc/next/3-tools.md b/doc/next/3-tools.md index c23b204e914..9017b53b100 100644 --- a/doc/next/3-tools.md +++ b/doc/next/3-tools.md @@ -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). diff --git a/src/cmd/go/internal/cache/default.go b/src/cmd/go/internal/cache/default.go index b0f44251735..09814f0f174 100644 --- a/src/cmd/go/internal/cache/default.go +++ b/src/cmd/go/internal/cache/default.go @@ -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) } diff --git a/src/cmd/go/internal/cache/prog.go b/src/cmd/go/internal/cache/prog.go index 8d826f0b99b..e09620bac86 100644 --- a/src/cmd/go/internal/cache/prog.go +++ b/src/cmd/go/internal/cache/prog.go @@ -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, })