From dff00ea5090a7ebfd55a3906dd60b379bd6685bd Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Mon, 4 Oct 2021 13:44:34 -0400 Subject: [PATCH] Handle arch-variant in prebuilt_etc For cc_binary, changing the handling of version_script to no longer be a LabelAttribute, which reduces test coverage of that type. Expand prebuilt_etc to handle arch-variant srcs and correct a bug in LabelAttribute. Test: build/bazel/ci/bp2build.sh Change-Id: I620bc3a43b28c1873f335e30099844ca79ce94c1 --- bp2build/configurability.go | 6 ++++ bp2build/prebuilt_etc_conversion_test.go | 37 ++++++++++++++++++++++++ etc/prebuilt_etc.go | 12 ++++++-- 3 files changed, 53 insertions(+), 2 deletions(-) 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 85abf5998..408eb514a 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