find bazel-related files and add them to bazel.list and ninja deps

This retriggers soong_build whenever a new bzl, WORKSPACE, or
BUILD.bazel file is changed or added.

Test: Manually verified on bionic/libc genrules with manual changes to
related BUILD/bzl/WORKSPACE files -- these all retrigger builds.
Test: Updated finder_test.go

Change-Id: I634384f88781a6b6db32f5d6bf9c07e179e14c39
This commit is contained in:
Chris Parsons
2020-10-12 23:44:08 -04:00
parent 19bc60abee
commit a798d96076
5 changed files with 126 additions and 7 deletions

View File

@@ -63,10 +63,13 @@ func NewSourceFinder(ctx Context, config Config) (f *finder.Finder) {
"AndroidProducts.mk",
"Android.bp",
"Blueprints",
"BUILD.bazel",
"CleanSpec.mk",
"OWNERS",
"TEST_MAPPING",
"WORKSPACE",
},
IncludeSuffixes: []string{".bzl"},
}
dumpDir := config.FileListDir()
f, err = finder.New(cacheParams, filesystem, logger.New(ioutil.Discard),
@@ -77,6 +80,16 @@ func NewSourceFinder(ctx Context, config Config) (f *finder.Finder) {
return f
}
func findBazelFiles(entries finder.DirEntries) (dirNames []string, fileNames []string) {
matches := []string{}
for _, foundName := range entries.FileNames {
if foundName == "BUILD.bazel" || foundName == "WORKSPACE" || strings.HasSuffix(foundName, ".bzl") {
matches = append(matches, foundName)
}
}
return entries.DirNames, matches
}
// FindSources searches for source files known to <f> and writes them to the filesystem for
// use later.
func FindSources(ctx Context, config Config, f *finder.Finder) {
@@ -99,6 +112,12 @@ func FindSources(ctx Context, config Config, f *finder.Finder) {
ctx.Fatalf("Could not export product list: %v", err)
}
bazelFiles := f.FindMatching(".", findBazelFiles)
err = dumpListToFile(ctx, config, bazelFiles, filepath.Join(dumpDir, "bazel.list"))
if err != nil {
ctx.Fatalf("Could not export bazel BUILD list: %v", err)
}
cleanSpecs := f.FindFirstNamedAt(".", "CleanSpec.mk")
err = dumpListToFile(ctx, config, cleanSpecs, filepath.Join(dumpDir, "CleanSpec.mk.list"))
if err != nil {