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>
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
}
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"