mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go/internal/cacheprog: drop redundant Prog prefixes
Now that these types are in their own package, drop the unnecessary Prog prefixes from everything. Updates #71032 Updates #59719 Change-Id: Id54edf0473754e3b21a71beb72803fb5481206c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/638996 Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Austin Clements <austin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
20da34c6d2
commit
3c8e5b13df
2 changed files with 41 additions and 41 deletions
24
src/cmd/go/internal/cache/prog.go
vendored
24
src/cmd/go/internal/cache/prog.go
vendored
|
|
@ -39,7 +39,7 @@ type ProgCache struct {
|
|||
|
||||
// can are the commands that the child process declared that it supports.
|
||||
// This is effectively the versioning mechanism.
|
||||
can map[cacheprog.ProgCmd]bool
|
||||
can map[cacheprog.Cmd]bool
|
||||
|
||||
// fuzzDirCache is another Cache implementation to use for the FuzzDir
|
||||
// method. In practice this is the default GOCACHE disk-based
|
||||
|
|
@ -56,7 +56,7 @@ type ProgCache struct {
|
|||
|
||||
mu sync.Mutex // guards following fields
|
||||
nextID int64
|
||||
inFlight map[int64]chan<- *cacheprog.ProgResponse
|
||||
inFlight map[int64]chan<- *cacheprog.Response
|
||||
outputFile map[OutputID]string // object => abs path on disk
|
||||
|
||||
// writeMu serializes writing to the child process.
|
||||
|
|
@ -111,14 +111,14 @@ func startCacheProg(progAndArgs string, fuzzDirCache Cache) Cache {
|
|||
stdout: out,
|
||||
stdin: in,
|
||||
bw: bufio.NewWriter(in),
|
||||
inFlight: make(map[int64]chan<- *cacheprog.ProgResponse),
|
||||
inFlight: make(map[int64]chan<- *cacheprog.Response),
|
||||
outputFile: make(map[OutputID]string),
|
||||
readLoopDone: make(chan struct{}),
|
||||
}
|
||||
|
||||
// Register our interest in the initial protocol message from the child to
|
||||
// us, saying what it can do.
|
||||
capResc := make(chan *cacheprog.ProgResponse, 1)
|
||||
capResc := make(chan *cacheprog.Response, 1)
|
||||
pc.inFlight[0] = capResc
|
||||
|
||||
pc.jenc = json.NewEncoder(pc.bw)
|
||||
|
|
@ -133,7 +133,7 @@ func startCacheProg(progAndArgs string, fuzzDirCache Cache) Cache {
|
|||
case <-timer.C:
|
||||
log.Printf("# still waiting for GOCACHEPROG %v ...", prog)
|
||||
case capRes := <-capResc:
|
||||
can := map[cacheprog.ProgCmd]bool{}
|
||||
can := map[cacheprog.Cmd]bool{}
|
||||
for _, cmd := range capRes.KnownCommands {
|
||||
can[cmd] = true
|
||||
}
|
||||
|
|
@ -150,7 +150,7 @@ func (c *ProgCache) readLoop(readLoopDone chan<- struct{}) {
|
|||
defer close(readLoopDone)
|
||||
jd := json.NewDecoder(c.stdout)
|
||||
for {
|
||||
res := new(cacheprog.ProgResponse)
|
||||
res := new(cacheprog.Response)
|
||||
if err := jd.Decode(res); err != nil {
|
||||
if c.closing.Load() {
|
||||
return // quietly
|
||||
|
|
@ -175,8 +175,8 @@ func (c *ProgCache) readLoop(readLoopDone chan<- struct{}) {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *ProgCache) send(ctx context.Context, req *cacheprog.ProgRequest) (*cacheprog.ProgResponse, error) {
|
||||
resc := make(chan *cacheprog.ProgResponse, 1)
|
||||
func (c *ProgCache) send(ctx context.Context, req *cacheprog.Request) (*cacheprog.Response, error) {
|
||||
resc := make(chan *cacheprog.Response, 1)
|
||||
if err := c.writeToChild(req, resc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -191,7 +191,7 @@ func (c *ProgCache) send(ctx context.Context, req *cacheprog.ProgRequest) (*cach
|
|||
}
|
||||
}
|
||||
|
||||
func (c *ProgCache) writeToChild(req *cacheprog.ProgRequest, resc chan<- *cacheprog.ProgResponse) (err error) {
|
||||
func (c *ProgCache) writeToChild(req *cacheprog.Request, resc chan<- *cacheprog.Response) (err error) {
|
||||
c.mu.Lock()
|
||||
c.nextID++
|
||||
req.ID = c.nextID
|
||||
|
|
@ -252,7 +252,7 @@ func (c *ProgCache) Get(a ActionID) (Entry, error) {
|
|||
// error types on the Cache interface.
|
||||
return Entry{}, &entryNotFoundError{}
|
||||
}
|
||||
res, err := c.send(c.ctx, &cacheprog.ProgRequest{
|
||||
res, err := c.send(c.ctx, &cacheprog.Request{
|
||||
Command: cacheprog.CmdGet,
|
||||
ActionID: a[:],
|
||||
})
|
||||
|
|
@ -321,7 +321,7 @@ func (c *ProgCache) Put(a ActionID, file io.ReadSeeker) (_ OutputID, size int64,
|
|||
deprecatedValue = out[:]
|
||||
}
|
||||
|
||||
res, err := c.send(c.ctx, &cacheprog.ProgRequest{
|
||||
res, err := c.send(c.ctx, &cacheprog.Request{
|
||||
Command: cacheprog.CmdPut,
|
||||
ActionID: a[:],
|
||||
OutputID: out[:],
|
||||
|
|
@ -347,7 +347,7 @@ func (c *ProgCache) Close() error {
|
|||
// and clean up if it wants. Only after that exchange do we cancel
|
||||
// the context that kills the process.
|
||||
if c.can[cacheprog.CmdClose] {
|
||||
_, err = c.send(c.ctx, &cacheprog.ProgRequest{Command: cacheprog.CmdClose})
|
||||
_, err = c.send(c.ctx, &cacheprog.Request{Command: cacheprog.CmdClose})
|
||||
}
|
||||
// Cancel the context, which will close the helper's stdin.
|
||||
c.ctxCancel()
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@
|
|||
// with it via JSON messages over stdin/stdout. The subprocess's stderr will be
|
||||
// connected to the go command's stderr.
|
||||
//
|
||||
// The subprocess should immediately send a [ProgResponse] with its capabilities.
|
||||
// After that, the go command will send a stream of [ProgRequest] messages and the
|
||||
// subprocess should reply to each [ProgRequest] with a [ProgResponse] message.
|
||||
// The subprocess should immediately send a [Response] with its capabilities.
|
||||
// After that, the go command will send a stream of [Request] messages and the
|
||||
// subprocess should reply to each [Request] with a [Response] message.
|
||||
package cacheprog
|
||||
|
||||
import (
|
||||
|
|
@ -23,54 +23,54 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// ProgCmd is a command that can be issued to a child process.
|
||||
// Cmd is a command that can be issued to a child process.
|
||||
//
|
||||
// If the interface needs to grow, the go command can add new commands or new
|
||||
// versioned commands like "get2" in the future. The initial [ProgResponse] from
|
||||
// versioned commands like "get2" in the future. The initial [Response] from
|
||||
// the child process indicates which commands it supports.
|
||||
type ProgCmd string
|
||||
type Cmd string
|
||||
|
||||
const (
|
||||
// CmdPut tells the cache program to store an object in the cache.
|
||||
//
|
||||
// [ProgRequest.ActionID] is the cache key of this object. The cache should
|
||||
// store [ProgRequest.OutputID] and [ProgRequest.Body] under this key for a
|
||||
// [Request.ActionID] is the cache key of this object. The cache should
|
||||
// store [Request.OutputID] and [Request.Body] under this key for a
|
||||
// later "get" request. It must also store the Body in a file in the local
|
||||
// file system and return the path to that file in [ProgResponse.DiskPath],
|
||||
// file system and return the path to that file in [Response.DiskPath],
|
||||
// which must exist at least until a "close" request.
|
||||
CmdPut = ProgCmd("put")
|
||||
CmdPut = Cmd("put")
|
||||
|
||||
// CmdGet tells the cache program to retrieve an object from the cache.
|
||||
//
|
||||
// [ProgRequest.ActionID] specifies the key of the object to get. If the
|
||||
// cache does not contain this object, it should set [ProgResponse.Miss] to
|
||||
// true. Otherwise, it should populate the fields of [ProgResponse],
|
||||
// including setting [ProgResponse.OutputID] to the OutputID of the original
|
||||
// "put" request and [ProgResponse.DiskPath] to the path of a local file
|
||||
// [Request.ActionID] specifies the key of the object to get. If the
|
||||
// cache does not contain this object, it should set [Response.Miss] to
|
||||
// true. Otherwise, it should populate the fields of [Response],
|
||||
// including setting [Response.OutputID] to the OutputID of the original
|
||||
// "put" request and [Response.DiskPath] to the path of a local file
|
||||
// containing the Body of the original "put" request. That file must
|
||||
// continue to exist at least until a "close" request.
|
||||
CmdGet = ProgCmd("get")
|
||||
CmdGet = Cmd("get")
|
||||
|
||||
// CmdClose requests that the cache program exit gracefully.
|
||||
//
|
||||
// The cache program should reply to this request and then exit
|
||||
// (thus closing its stdout).
|
||||
CmdClose = ProgCmd("close")
|
||||
CmdClose = Cmd("close")
|
||||
)
|
||||
|
||||
// ProgRequest is the JSON-encoded message that's sent from the go command to
|
||||
// Request is the JSON-encoded message that's sent from the go command to
|
||||
// the GOCACHEPROG child process over stdin. Each JSON object is on its own
|
||||
// line. A ProgRequest of Type "put" with BodySize > 0 will be followed by a
|
||||
// line containing a base64-encoded JSON string literal of the body.
|
||||
type ProgRequest struct {
|
||||
type Request struct {
|
||||
// ID is a unique number per process across all requests.
|
||||
// It must be echoed in the ProgResponse from the child.
|
||||
// It must be echoed in the Response from the child.
|
||||
ID int64
|
||||
|
||||
// Command is the type of request.
|
||||
// The go command will only send commands that were declared
|
||||
// as supported by the child.
|
||||
Command ProgCmd
|
||||
Command Cmd
|
||||
|
||||
// ActionID is the cache key for "put" and "get" requests.
|
||||
ActionID []byte `json:",omitempty"` // or nil if not used
|
||||
|
|
@ -85,7 +85,7 @@ type ProgRequest struct {
|
|||
// as a base64-encoded JSON string when BodySize is non-zero.
|
||||
// It's sent as a separate JSON value instead of being a struct field
|
||||
// send in this JSON object so large values can be streamed in both directions.
|
||||
// The base64 string body of a ProgRequest will always be written
|
||||
// The base64 string body of a Request will always be written
|
||||
// immediately after the JSON object and a newline.
|
||||
Body io.Reader `json:"-"`
|
||||
|
||||
|
|
@ -101,26 +101,26 @@ type ProgRequest struct {
|
|||
ObjectID []byte `json:",omitempty"`
|
||||
}
|
||||
|
||||
// ProgResponse is the JSON response from the child process to the go command.
|
||||
// Response is the JSON response from the child process to the go command.
|
||||
//
|
||||
// With the exception of the first protocol message that the child writes to its
|
||||
// stdout with ID==0 and KnownCommands populated, these are only sent in
|
||||
// response to a ProgRequest from the go command.
|
||||
// response to a Request from the go command.
|
||||
//
|
||||
// ProgResponses can be sent in any order. The ID must match the request they're
|
||||
// Responses can be sent in any order. The ID must match the request they're
|
||||
// replying to.
|
||||
type ProgResponse struct {
|
||||
ID int64 // that corresponds to ProgRequest; they can be answered out of order
|
||||
type Response struct {
|
||||
ID int64 // that corresponds to Request; they can be answered out of order
|
||||
Err string `json:",omitempty"` // if non-empty, the error
|
||||
|
||||
// KnownCommands is included in the first message that cache helper program
|
||||
// writes to stdout on startup (with ID==0). It includes the
|
||||
// ProgRequest.Command types that are supported by the program.
|
||||
// Request.Command types that are supported by the program.
|
||||
//
|
||||
// This lets the go command extend the protocol gracefully over time (adding
|
||||
// "get2", etc), or fail gracefully when needed. It also lets the go command
|
||||
// verify the program wants to be a cache helper.
|
||||
KnownCommands []ProgCmd `json:",omitempty"`
|
||||
KnownCommands []Cmd `json:",omitempty"`
|
||||
|
||||
// For "get" requests.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue