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.
|
// can are the commands that the child process declared that it supports.
|
||||||
// This is effectively the versioning mechanism.
|
// 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
|
// fuzzDirCache is another Cache implementation to use for the FuzzDir
|
||||||
// method. In practice this is the default GOCACHE disk-based
|
// method. In practice this is the default GOCACHE disk-based
|
||||||
|
|
@ -56,7 +56,7 @@ type ProgCache struct {
|
||||||
|
|
||||||
mu sync.Mutex // guards following fields
|
mu sync.Mutex // guards following fields
|
||||||
nextID int64
|
nextID int64
|
||||||
inFlight map[int64]chan<- *cacheprog.ProgResponse
|
inFlight map[int64]chan<- *cacheprog.Response
|
||||||
outputFile map[OutputID]string // object => abs path on disk
|
outputFile map[OutputID]string // object => abs path on disk
|
||||||
|
|
||||||
// writeMu serializes writing to the child process.
|
// writeMu serializes writing to the child process.
|
||||||
|
|
@ -111,14 +111,14 @@ func startCacheProg(progAndArgs string, fuzzDirCache Cache) Cache {
|
||||||
stdout: out,
|
stdout: out,
|
||||||
stdin: in,
|
stdin: in,
|
||||||
bw: bufio.NewWriter(in),
|
bw: bufio.NewWriter(in),
|
||||||
inFlight: make(map[int64]chan<- *cacheprog.ProgResponse),
|
inFlight: make(map[int64]chan<- *cacheprog.Response),
|
||||||
outputFile: make(map[OutputID]string),
|
outputFile: make(map[OutputID]string),
|
||||||
readLoopDone: make(chan struct{}),
|
readLoopDone: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register our interest in the initial protocol message from the child to
|
// Register our interest in the initial protocol message from the child to
|
||||||
// us, saying what it can do.
|
// us, saying what it can do.
|
||||||
capResc := make(chan *cacheprog.ProgResponse, 1)
|
capResc := make(chan *cacheprog.Response, 1)
|
||||||
pc.inFlight[0] = capResc
|
pc.inFlight[0] = capResc
|
||||||
|
|
||||||
pc.jenc = json.NewEncoder(pc.bw)
|
pc.jenc = json.NewEncoder(pc.bw)
|
||||||
|
|
@ -133,7 +133,7 @@ func startCacheProg(progAndArgs string, fuzzDirCache Cache) Cache {
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
log.Printf("# still waiting for GOCACHEPROG %v ...", prog)
|
log.Printf("# still waiting for GOCACHEPROG %v ...", prog)
|
||||||
case capRes := <-capResc:
|
case capRes := <-capResc:
|
||||||
can := map[cacheprog.ProgCmd]bool{}
|
can := map[cacheprog.Cmd]bool{}
|
||||||
for _, cmd := range capRes.KnownCommands {
|
for _, cmd := range capRes.KnownCommands {
|
||||||
can[cmd] = true
|
can[cmd] = true
|
||||||
}
|
}
|
||||||
|
|
@ -150,7 +150,7 @@ func (c *ProgCache) readLoop(readLoopDone chan<- struct{}) {
|
||||||
defer close(readLoopDone)
|
defer close(readLoopDone)
|
||||||
jd := json.NewDecoder(c.stdout)
|
jd := json.NewDecoder(c.stdout)
|
||||||
for {
|
for {
|
||||||
res := new(cacheprog.ProgResponse)
|
res := new(cacheprog.Response)
|
||||||
if err := jd.Decode(res); err != nil {
|
if err := jd.Decode(res); err != nil {
|
||||||
if c.closing.Load() {
|
if c.closing.Load() {
|
||||||
return // quietly
|
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) {
|
func (c *ProgCache) send(ctx context.Context, req *cacheprog.Request) (*cacheprog.Response, error) {
|
||||||
resc := make(chan *cacheprog.ProgResponse, 1)
|
resc := make(chan *cacheprog.Response, 1)
|
||||||
if err := c.writeToChild(req, resc); err != nil {
|
if err := c.writeToChild(req, resc); err != nil {
|
||||||
return nil, err
|
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.mu.Lock()
|
||||||
c.nextID++
|
c.nextID++
|
||||||
req.ID = c.nextID
|
req.ID = c.nextID
|
||||||
|
|
@ -252,7 +252,7 @@ func (c *ProgCache) Get(a ActionID) (Entry, error) {
|
||||||
// error types on the Cache interface.
|
// error types on the Cache interface.
|
||||||
return Entry{}, &entryNotFoundError{}
|
return Entry{}, &entryNotFoundError{}
|
||||||
}
|
}
|
||||||
res, err := c.send(c.ctx, &cacheprog.ProgRequest{
|
res, err := c.send(c.ctx, &cacheprog.Request{
|
||||||
Command: cacheprog.CmdGet,
|
Command: cacheprog.CmdGet,
|
||||||
ActionID: a[:],
|
ActionID: a[:],
|
||||||
})
|
})
|
||||||
|
|
@ -321,7 +321,7 @@ func (c *ProgCache) Put(a ActionID, file io.ReadSeeker) (_ OutputID, size int64,
|
||||||
deprecatedValue = out[:]
|
deprecatedValue = out[:]
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := c.send(c.ctx, &cacheprog.ProgRequest{
|
res, err := c.send(c.ctx, &cacheprog.Request{
|
||||||
Command: cacheprog.CmdPut,
|
Command: cacheprog.CmdPut,
|
||||||
ActionID: a[:],
|
ActionID: a[:],
|
||||||
OutputID: out[:],
|
OutputID: out[:],
|
||||||
|
|
@ -347,7 +347,7 @@ func (c *ProgCache) Close() error {
|
||||||
// and clean up if it wants. Only after that exchange do we cancel
|
// and clean up if it wants. Only after that exchange do we cancel
|
||||||
// the context that kills the process.
|
// the context that kills the process.
|
||||||
if c.can[cacheprog.CmdClose] {
|
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.
|
// Cancel the context, which will close the helper's stdin.
|
||||||
c.ctxCancel()
|
c.ctxCancel()
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,9 @@
|
||||||
// with it via JSON messages over stdin/stdout. The subprocess's stderr will be
|
// with it via JSON messages over stdin/stdout. The subprocess's stderr will be
|
||||||
// connected to the go command's stderr.
|
// connected to the go command's stderr.
|
||||||
//
|
//
|
||||||
// The subprocess should immediately send a [ProgResponse] with its capabilities.
|
// The subprocess should immediately send a [Response] with its capabilities.
|
||||||
// After that, the go command will send a stream of [ProgRequest] messages and the
|
// After that, the go command will send a stream of [Request] messages and the
|
||||||
// subprocess should reply to each [ProgRequest] with a [ProgResponse] message.
|
// subprocess should reply to each [Request] with a [Response] message.
|
||||||
package cacheprog
|
package cacheprog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -23,54 +23,54 @@ import (
|
||||||
"time"
|
"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
|
// 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.
|
// the child process indicates which commands it supports.
|
||||||
type ProgCmd string
|
type Cmd string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// CmdPut tells the cache program to store an object in the cache.
|
// CmdPut tells the cache program to store an object in the cache.
|
||||||
//
|
//
|
||||||
// [ProgRequest.ActionID] is the cache key of this object. The cache should
|
// [Request.ActionID] is the cache key of this object. The cache should
|
||||||
// store [ProgRequest.OutputID] and [ProgRequest.Body] under this key for a
|
// 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
|
// 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.
|
// 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.
|
// CmdGet tells the cache program to retrieve an object from the cache.
|
||||||
//
|
//
|
||||||
// [ProgRequest.ActionID] specifies the key of the object to get. If the
|
// [Request.ActionID] specifies the key of the object to get. If the
|
||||||
// cache does not contain this object, it should set [ProgResponse.Miss] to
|
// cache does not contain this object, it should set [Response.Miss] to
|
||||||
// true. Otherwise, it should populate the fields of [ProgResponse],
|
// true. Otherwise, it should populate the fields of [Response],
|
||||||
// including setting [ProgResponse.OutputID] to the OutputID of the original
|
// including setting [Response.OutputID] to the OutputID of the original
|
||||||
// "put" request and [ProgResponse.DiskPath] to the path of a local file
|
// "put" request and [Response.DiskPath] to the path of a local file
|
||||||
// containing the Body of the original "put" request. That file must
|
// containing the Body of the original "put" request. That file must
|
||||||
// continue to exist at least until a "close" request.
|
// continue to exist at least until a "close" request.
|
||||||
CmdGet = ProgCmd("get")
|
CmdGet = Cmd("get")
|
||||||
|
|
||||||
// CmdClose requests that the cache program exit gracefully.
|
// CmdClose requests that the cache program exit gracefully.
|
||||||
//
|
//
|
||||||
// The cache program should reply to this request and then exit
|
// The cache program should reply to this request and then exit
|
||||||
// (thus closing its stdout).
|
// (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
|
// 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. A ProgRequest of Type "put" with BodySize > 0 will be followed by a
|
||||||
// line containing a base64-encoded JSON string literal of the body.
|
// 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.
|
// 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
|
ID int64
|
||||||
|
|
||||||
// Command is the type of request.
|
// Command is the type of request.
|
||||||
// The go command will only send commands that were declared
|
// The go command will only send commands that were declared
|
||||||
// as supported by the child.
|
// as supported by the child.
|
||||||
Command ProgCmd
|
Command Cmd
|
||||||
|
|
||||||
// ActionID is the cache key for "put" and "get" requests.
|
// ActionID is the cache key for "put" and "get" requests.
|
||||||
ActionID []byte `json:",omitempty"` // or nil if not used
|
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.
|
// 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
|
// 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.
|
// 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.
|
// immediately after the JSON object and a newline.
|
||||||
Body io.Reader `json:"-"`
|
Body io.Reader `json:"-"`
|
||||||
|
|
||||||
|
|
@ -101,26 +101,26 @@ type ProgRequest struct {
|
||||||
ObjectID []byte `json:",omitempty"`
|
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
|
// 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
|
// 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.
|
// replying to.
|
||||||
type ProgResponse struct {
|
type Response struct {
|
||||||
ID int64 // that corresponds to ProgRequest; they can be answered out of order
|
ID int64 // that corresponds to Request; they can be answered out of order
|
||||||
Err string `json:",omitempty"` // if non-empty, the error
|
Err string `json:",omitempty"` // if non-empty, the error
|
||||||
|
|
||||||
// KnownCommands is included in the first message that cache helper program
|
// KnownCommands is included in the first message that cache helper program
|
||||||
// writes to stdout on startup (with ID==0). It includes the
|
// 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
|
// 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
|
// "get2", etc), or fail gracefully when needed. It also lets the go command
|
||||||
// verify the program wants to be a cache helper.
|
// verify the program wants to be a cache helper.
|
||||||
KnownCommands []ProgCmd `json:",omitempty"`
|
KnownCommands []Cmd `json:",omitempty"`
|
||||||
|
|
||||||
// For "get" requests.
|
// For "get" requests.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue