diff --git a/bp2build/configurability.go b/bp2build/configurability.go index 005f13dd2..0bcf91d58 100644 --- a/bp2build/configurability.go +++ b/bp2build/configurability.go @@ -48,6 +48,12 @@ func getLabelValue(label bazel.LabelAttribute) (reflect.Value, []selects) { } } + // if there is a select, use the base value as the conditions default value + if len(ret) > 0 { + ret[bazel.ConditionsDefaultSelectKey] = value + value = reflect.Zero(value.Type()) + } + return value, []selects{ret} } diff --git a/bp2build/prebuilt_etc_conversion_test.go b/bp2build/prebuilt_etc_conversion_test.go index 4e25d1be2..62e407bf1 100644 --- a/bp2build/prebuilt_etc_conversion_test.go +++ b/bp2build/prebuilt_etc_conversion_test.go @@ -53,3 +53,40 @@ prebuilt_etc { sub_dir = "tz", )`}}) } + +func TestPrebuiltEtcArchVariant(t *testing.T) { + runPrebuiltEtcTestCase(t, bp2buildTestCase{ + description: "prebuilt_etc - simple example", + moduleTypeUnderTest: "prebuilt_etc", + moduleTypeUnderTestFactory: etc.PrebuiltEtcFactory, + moduleTypeUnderTestBp2BuildMutator: etc.PrebuiltEtcBp2Build, + filesystem: map[string]string{}, + blueprint: ` +prebuilt_etc { + name: "apex_tz_version", + src: "version/tz_version", + filename: "tz_version", + sub_dir: "tz", + installable: false, + arch: { + arm: { + src: "arm", + }, + arm64: { + src: "arm64", + }, + } +} +`, + expectedBazelTargets: []string{`prebuilt_etc( + name = "apex_tz_version", + filename = "tz_version", + installable = False, + src = select({ + "//build/bazel/platforms/arch:arm": "arm", + "//build/bazel/platforms/arch:arm64": "arm64", + "//conditions:default": "version/tz_version", + }), + sub_dir = "tz", +)`}}) +} diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go index 81896bd68..a1ce8dc8e 100644 --- a/etc/prebuilt_etc.go +++ b/etc/prebuilt_etc.go @@ -673,8 +673,16 @@ func PrebuiltEtcBp2Build(ctx android.TopDownMutatorContext) { func prebuiltEtcBp2BuildInternal(ctx android.TopDownMutatorContext, module *PrebuiltEtc) { var srcLabelAttribute bazel.LabelAttribute - if module.properties.Src != nil { - srcLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Src)) + for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltEtcProperties{}) { + for config, p := range configToProps { + props, ok := p.(*prebuiltEtcProperties) + if !ok { + continue + } + if props.Src != nil { + srcLabelAttribute.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *props.Src)) + } + } } var filename string