diff options
author | Vincent Ambo <tazjin@google.com> | 2019-12-12T23·53+0000 |
---|---|---|
committer | Vincent Ambo <mail@tazj.in> | 2019-12-13T00·39+0000 |
commit | 218b81c709248784112ae7bd0646c7fc6773fe5f (patch) | |
tree | a87f609704a5c2e231d7eae7a73bcdbc1fd95e2f /external/main.go | |
parent | 39e73f42b21e369906442fc3235cf9ce62f25ce1 (diff) |
fix(external): Skip folders with "no buildable Go files"
This error is returned by the build analysis logic if the target package does not have any relevant Go files, which might be the case if `+build` flags and such are used.
Diffstat (limited to 'external/main.go')
-rw-r--r-- | external/main.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/external/main.go b/external/main.go index 23fd53326ed0..e0b95605f0dd 100644 --- a/external/main.go +++ b/external/main.go @@ -43,14 +43,15 @@ func findGoDirs(at string) ([]string, error) { dirSet := make(map[string]bool) err := filepath.Walk(at, func(path string, info os.FileInfo, err error) error { + name := info.Name() // Skip folders that are guaranteed to not be relevant - if info.IsDir() && (info.Name() == "testdata" || info.Name() == ".git") { + if info.IsDir() && (name == "testdata" || name == ".git") { return filepath.SkipDir } // If the current file is a Go file, then the directory is popped // (i.e. marked as a Go directory). - if !info.IsDir() && strings.HasSuffix(info.Name(), ".go") && !strings.HasSuffix(info.Name(), "_test.go") { + if !info.IsDir() && strings.HasSuffix(name, ".go") && !strings.HasSuffix(name, "_test.go") { dirSet[filepath.Dir(path)] = true } @@ -154,6 +155,16 @@ func main() { all := []pkg{} for _, d := range goDirs { analysed, err := analysePackage(*source, d, *path, stdlibPkgs) + + // If the Go source analysis returned "no buildable Go files", + // that directory should be skipped. + // + // This might be due to `+build` flags on the platform and other + // reasons (such as test files). + if _, ok := err.(*build.NoGoError); ok { + continue + } + if err != nil { log.Fatalf("failed to analyse package at %q: %s", d, err) } |