]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't report non-go files in CompiledGoFiles
authorMichael Matloob <matloob@golang.org>
Fri, 18 Nov 2022 19:54:14 +0000 (14:54 -0500)
committerMichael Matloob <matloob@golang.org>
Fri, 18 Nov 2022 21:12:24 +0000 (21:12 +0000)
We save non-go files in the cached srcfiles file because we want the
non-go files for vet, but we shouldn't report them in CompiledGoFiles.
Filter them out before adding them to CompiledGoFiles.

Fixes #28749

Change-Id: I889d4bbf8c4ec1348584a62ef5e4f8b3f05e97da
Reviewed-on: https://go-review.googlesource.com/c/go/+/451285
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/work/exec.go
src/cmd/go/testdata/script/list_compiled_files_issue28749.txt [new file with mode: 0644]

index 344f409199c0bb6de38e0bcca90ca5ddbfe6e630..7569935926133a11f5b6aaeaabd8fc354b4f20c5 100644 (file)
@@ -479,7 +479,7 @@ func (b *Builder) build(ctx context.Context, a *Action) (err error) {
                                p.BuildID = a.buildID
                        }
                        if need&needCompiledGoFiles != 0 {
-                               if err := b.loadCachedSrcFiles(a); err == nil {
+                               if err := b.loadCachedCompiledGoFiles(a); err == nil {
                                        need &^= needCompiledGoFiles
                                }
                        }
@@ -488,7 +488,7 @@ func (b *Builder) build(ctx context.Context, a *Action) (err error) {
                // Source files might be cached, even if the full action is not
                // (e.g., go list -compiled -find).
                if !cachedBuild && need&needCompiledGoFiles != 0 {
-                       if err := b.loadCachedSrcFiles(a); err == nil {
+                       if err := b.loadCachedCompiledGoFiles(a); err == nil {
                                need &^= needCompiledGoFiles
                        }
                }
@@ -773,7 +773,7 @@ OverlayLoop:
                need &^= needVet
        }
        if need&needCompiledGoFiles != 0 {
-               if err := b.loadCachedSrcFiles(a); err != nil {
+               if err := b.loadCachedCompiledGoFiles(a); err != nil {
                        return fmt.Errorf("loading compiled Go files from cache: %w", err)
                }
                need &^= needCompiledGoFiles
@@ -1040,28 +1040,30 @@ func (b *Builder) loadCachedVet(a *Action) error {
        return nil
 }
 
-func (b *Builder) loadCachedSrcFiles(a *Action) error {
+func (b *Builder) loadCachedCompiledGoFiles(a *Action) error {
        c := cache.Default()
        list, _, err := c.GetBytes(cache.Subkey(a.actionID, "srcfiles"))
        if err != nil {
                return fmt.Errorf("reading srcfiles list: %w", err)
        }
-       var files []string
+       var gofiles []string
        for _, name := range strings.Split(string(list), "\n") {
                if name == "" { // end of list
                        continue
+               } else if !strings.HasSuffix(name, ".go") {
+                       continue
                }
                if strings.HasPrefix(name, "./") {
-                       files = append(files, name[len("./"):])
+                       gofiles = append(gofiles, name[len("./"):])
                        continue
                }
                file, err := b.findCachedObjdirFile(a, c, name)
                if err != nil {
                        return fmt.Errorf("finding %s: %w", name, err)
                }
-               files = append(files, file)
+               gofiles = append(gofiles, file)
        }
-       a.Package.CompiledGoFiles = files
+       a.Package.CompiledGoFiles = gofiles
        return nil
 }
 
diff --git a/src/cmd/go/testdata/script/list_compiled_files_issue28749.txt b/src/cmd/go/testdata/script/list_compiled_files_issue28749.txt
new file mode 100644 (file)
index 0000000..e0fb977
--- /dev/null
@@ -0,0 +1,10 @@
+go list -compiled -f {{.CompiledGoFiles}} .
+! stdout 'foo.s'
+
+-- go.mod --
+module example.com/foo
+
+go 1.20
+-- foo.go --
+package foo
+-- foo.s --