From fa1831c2008c93e9a68309f6f4ef6e0d6c48c264 Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Tue, 22 Feb 2022 18:07:55 +0000 Subject: [PATCH] add a module-level allowlist to bp2build We currently enabled modules in bp2build on a package level, and we disable individual modules based on a denylist. To enable a specific module individually, we must change the corresponding Android.bp file to include a bp2build_available property. Instead, have a centralized list of specifically enabled modules. Bug: 220875679 Test: m bp2build Change-Id: I908f2f2366b72affb04234fbe92ba03bf5a37338 --- android/bazel.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/android/bazel.go b/android/bazel.go index f4fc03838..becf98822 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -379,6 +379,11 @@ var ( "tools/platform-compat/java/android/compat": Bp2BuildDefaultTrueRecursively, } + // Per-module allowlist to always opt modules in of both bp2build and mixed builds. + bp2buildModuleAlwaysConvertList = []string{ + "junit-params-assertj-core", + } + // Per-module denylist to always opt modules out of both bp2build and mixed builds. bp2buildModuleDoNotConvertList = []string{ "libnativehelper_compat_libc", // Broken compile: implicit declaration of function 'strerror_r' is invalid in C99 @@ -569,11 +574,16 @@ var ( // Used for quicker lookups bp2buildModuleDoNotConvert = map[string]bool{} + bp2buildModuleAlwaysConvert = map[string]bool{} bp2buildCcLibraryStaticOnly = map[string]bool{} mixedBuildsDisabled = map[string]bool{} ) func init() { + for _, moduleName := range bp2buildModuleAlwaysConvertList { + bp2buildModuleAlwaysConvert[moduleName] = true + } + for _, moduleName := range bp2buildModuleDoNotConvertList { bp2buildModuleDoNotConvert[moduleName] = true } @@ -649,7 +659,14 @@ func (b *BazelModuleBase) ShouldConvertWithBp2build(ctx BazelConversionContext) } func (b *BazelModuleBase) shouldConvertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool { - if bp2buildModuleDoNotConvert[module.Name()] { + moduleNameNoPrefix := RemoveOptionalPrebuiltPrefix(module.Name()) + alwaysConvert := bp2buildModuleAlwaysConvert[moduleNameNoPrefix] + + if bp2buildModuleDoNotConvert[moduleNameNoPrefix] { + if alwaysConvert { + ctx.(BaseModuleContext).ModuleErrorf("a module cannot be in bp2buildModuleDoNotConvert" + + " and also be in bp2buildModuleAlwaysConvert") + } return false } @@ -663,12 +680,17 @@ func (b *BazelModuleBase) shouldConvertWithBp2build(ctx BazelConversionContext, // This is a tristate value: true, false, or unset. propValue := b.bazelProperties.Bazel_module.Bp2build_available if bp2buildDefaultTrueRecursively(packagePath, config) { + if alwaysConvert { + ctx.(BaseModuleContext).ModuleErrorf("a module cannot be in a directory marked Bp2BuildDefaultTrue" + + " or Bp2BuildDefaultTrueRecursively and also be in bp2buildModuleAlwaysConvert") + } + // Allow modules to explicitly opt-out. return proptools.BoolDefault(propValue, true) } // Allow modules to explicitly opt-in. - return proptools.BoolDefault(propValue, false) + return proptools.BoolDefault(propValue, alwaysConvert) } // bp2buildDefaultTrueRecursively checks that the package contains a prefix from the