From 8dcc6e70cdefe9a82236b6e195e4f4e2108fcb9f Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sat, 23 Feb 2019 16:55:23 -0800 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Michael Matloob --- go/packages/golist.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/go/packages/golist.go b/go/packages/golist.go index e053b5e9cc2..067b008d3c2 100644 --- a/go/packages/golist.go +++ b/go/packages/golist.go @@ -620,16 +620,25 @@ func golistDriverCurrent(cfg *Config, words ...string) (*driverResponse, error) OtherFiles: absJoin(p.Dir, otherFiles(p)...), } - // Workaround for https://golang.org/issue/28749. - // TODO(adonovan): delete before go1.12 release. - out := pkg.CompiledGoFiles[:0] - for _, f := range pkg.CompiledGoFiles { - if strings.HasSuffix(f, ".s") { - continue + // Work around https://golang.org/issue/28749: + // cmd/go puts assembly, C, and C++ files in CompiledGoFiles. + // Filter out any elements of CompiledGoFiles that are also in OtherFiles. + // We have to keep this workaround in place until go1.12 is a distant memory. + if len(pkg.OtherFiles) > 0 { + 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. if i := strings.IndexByte(pkg.ID, ' '); i >= 0 {