1
0
mirror of https://github.com/golang/go synced 2024-11-17 09:54:46 -07:00

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 <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Michael Matloob 2022-11-18 14:54:14 -05:00
parent 7161fc737d
commit dccc58e1b9
2 changed files with 20 additions and 8 deletions

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

View File

@ -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 --