Use one mutator for all bp2build conversion.
Each conversion required defining a separate mutator, which will each
operate on _all_ modules and requires each to repeat checks whether the
mutator should operator. Instead, we introduce a single mutator and
modules can define a ConvertWithBp2build to implement bp2build
conversion for that module.
Test: bp2build.sh
Bug: 183079158
Change-Id: I99d4b51f441c2903879092c5b56313d606d4338d
diff --git a/cc/binary.go b/cc/binary.go
index e839122..50175d9 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -69,13 +69,14 @@
// cc_binary produces a binary that is runnable on a device.
func BinaryFactory() android.Module {
- module, _ := NewBinary(android.HostAndDeviceSupported)
+ module, _ := newBinary(android.HostAndDeviceSupported, true)
return module.Init()
}
// cc_binary_host produces a binary that is runnable on a host.
func BinaryHostFactory() android.Module {
- module, _ := NewBinary(android.HostSupported)
+ module, _ := newBinary(android.HostSupported, true)
+ module.bazelable = true
return module.Init()
}
@@ -193,6 +194,10 @@
// Individual module implementations which comprise a C++ binary should call this function,
// set some fields on the result, and then call the Init function.
func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
+ return newBinary(hod, true)
+}
+
+func newBinary(hod android.HostOrDeviceSupported, bazelable bool) (*Module, *binaryDecorator) {
module := newModule(hod, android.MultilibFirst)
binary := &binaryDecorator{
baseLinker: NewBaseLinker(module.sanitize),
@@ -201,6 +206,7 @@
module.compiler = NewBaseCompiler()
module.linker = binary
module.installer = binary
+ module.bazelable = bazelable
// Allow module to be added as member of an sdk/module_exports.
module.sdkMemberTypes = []android.SdkMemberType{
@@ -551,33 +557,7 @@
})
}
-func init() {
- android.RegisterBp2BuildMutator("cc_binary", BinaryBp2build)
- android.RegisterBp2BuildMutator("cc_binary_host", BinaryHostBp2build)
-}
-
-func BinaryBp2build(ctx android.TopDownMutatorContext) {
- binaryBp2build(ctx, "cc_binary")
-}
-
-func BinaryHostBp2build(ctx android.TopDownMutatorContext) {
- binaryBp2build(ctx, "cc_binary_host")
-}
-
-func binaryBp2build(ctx android.TopDownMutatorContext, typ string) {
- m, ok := ctx.Module().(*Module)
- if !ok {
- // Not a cc module
- return
- }
- if !m.ConvertWithBp2build(ctx) {
- return
- }
-
- if ctx.ModuleType() != typ {
- return
- }
-
+func binaryBp2build(ctx android.TopDownMutatorContext, m *Module, typ string) {
var compatibleWith bazel.StringListAttribute
if typ == "cc_binary_host" {
//incompatible with android OS