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/cc/binary.go b/cc/binary.go
index 50175d9..b59e762 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -558,13 +558,6 @@
}
func binaryBp2build(ctx android.TopDownMutatorContext, m *Module, typ string) {
- var compatibleWith bazel.StringListAttribute
- if typ == "cc_binary_host" {
- //incompatible with android OS
- compatibleWith.SetSelectValue(bazel.OsConfigurationAxis, android.Android.Name, []string{"@platforms//:incompatible"})
- compatibleWith.SetSelectValue(bazel.OsConfigurationAxis, bazel.ConditionsDefaultConfigKey, []string{})
- }
-
baseAttrs := bp2BuildParseBaseProps(ctx, m)
binaryLinkerAttrs := bp2buildBinaryLinkerProps(ctx, m)
@@ -610,16 +603,22 @@
None: baseAttrs.stripNone,
},
- Target_compatible_with: compatibleWith,
- Features: baseAttrs.features,
+ Features: baseAttrs.features,
}
- ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
+ var enabledProperty bazel.BoolAttribute
+ if typ == "cc_binary_host" {
+ falseVal := false
+ enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, android.Android.Name, &falseVal)
+ }
+
+ ctx.CreateBazelTargetModuleWithRestrictions(bazel.BazelTargetModuleProperties{
Rule_class: "cc_binary",
Bzl_load_location: "//build/bazel/rules:cc_binary.bzl",
},
android.CommonAttributes{Name: m.Name()},
- attrs)
+ attrs,
+ enabledProperty)
}
// binaryAttributes contains Bazel attributes corresponding to a cc binary
@@ -655,6 +654,4 @@
Strip stripAttributes
Features bazel.StringListAttribute
-
- Target_compatible_with bazel.StringListAttribute
}
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 2119ee4..e4762a0 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -57,6 +57,8 @@
Implementation_whole_archive_deps bazel.LabelListAttribute
System_dynamic_deps bazel.LabelListAttribute
+
+ Enabled bazel.BoolAttribute
}
func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute {
@@ -175,6 +177,7 @@
attrs.Implementation_dynamic_deps.SetSelectValue(axis, config, sharedDeps.implementation)
attrs.Whole_archive_deps.SetSelectValue(axis, config, bazelLabelForWholeDeps(ctx, props.Whole_static_libs))
+ attrs.Enabled.SetSelectValue(axis, config, props.Enabled)
}
// system_dynamic_deps distinguishes between nil/empty list behavior:
// nil -> use default values
diff --git a/cc/cc.go b/cc/cc.go
index 22baf30..281ebc1 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -3461,8 +3461,15 @@
objectBp2Build(ctx, c)
}
} else if c.CcLibrary() {
- static := c.BuildStaticVariant()
- shared := c.BuildSharedVariant()
+ static := false
+ shared := false
+ if library, ok := c.linker.(*libraryDecorator); ok {
+ static = library.MutatedProperties.BuildStatic
+ shared = library.MutatedProperties.BuildShared
+ } else if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
+ static = library.MutatedProperties.BuildStatic
+ shared = library.MutatedProperties.BuildShared
+ }
if static && shared {
if !prebuilt {
diff --git a/cc/library.go b/cc/library.go
index 216c124..5720944 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -392,8 +392,12 @@
Bzl_load_location: "//build/bazel/rules:cc_library_shared.bzl",
}
- ctx.CreateBazelTargetModule(staticProps, android.CommonAttributes{Name: m.Name() + "_bp2build_cc_library_static"}, staticTargetAttrs)
- ctx.CreateBazelTargetModule(sharedProps, android.CommonAttributes{Name: m.Name()}, sharedTargetAttrs)
+ ctx.CreateBazelTargetModuleWithRestrictions(staticProps,
+ android.CommonAttributes{Name: m.Name() + "_bp2build_cc_library_static"},
+ staticTargetAttrs, staticAttrs.Enabled)
+ ctx.CreateBazelTargetModuleWithRestrictions(sharedProps,
+ android.CommonAttributes{Name: m.Name()},
+ sharedTargetAttrs, sharedAttrs.Enabled)
}
// cc_library creates both static and/or shared libraries for a device and/or
diff --git a/cc/object.go b/cc/object.go
index bd43e36..24f6ed4 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -155,7 +155,8 @@
for config, props := range configToProps {
if objectLinkerProps, ok := props.(*ObjectLinkerProperties); ok {
if objectLinkerProps.Linker_script != nil {
- linkerScript.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *objectLinkerProps.Linker_script))
+ label := android.BazelLabelForModuleSrcSingle(ctx, *objectLinkerProps.Linker_script)
+ linkerScript.SetSelectValue(axis, config, label)
}
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Objs))
systemSharedLibs := objectLinkerProps.System_shared_libs