go/packages: expand CompiledGoFiles workaround

Updates golang/go#28749

Change-Id: I76eb264f61b511fec7e05cef1bdd35e1c7fd603b
Reviewed-on: https://go-review.googlesource.com/c/163597
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2019-02-23 16:55:23 -08:00
parent f727befe75
commit 8dcc6e70cd
1 changed files with 17 additions and 8 deletions

View File

@ -620,16 +620,25 @@ func golistDriverCurrent(cfg *Config, words ...string) (*driverResponse, error)
OtherFiles: absJoin(p.Dir, otherFiles(p)...), OtherFiles: absJoin(p.Dir, otherFiles(p)...),
} }
// Workaround for https://golang.org/issue/28749. // Work around https://golang.org/issue/28749:
// TODO(adonovan): delete before go1.12 release. // cmd/go puts assembly, C, and C++ files in CompiledGoFiles.
out := pkg.CompiledGoFiles[:0] // Filter out any elements of CompiledGoFiles that are also in OtherFiles.
for _, f := range pkg.CompiledGoFiles { // We have to keep this workaround in place until go1.12 is a distant memory.
if strings.HasSuffix(f, ".s") { if len(pkg.OtherFiles) > 0 {
continue other := make(map[string]bool, len(pkg.OtherFiles))
for _, f := range pkg.OtherFiles {
other[f] = true
} }
out = append(out, f)
out := pkg.CompiledGoFiles[:0]
for _, f := range pkg.CompiledGoFiles {
if other[f] {
continue
}
out = append(out, f)
}
pkg.CompiledGoFiles = out
} }
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 {