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/module.go b/android/module.go
index 7451e09..b571f15 100644
--- a/android/module.go
+++ b/android/module.go
@@ -491,6 +491,11 @@
AddProperties(props ...interface{})
GetProperties() []interface{}
+ // IsConvertedByBp2build returns whether this module was converted via bp2build
+ IsConvertedByBp2build() bool
+ // Bp2buildTargets returns the target(s) generated for Bazel via bp2build for this module
+ Bp2buildTargets() []bp2buildInfo
+
BuildParamsForTests() []BuildParams
RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
VariablesForTests() map[string]string
@@ -878,6 +883,11 @@
// for example "" for core or "recovery" for recovery. It will often be set to one of the
// constants in image.go, but can also be set to a custom value by individual module types.
ImageVariation string `blueprint:"mutated"`
+
+ // Information about _all_ bp2build targets generated by this module. Multiple targets are
+ // supported as Soong handles some things within a single target that we may choose to split into
+ // multiple targets, e.g. renderscript, protos, yacc within a cc module.
+ Bp2buildInfo []bp2buildInfo `blueprint:"mutated"`
}
type distProperties struct {
@@ -1204,6 +1214,54 @@
vintfFragmentsPaths Paths
}
+// A struct containing all relevant information about a Bazel target converted via bp2build.
+type bp2buildInfo struct {
+ Name string
+ Dir string
+ BazelProps bazel.BazelTargetModuleProperties
+ Attrs interface{}
+}
+
+// TargetName returns the Bazel target name of a bp2build converted target.
+func (b bp2buildInfo) TargetName() string {
+ return b.Name
+}
+
+// TargetPackage returns the Bazel package of a bp2build converted target.
+func (b bp2buildInfo) TargetPackage() string {
+ return b.Dir
+}
+
+// BazelRuleClass returns the Bazel rule class of a bp2build converted target.
+func (b bp2buildInfo) BazelRuleClass() string {
+ return b.BazelProps.Rule_class
+}
+
+// BazelRuleLoadLocation returns the location of the Bazel rule of a bp2build converted target.
+// This may be empty as native Bazel rules do not need to be loaded.
+func (b bp2buildInfo) BazelRuleLoadLocation() string {
+ return b.BazelProps.Bzl_load_location
+}
+
+// BazelAttributes returns the Bazel attributes of a bp2build converted target.
+func (b bp2buildInfo) BazelAttributes() interface{} {
+ return b.Attrs
+}
+
+func (m *ModuleBase) addBp2buildInfo(info bp2buildInfo) {
+ m.commonProperties.Bp2buildInfo = append(m.commonProperties.Bp2buildInfo, info)
+}
+
+// IsConvertedByBp2build returns whether this module was converted via bp2build.
+func (m *ModuleBase) IsConvertedByBp2build() bool {
+ return len(m.commonProperties.Bp2buildInfo) > 0
+}
+
+// Bp2buildTargets returns the Bazel targets bp2build generated for this module.
+func (m *ModuleBase) Bp2buildTargets() []bp2buildInfo {
+ return m.commonProperties.Bp2buildInfo
+}
+
func (m *ModuleBase) AddJSONData(d *map[string]interface{}) {
(*d)["Android"] = map[string]interface{}{}
}