Skip to content

Commit

Permalink
perf(gazelle): cache fs check for BUILD files (#3951)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: f2e0e86c9d5b5a9ceceb9451ef4a6fab97f7de35
  • Loading branch information
jbedard authored and gregmagolan committed Dec 5, 2023
1 parent 5e743a0 commit 1c190cc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gazelle/common/bazel.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@ import (
var (
// BUILD file names.
buildFileNames = []string{"BUILD", "BUILD.bazel"}

// A set of already-seen Bazel packages so we avoid doing
// disk IO over and over to determine if a directory is a Bazel package.
isPackageCache = make(map[string]bool)
)

// IsBazelPackage determines if the directory is a Bazel package by probing for
// the existence of a known BUILD file name.
func IsBazelPackage(dir string) bool {
if isPkg, cached := isPackageCache[dir]; cached {
return isPkg
}

for _, buildFilename := range buildFileNames {
buildPath := path.Join(dir, buildFilename)
if _, err := os.Stat(buildPath); err == nil {
isPackageCache[dir] = true
return true
}
}
isPackageCache[dir] = false
return false
}

Expand Down

0 comments on commit 1c190cc

Please sign in to comment.