Merge "add a module-level allowlist to bp2build"

This commit is contained in:
Sam Delmerico 2022-02-25 15:23:00 +00:00 committed by Gerrit Code Review
commit b0b94f6182

View file

@ -379,6 +379,11 @@ var (
"tools/platform-compat/java/android/compat": Bp2BuildDefaultTrueRecursively, "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. // Per-module denylist to always opt modules out of both bp2build and mixed builds.
bp2buildModuleDoNotConvertList = []string{ bp2buildModuleDoNotConvertList = []string{
"libnativehelper_compat_libc", // Broken compile: implicit declaration of function 'strerror_r' is invalid in C99 "libnativehelper_compat_libc", // Broken compile: implicit declaration of function 'strerror_r' is invalid in C99
@ -569,11 +574,16 @@ var (
// Used for quicker lookups // Used for quicker lookups
bp2buildModuleDoNotConvert = map[string]bool{} bp2buildModuleDoNotConvert = map[string]bool{}
bp2buildModuleAlwaysConvert = map[string]bool{}
bp2buildCcLibraryStaticOnly = map[string]bool{} bp2buildCcLibraryStaticOnly = map[string]bool{}
mixedBuildsDisabled = map[string]bool{} mixedBuildsDisabled = map[string]bool{}
) )
func init() { func init() {
for _, moduleName := range bp2buildModuleAlwaysConvertList {
bp2buildModuleAlwaysConvert[moduleName] = true
}
for _, moduleName := range bp2buildModuleDoNotConvertList { for _, moduleName := range bp2buildModuleDoNotConvertList {
bp2buildModuleDoNotConvert[moduleName] = true bp2buildModuleDoNotConvert[moduleName] = true
} }
@ -649,7 +659,14 @@ func (b *BazelModuleBase) ShouldConvertWithBp2build(ctx BazelConversionContext)
} }
func (b *BazelModuleBase) shouldConvertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool { 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 return false
} }
@ -663,12 +680,17 @@ func (b *BazelModuleBase) shouldConvertWithBp2build(ctx BazelConversionContext,
// This is a tristate value: true, false, or unset. // This is a tristate value: true, false, or unset.
propValue := b.bazelProperties.Bazel_module.Bp2build_available propValue := b.bazelProperties.Bazel_module.Bp2build_available
if bp2buildDefaultTrueRecursively(packagePath, config) { 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. // Allow modules to explicitly opt-out.
return proptools.BoolDefault(propValue, true) return proptools.BoolDefault(propValue, true)
} }
// Allow modules to explicitly opt-in. // 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 // bp2buildDefaultTrueRecursively checks that the package contains a prefix from the