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/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 875ed34..f826f5c 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -461,6 +461,9 @@
// TODO(b/266459895): remove this and the placeholder BUILD file after re-enabling libunwindstack
"external/rust/crates/rustc-demangle-capi":/* recursive = */ false,
+
+ // Used for testing purposes only. Should not actually exist in the real source tree.
+ "testpkg/keep_build_file":/* recursive = */ false,
}
Bp2buildModuleAlwaysConvertList = []string{
@@ -845,9 +848,6 @@
"libbase_ndk", // TODO(b/186826477): fails to link libctscamera2_jni for device (required for CtsCameraTestCases)
"bouncycastle", // TODO(b/274474005): Need support for custom system_modules.
- // python protos
- "libprotobuf-python", // Has a handcrafted alternative
-
// genrule incompatibilities
"brotli-fuzzer-corpus", // TODO(b/202015218): outputs are in location incompatible with bazel genrule handling.
"platform_tools_properties", "build_tools_source_properties", // TODO(b/203369847): multiple genrules in the same package creating the same file
diff --git a/android/bazel.go b/android/bazel.go
index d326634..e631ed4 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -537,6 +537,12 @@
}
func convertWithBp2build(ctx TopDownMutatorContext) {
+ if ctx.Config().HasBazelBuildTargetInSource(ctx) {
+ // Defer to the BUILD target. Generating an additional target would
+ // cause a BUILD file conflict.
+ return
+ }
+
bModule, ok := ctx.Module().(Bazelable)
if !ok || !bModule.shouldConvertWithBp2build(ctx, ctx.Module()) {
return
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 {