]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: use cached source files in "go list -find -compiled"
authorJay Conrod <jayconrod@google.com>
Fri, 21 Dec 2018 18:47:20 +0000 (13:47 -0500)
committerJay Conrod <jayconrod@google.com>
Fri, 21 Dec 2018 20:45:04 +0000 (20:45 +0000)
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>
src/cmd/go/internal/work/exec.go
src/cmd/go/testdata/script/list_find.txt

index ca588911fed84d50ddfd5d0c4957fe7783f1d4d8..baa587268744f6913b854dc2000f47b6a8e4fa4d 100644 (file)
@@ -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
                }
index dbe8fb0ac98cea704f5eb2f3b5f655451aefe4e8..63c6896e507dbbaceaf02a0e71c6a2025320bf19 100644 (file)
@@ -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"