Don't create a new module for bp2build conversion.
A performance improvement for bp2build as Blueprint/Soong no longer have
the overhead of additional modules. The creation of these modules
results in:
* traversal of additional modules for each subsequent mutator
* synchronization over a go channel to collect newly created modules:
https://cs.android.com/android/platform/superproject/+/master:build/blueprint/context.go;l=2594,2600;drc=1602226f23181b8c3fbfcaf3358f0297e839d7d3
We avoid both of these by storing the information directly in the
underlying module.
Also as a fringe benefit, removes some necessary boilerplate for
conversion.
For benchmarks, reduces runtime ~1% for 1% converted, ~24% for 100%
converted. See more: go/benchmarks-for-https:-r.android.com-1792714
Test: ran benchmarks/tests in bp2build
Test: build/bazel/ci/bp2build.sh
Change-Id: Ie9273b8cbab5bc6edac1728067ce184382feb211
diff --git a/bp2build/testing.go b/bp2build/testing.go
index faf1a44..266b817 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -140,16 +140,6 @@
customBazelModuleAttributes
}
-func customBazelModuleFactory() android.Module {
- module := &customBazelModule{}
- module.AddProperties(&module.customBazelModuleAttributes)
- android.InitBazelTargetModule(module)
- return module
-}
-
-func (m *customBazelModule) Name() string { return m.BaseModuleName() }
-func (m *customBazelModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
-
func customBp2BuildMutator(ctx android.TopDownMutatorContext) {
if m, ok := ctx.Module().(*customModule); ok {
if !m.ConvertWithBp2build(ctx) {
@@ -178,7 +168,7 @@
Rule_class: "custom",
}
- ctx.CreateBazelTargetModule(customBazelModuleFactory, m.Name(), props, attrs)
+ ctx.CreateBazelTargetModule(m.Name(), props, attrs)
}
}
@@ -197,19 +187,19 @@
Rule_class: "my_library",
Bzl_load_location: "//build/bazel/rules:rules.bzl",
}
- ctx.CreateBazelTargetModule(customBazelModuleFactory, baseName, myLibraryProps, attrs)
+ ctx.CreateBazelTargetModule(baseName, myLibraryProps, attrs)
protoLibraryProps := bazel.BazelTargetModuleProperties{
Rule_class: "proto_library",
Bzl_load_location: "//build/bazel/rules:proto.bzl",
}
- ctx.CreateBazelTargetModule(customBazelModuleFactory, baseName+"_proto_library_deps", protoLibraryProps, attrs)
+ ctx.CreateBazelTargetModule(baseName+"_proto_library_deps", protoLibraryProps, attrs)
myProtoLibraryProps := bazel.BazelTargetModuleProperties{
Rule_class: "my_proto_library",
Bzl_load_location: "//build/bazel/rules:proto.bzl",
}
- ctx.CreateBazelTargetModule(customBazelModuleFactory, baseName+"_my_proto_library_deps", myProtoLibraryProps, attrs)
+ ctx.CreateBazelTargetModule(baseName+"_my_proto_library_deps", myProtoLibraryProps, attrs)
}
}