go/packages: remove .s files from go list's CompiledGoFiles

This is a workaround for a go list regression that broke
go/packages but went unnoticed by because of a missing
call to packages.PrintErrors, added here.

Updates golang/go#28749

Change-Id: I1819a6143134a422791106ac037d3458ef864322
Reviewed-on: https://go-review.googlesource.com/c/149237
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Alan Donovan 2018-11-12 19:18:07 -05:00
parent c340431777
commit 5a00de994c
2 changed files with 21 additions and 1 deletions

View File

@ -548,6 +548,17 @@ func golistDriverCurrent(cfg *Config, words ...string) (*driverResponse, error)
OtherFiles: absJoin(p.Dir, otherFiles(p)...), OtherFiles: absJoin(p.Dir, otherFiles(p)...),
} }
// Workaround for github.com/golang/go/issues/28749.
// TODO(adonovan): delete before go1.12 release.
out := pkg.CompiledGoFiles[:0]
for _, f := range pkg.CompiledGoFiles {
if strings.HasSuffix(f, ".s") {
continue
}
out = append(out, f)
}
pkg.CompiledGoFiles = out
// Extract the PkgPath from the package's ID. // Extract the PkgPath from the package's ID.
if i := strings.IndexByte(pkg.ID, ' '); i >= 0 { if i := strings.IndexByte(pkg.ID, ' '); i >= 0 {
pkg.PkgPath = pkg.ID[:i] pkg.PkgPath = pkg.ID[:i]
@ -594,7 +605,9 @@ func golistDriverCurrent(cfg *Config, words ...string) (*driverResponse, error)
response.Roots = append(response.Roots, pkg.ID) response.Roots = append(response.Roots, pkg.ID)
} }
// TODO(matloob): Temporary hack since CompiledGoFiles isn't always set. // Work around for pre-go.1.11 versions of go list.
// TODO(matloob): they should be handled by the fallback.
// Can we delete this?
if len(pkg.CompiledGoFiles) == 0 { if len(pkg.CompiledGoFiles) == 0 {
pkg.CompiledGoFiles = pkg.GoFiles pkg.CompiledGoFiles = pkg.GoFiles
} }

View File

@ -35,6 +35,9 @@ func TestStdlibMetadata(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("failed to load metadata: %v", err) t.Fatalf("failed to load metadata: %v", err)
} }
if packages.PrintErrors(pkgs) > 0 {
t.Fatal("there were errors loading standard library")
}
t1 := time.Now() t1 := time.Now()
runtime.GC() runtime.GC()
@ -99,6 +102,10 @@ func TestCgoOption(t *testing.T) {
t.Errorf("Load failed: %v", err) t.Errorf("Load failed: %v", err)
continue continue
} }
if packages.PrintErrors(pkgs) > 0 {
t.Error("there were errors loading standard library")
continue
}
pkg := pkgs[0] pkg := pkgs[0]
obj := pkg.Types.Scope().Lookup(test.name) obj := pkg.Types.Scope().Lookup(test.name)
if obj == nil { if obj == nil {