From: Michael Matloob Date: Fri, 18 Nov 2022 19:54:14 +0000 (-0500) Subject: cmd/go: don't report non-go files in CompiledGoFiles X-Git-Tag: go1.20rc1~156 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=dccc58e1b9d3fbc88c6a86c02f77ed0f26d07a4a;p=gostls13.git cmd/go: don't report non-go files in CompiledGoFiles 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 Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Michael Matloob --- diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 344f409199..7569935926 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -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 index 0000000000..e0fb977c8d --- /dev/null +++ b/src/cmd/go/testdata/script/list_compiled_files_issue28749.txt @@ -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 --