Read BUILD files in bp2build
The parsed BUILD files will be scanned for obvious definitions of BUILD
targets which have Android.bp counterparts. In such cases, bp2build will
automatically omit conversion of these defined modules (to prevent
collisions). With this change, we no longer need one-off denylisting of
modules which have BUILD file definitions.
This has a 0.03s to 0.2s slowdown for bp2build with current state. This
impact is identical on a heavier test branch, as well. I also ran an
experiment that applied BUILD scanning to all source BUILD files
(regardless of allowlisting), and this had a 2 second slowdown.
We may want to look into parallelizing or improving the performance of
this evaluation, but it's probably not worth the effort at this time,
since the current performance hit is small.
Test: New integration test
Test: Removed libprotobuf-python from denylist and tested building the
package
Test: Treehugger
Change-Id: Ibde3bab12cd4a8fed642ad46e5344a56953bec91
diff --git a/android/config.go b/android/config.go
index d4703ff..90dbe0b 100644
--- a/android/config.go
+++ b/android/config.go
@@ -291,6 +291,10 @@
// "--bazel-force-enabled-modules"
bazelForceEnabledModules map[string]struct{}
+ // Names of Bazel targets as defined by BUILD files in the source tree,
+ // keyed by the directory in which they are defined.
+ bazelTargetsByDir map[string][]string
+
// If true, for any requests to Bazel, communicate with a Bazel proxy using
// unix sockets, instead of spawning Bazel as a subprocess.
UseBazelProxy bool
@@ -2002,6 +2006,20 @@
}
}
+func (c *config) HasBazelBuildTargetInSource(ctx BaseModuleContext) bool {
+ moduleName := ctx.Module().Name()
+ for _, buildTarget := range c.bazelTargetsByDir[ctx.ModuleDir()] {
+ if moduleName == buildTarget {
+ return true
+ }
+ }
+ return false
+}
+
+func (c *config) SetBazelBuildFileTargets(bazelTargetsByDir map[string][]string) {
+ c.bazelTargetsByDir = bazelTargetsByDir
+}
+
// ApiSurfaces directory returns the source path inside the api_surfaces repo
// (relative to workspace root).
func (c *config) ApiSurfacesDir(s ApiSurface, version string) string {