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/android/mutator.go b/android/mutator.go
index d895669..20ec621 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -270,7 +270,7 @@
// factory method, just like in CreateModule, but also requires
// BazelTargetModuleProperties containing additional metadata for the
// bp2build codegenerator.
- CreateBazelTargetModule(ModuleFactory, string, bazel.BazelTargetModuleProperties, interface{}) BazelTargetModule
+ CreateBazelTargetModule(string, bazel.BazelTargetModuleProperties, interface{})
}
type topDownMutatorContext struct {
@@ -516,26 +516,24 @@
}
func (t *topDownMutatorContext) CreateBazelTargetModule(
- factory ModuleFactory,
name string,
bazelProps bazel.BazelTargetModuleProperties,
- attrs interface{}) BazelTargetModule {
+ attrs interface{}) {
if strings.HasPrefix(name, bazel.BazelTargetModuleNamePrefix) {
panic(fmt.Errorf(
"The %s name prefix is added automatically, do not set it manually: %s",
bazel.BazelTargetModuleNamePrefix,
name))
}
- name = bazel.BazelTargetModuleNamePrefix + name
- nameProp := struct {
- Name *string
- }{
- Name: &name,
+
+ info := bp2buildInfo{
+ Name: name,
+ Dir: t.OtherModuleDir(t.Module()),
+ BazelProps: bazelProps,
+ Attrs: attrs,
}
- b := t.createModuleWithoutInheritance(factory, &nameProp, attrs).(BazelTargetModule)
- b.SetBazelTargetModuleProperties(bazelProps)
- return b
+ t.Module().base().addBp2buildInfo(info)
}
func (t *topDownMutatorContext) AppendProperties(props ...interface{}) {