Skip to content

Commit

Permalink
cmd/go: use cached source files in "go list -find -compiled"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jay Conrod committed Dec 21, 2018
1 parent 0005515 commit b7451e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cmd/go/internal/work/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ func (b *Builder) build(a *Action) (err error) {
cached = true
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 {
return nil
}
Expand Down
9 changes: 9 additions & 0 deletions src/cmd/go/testdata/script/list_find.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ stdout true
go list -find -f '{{.Incomplete}} {{.Imports}}' x/y/z...
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 --
package z
import "does/not/exist"

0 comments on commit b7451e2

Please sign in to comment.