Handle the 'enabled' property in bp2build
Also fix some bugs pertaining to configurable attribute handling of bool
attributes and label sttributes, so that they may support values across
multiple different axes at the same time.
Test: unit tests for bp2build
Test: mixed_droid
Change-Id: I411efcfddf02d55dbc0775962068a11348a8bb2c
diff --git a/android/mutator.go b/android/mutator.go
index dbd8c04..fa6f2be8 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -254,6 +254,14 @@
// BazelTargetModuleProperties containing additional metadata for the
// bp2build codegenerator.
CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{})
+
+ // CreateBazelTargetModuleWithRestrictions creates a BazelTargetModule by calling the
+ // factory method, just like in CreateModule, but also requires
+ // BazelTargetModuleProperties containing additional metadata for the
+ // bp2build codegenerator. The generated target is restricted to only be buildable for certain
+ // platforms, as dictated by a given bool attribute: the target will not be buildable in
+ // any platform for which this bool attribute is false.
+ CreateBazelTargetModuleWithRestrictions(bazel.BazelTargetModuleProperties, CommonAttributes, interface{}, bazel.BoolAttribute)
}
type topDownMutatorContext struct {
@@ -502,13 +510,30 @@
bazelProps bazel.BazelTargetModuleProperties,
commonAttrs CommonAttributes,
attrs interface{}) {
- commonAttrs.fillCommonBp2BuildModuleAttrs(t)
+ t.createBazelTargetModule(bazelProps, commonAttrs, attrs, bazel.BoolAttribute{})
+}
+
+func (t *topDownMutatorContext) CreateBazelTargetModuleWithRestrictions(
+ bazelProps bazel.BazelTargetModuleProperties,
+ commonAttrs CommonAttributes,
+ attrs interface{},
+ enabledProperty bazel.BoolAttribute) {
+ t.createBazelTargetModule(bazelProps, commonAttrs, attrs, enabledProperty)
+}
+
+func (t *topDownMutatorContext) createBazelTargetModule(
+ bazelProps bazel.BazelTargetModuleProperties,
+ commonAttrs CommonAttributes,
+ attrs interface{},
+ enabledProperty bazel.BoolAttribute) {
+ constraintAttributes := commonAttrs.fillCommonBp2BuildModuleAttrs(t, enabledProperty)
mod := t.Module()
info := bp2buildInfo{
- Dir: t.OtherModuleDir(mod),
- BazelProps: bazelProps,
- CommonAttrs: commonAttrs,
- Attrs: attrs,
+ Dir: t.OtherModuleDir(mod),
+ BazelProps: bazelProps,
+ CommonAttrs: commonAttrs,
+ ConstraintAttrs: constraintAttributes,
+ Attrs: attrs,
}
mod.base().addBp2buildInfo(info)
}