Refactor MixedBuildsEnabled and add --ensure-allowlist-integrity.

Currently, there is little verification around allowlisted modules
actually being mixed-built. This flag would allow us to verify
that a module allowlisted is mixed-built for at least one variant.

Bug: 278910100
Test: m nothing --bazel-mode-staging --ensure-allowlist-integrity
Test: m nothing --bazel-mode-staging --ensure-allowlist-integrity
--bazel-force-enabled-modules=com.google.android.neuralnetworks (This
fails, as expected)
Test: build/soong/test/mixed_mode_test.sh

Change-Id: Icd5976f4f44f1a8caca1e5247d986642f7995f97
This commit is contained in:
MarkDacek
2023-04-19 16:47:36 +00:00
parent b420705230
commit f47e142ffd
9 changed files with 136 additions and 41 deletions

View File

@@ -32,6 +32,22 @@ const (
Bp2BuildTopLevel = "."
)
type MixedBuildEnabledStatus int
const (
// This module can be mixed_built.
MixedBuildEnabled = iota
// There is a technical incompatibility preventing this module from being
// bazel-analyzed. Note: the module might also be incompatible.
TechnicalIncompatibility
// This module cannot be mixed_built due to some incompatibility with it
// that is not a platform incompatibility. Example: the module-type is not
// enabled, or is not bp2build-converted.
ModuleIncompatibility
)
// FileGroupAsLibrary describes a filegroup module that is converted to some library
// such as aidl_library or proto_library.
type FileGroupAsLibrary interface {
@@ -346,24 +362,31 @@ func GetBp2BuildAllowList() Bp2BuildConversionAllowlist {
}).(Bp2BuildConversionAllowlist)
}
// MixedBuildsEnabled returns true if a module is ready to be replaced by a
// converted or handcrafted Bazel target. As a side effect, calling this
// method will also log whether this module is mixed build enabled for
// metrics reporting.
func MixedBuildsEnabled(ctx BaseModuleContext) bool {
// MixedBuildsEnabled returns a MixedBuildEnabledStatus regarding whether
// a module is ready to be replaced by a converted or handcrafted Bazel target.
// As a side effect, calling this method will also log whether this module is
// mixed build enabled for metrics reporting.
func MixedBuildsEnabled(ctx BaseModuleContext) MixedBuildEnabledStatus {
module := ctx.Module()
apexInfo := ctx.Provider(ApexInfoProvider).(ApexInfo)
withinApex := !apexInfo.IsForPlatform()
platformIncompatible := isPlatformIncompatible(ctx.Os(), ctx.Arch().ArchType)
if platformIncompatible {
ctx.Config().LogMixedBuild(ctx, false)
return TechnicalIncompatibility
}
mixedBuildEnabled := ctx.Config().IsMixedBuildsEnabled() &&
ctx.Os() != Windows && // Windows toolchains are not currently supported.
ctx.Os() != LinuxBionic && // Linux Bionic toolchains are not currently supported.
ctx.Os() != LinuxMusl && // Linux musl toolchains are not currently supported (b/259266326).
ctx.Arch().ArchType != Riscv64 && // TODO(b/262192655) Riscv64 toolchains are not currently supported.
module.Enabled() &&
convertedToBazel(ctx, module) &&
ctx.Config().BazelContext.IsModuleNameAllowed(module.Name(), withinApex)
ctx.Config().LogMixedBuild(ctx, mixedBuildEnabled)
return mixedBuildEnabled
if mixedBuildEnabled {
return MixedBuildEnabled
}
return ModuleIncompatibility
}
// ConvertedToBazel returns whether this module has been converted (with bp2build or manually) to Bazel.
@@ -388,6 +411,13 @@ type bazelOtherModuleContext interface {
OtherModuleDir(m blueprint.Module) string
}
func isPlatformIncompatible(osType OsType, arch ArchType) bool {
return osType == Windows || // Windows toolchains are not currently supported.
osType == LinuxBionic || // Linux Bionic toolchains are not currently supported.
osType == LinuxMusl || // Linux musl toolchains are not currently supported (b/259266326).
arch == Riscv64 // TODO(b/262192655) Riscv64 toolchains are not currently supported.
}
func (b *BazelModuleBase) shouldConvertWithBp2build(ctx bazelOtherModuleContext, module blueprint.Module) bool {
if !b.bazelProps().Bazel_module.CanConvertToBazel {
return false