mirror of https://github.com/golang/go.git
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 <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>
This commit is contained in:
parent
4310502385
commit
83a7626687
|
|
@ -20,3 +20,11 @@ non-existent identifiers. Some of these mistakes may cause tests not
|
||||||
to run.
|
to run.
|
||||||
|
|
||||||
This analyzer is among the subset of analyzers that are run by `go test`.
|
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).
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
|
|
||||||
"cmd/go/internal/base"
|
"cmd/go/internal/base"
|
||||||
"cmd/go/internal/cfg"
|
"cmd/go/internal/cfg"
|
||||||
"internal/goexperiment"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Default returns the default cache to use.
|
// 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)
|
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)
|
return startCacheProg(v, diskCache)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"internal/goexperiment"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -91,8 +92,11 @@ type ProgRequest struct {
|
||||||
// ActionID is non-nil for get and puts.
|
// ActionID is non-nil for get and puts.
|
||||||
ActionID []byte `json:",omitempty"` // or nil if not used
|
ActionID []byte `json:",omitempty"` // or nil if not used
|
||||||
|
|
||||||
// ObjectID is set for Type "put" and "output-file".
|
// OutputID is set for Type "put".
|
||||||
ObjectID []byte `json:",omitempty"` // or nil if not used
|
//
|
||||||
|
// 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
|
// 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.
|
// 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 is the number of bytes of Body. If zero, the body isn't written.
|
||||||
BodySize int64 `json:",omitempty"`
|
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.
|
// 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
|
return nil
|
||||||
}
|
}
|
||||||
if wrote != req.BodySize {
|
if wrote != req.BodySize {
|
||||||
return fmt.Errorf("short write writing body to GOCACHEPROG for action %x, object %x: wrote %v; expected %v",
|
return fmt.Errorf("short write writing body to GOCACHEPROG for action %x, output %x: wrote %v; expected %v",
|
||||||
req.ActionID, req.ObjectID, wrote, req.BodySize)
|
req.ActionID, req.OutputID, wrote, req.BodySize)
|
||||||
}
|
}
|
||||||
if _, err := c.bw.WriteString("\"\n"); err != nil {
|
if _, err := c.bw.WriteString("\"\n"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -388,10 +400,18 @@ func (c *ProgCache) Put(a ActionID, file io.ReadSeeker) (_ OutputID, size int64,
|
||||||
return out, size, nil
|
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{
|
res, err := c.send(c.ctx, &ProgRequest{
|
||||||
Command: cmdPut,
|
Command: cmdPut,
|
||||||
ActionID: a[:],
|
ActionID: a[:],
|
||||||
ObjectID: out[:],
|
OutputID: out[:],
|
||||||
|
ObjectID: deprecatedValue, // TODO(bradfitz): remove in Go 1.25
|
||||||
Body: file,
|
Body: file,
|
||||||
BodySize: size,
|
BodySize: size,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue