Skip to content

Commit b7451e2

Browse files
author
Jay Conrod
committed
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 <[email protected]>
1 parent 0005515 commit b7451e2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/cmd/go/internal/work/exec.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,13 @@ func (b *Builder) build(a *Action) (err error) {
386386
cached = true
387387
a.output = []byte{} // start saving output in case we miss any cache results
388388
}
389+
390+
// Source files might be cached, even if the full action is not
391+
// (e.g., go list -compiled -find).
392+
if !cached && need&needCompiledGoFiles != 0 && b.loadCachedSrcFiles(a) {
393+
need &^= needCompiledGoFiles
394+
}
395+
389396
if need == 0 {
390397
return nil
391398
}

src/cmd/go/testdata/script/list_find.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ stdout true
55
go list -find -f '{{.Incomplete}} {{.Imports}}' x/y/z...
66
stdout '^false \[\]'
77

8+
# go list -find -compiled should use cached sources the second time it's run.
9+
# It might not find the same cached sources as "go build", but the sources
10+
# should be identical. "go build" derives action IDs (which are used as cache
11+
# keys) from dependencies' action IDs. "go list -find" won't know what the
12+
# dependencies are, so it's can't construct the same action IDs.
13+
go list -find -compiled net
14+
go list -find -compiled -x net
15+
! stderr 'cgo'
16+
817
-- x/y/z/z.go --
918
package z
1019
import "does/not/exist"

0 commit comments

Comments
 (0)