Merge "bp2build: block src == name for prebuilt_* modules" into main
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 99b67a1..ababd4c 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -1636,10 +1636,6 @@
// depends on libart-unstripped and new module type llvm_prebuilt_build_tool
"check_cfi",
- // TODO(b/297070571): cannot convert prebuilts_etc module which possess identical name and src properties
- "boringssl_self_test.zygote64.rc",
- "boringssl_self_test.zygote64_32.rc",
-
// depends on unconverted module tradefed
"HelloWorldPerformanceTest",
diff --git a/bp2build/prebuilt_etc_conversion_test.go b/bp2build/prebuilt_etc_conversion_test.go
index 5b2d609..e237303 100644
--- a/bp2build/prebuilt_etc_conversion_test.go
+++ b/bp2build/prebuilt_etc_conversion_test.go
@@ -346,3 +346,17 @@
ExpectedErr: fmt.Errorf("label attribute could not be collapsed"),
})
}
+
+func TestPrebuiltEtcNoConversionIfSrcEqualsName(t *testing.T) {
+ runPrebuiltEtcTestCase(t, Bp2buildTestCase{
+ Description: "",
+ Filesystem: map[string]string{},
+ Blueprint: `
+prebuilt_etc {
+ name: "foo",
+ filename: "fooFilename",
+ src: "foo",
+}`,
+ ExpectedBazelTargets: []string{},
+ })
+}
diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go
index 370a423..c48bafa 100644
--- a/etc/prebuilt_etc.go
+++ b/etc/prebuilt_etc.go
@@ -40,6 +40,7 @@
"android/soong/bazel"
"android/soong/bazel/cquery"
"android/soong/snapshot"
+ "android/soong/ui/metrics/bp2build_metrics_proto"
)
var pctx = android.NewPackageContext("android/soong/etc")
@@ -711,7 +712,7 @@
// Bp2buildHelper returns a bazelPrebuiltFileAttributes used for the conversion
// of prebuilt_* modules. bazelPrebuiltFileAttributes has the common attributes
// used by both prebuilt_etc_xml and other prebuilt_* moodules
-func (module *PrebuiltEtc) Bp2buildHelper(ctx android.TopDownMutatorContext) *bazelPrebuiltFileAttributes {
+func (module *PrebuiltEtc) Bp2buildHelper(ctx android.TopDownMutatorContext) (*bazelPrebuiltFileAttributes, bool) {
var src bazel.LabelAttribute
for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltEtcProperties{}) {
for config, p := range configToProps {
@@ -720,7 +721,12 @@
continue
}
if props.Src != nil {
- label := android.BazelLabelForModuleSrcSingle(ctx, *props.Src)
+ srcStr := proptools.String(props.Src)
+ if srcStr == ctx.ModuleName() {
+ ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "src == name")
+ return &bazelPrebuiltFileAttributes{}, false
+ }
+ label := android.BazelLabelForModuleSrcSingle(ctx, srcStr)
src.SetSelectValue(axis, config, label)
}
}
@@ -779,8 +785,7 @@
attrs.Filename_from_src = bazel.BoolAttribute{Value: moduleProps.Filename_from_src}
}
- return attrs
-
+ return attrs, true
}
// ConvertWithBp2build performs bp2build conversion of PrebuiltEtc
@@ -793,7 +798,10 @@
return
}
- attrs := module.Bp2buildHelper(ctx)
+ attrs, convertible := module.Bp2buildHelper(ctx)
+ if !convertible {
+ return
+ }
props := bazel.BazelTargetModuleProperties{
Rule_class: "prebuilt_file",
diff --git a/xml/xml.go b/xml/xml.go
index 8c0c072..20a26f5 100644
--- a/xml/xml.go
+++ b/xml/xml.go
@@ -146,7 +146,11 @@
}
func (p *prebuiltEtcXml) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
- baseAttrs := p.PrebuiltEtc.Bp2buildHelper(ctx)
+ baseAttrs, convertible := p.PrebuiltEtc.Bp2buildHelper(ctx)
+
+ if !convertible {
+ return
+ }
var schema *string
if p.properties.Schema != nil {