From 94d26c2bc0e31929c5f5c758654343d2275bd3c2 Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Fri, 25 Feb 2022 21:34:51 +0000 Subject: [PATCH] prevent module being enabled if in existing BUILD file If a module is enabled via the module-level allow list, bp2buildModuleAlwaysConvertList, then we should error if that same module is hidden by an existing BUILD file. Bug: 220875679 Test: add a module in a directory covered by an existing BUILD file Change-Id: I5426bd9edac593690c0989b68a421ac1c3216010 --- android/bazel.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/android/bazel.go b/android/bazel.go index 7714f2ceb..e84eb6859 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -676,14 +676,21 @@ func (b *BazelModuleBase) shouldConvertWithBp2build(ctx BazelConversionContext, } packagePath := ctx.OtherModuleDir(module) - config := ctx.Config().bp2buildPackageConfig + if alwaysConvert && ShouldKeepExistingBuildFileForDir(packagePath) { + ctx.(BaseModuleContext).ModuleErrorf("A module cannot be in a directory listed in bp2buildKeepExistingBuildFile"+ + " and also be in bp2buildModuleAlwaysConvert. Directory: '%s'", packagePath) + return false + } + + config := ctx.Config().bp2buildPackageConfig // 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") + ctx.(BaseModuleContext).ModuleErrorf("A module cannot be in a directory marked Bp2BuildDefaultTrue"+ + " or Bp2BuildDefaultTrueRecursively and also be in bp2buildModuleAlwaysConvert. Directory: '%s'", + packagePath) } // Allow modules to explicitly opt-out.