1
0
mirror of https://github.com/golang/go synced 2024-11-13 18:00:30 -07:00

cmd/go: use cached source files in "go list -find -compiled"

When "go list" is invoked with -find, it clears the list of imports
for each package matched on the command line. This affects action IDs,
since they incorporate dependencies' action IDs. Consequently, the
build triggered by -compiled won't find sources cached by
"go build".

We can still safely cache compiled sources from multiple runs of
"go list -find -compiled" though, since cgo generated sources are not
affected by imported dependencies. This change adds a second look into
the cache in this situation.

Fixes #29371

Change-Id: Ia0ae5a403ab5d621feaa16f521e6a65ac0ae6d9a
Reviewed-on: https://go-review.googlesource.com/c/155481
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Jay Conrod 2018-12-21 13:47:20 -05:00
parent 00055152d3
commit b7451e299b
2 changed files with 16 additions and 0 deletions

View File

@ -386,6 +386,13 @@ func (b *Builder) build(a *Action) (err error) {
cached = true cached = true
a.output = []byte{} // start saving output in case we miss any cache results a.output = []byte{} // start saving output in case we miss any cache results
} }
// Source files might be cached, even if the full action is not
// (e.g., go list -compiled -find).
if !cached && need&needCompiledGoFiles != 0 && b.loadCachedSrcFiles(a) {
need &^= needCompiledGoFiles
}
if need == 0 { if need == 0 {
return nil return nil
} }

View File

@ -5,6 +5,15 @@ stdout true
go list -find -f '{{.Incomplete}} {{.Imports}}' x/y/z... go list -find -f '{{.Incomplete}} {{.Imports}}' x/y/z...
stdout '^false \[\]' stdout '^false \[\]'
# go list -find -compiled should use cached sources the second time it's run.
# It might not find the same cached sources as "go build", but the sources
# should be identical. "go build" derives action IDs (which are used as cache
# keys) from dependencies' action IDs. "go list -find" won't know what the
# dependencies are, so it's can't construct the same action IDs.
go list -find -compiled net
go list -find -compiled -x net
! stderr 'cgo'
-- x/y/z/z.go -- -- x/y/z/z.go --
package z package z
import "does/not/exist" import "does/not/exist"