Merge "Fix bp2build for cc_aidl_library to use LabelListAttribute.Partition"

This commit is contained in:
Vinh Tran
2022-09-16 22:02:40 +00:00
committed by Gerrit Code Review

View File

@@ -746,60 +746,37 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
}
}
func bp2buildAidlLibraries(
func bp2buildCcAidlLibrary(
ctx android.Bp2buildMutatorContext,
m *Module,
aidlSrcs bazel.LabelListAttribute,
) bazel.LabelList {
var aidlLibraries bazel.LabelList
var directAidlSrcs bazel.LabelList
// Make a list of labels that correspond to filegroups that are already converted to aidl_library
for _, aidlSrc := range aidlSrcs.Value.Includes {
src := aidlSrc.OriginalModuleName
if fg, ok := android.ToFileGroupAsLibrary(ctx, src); ok &&
aidlLabelList bazel.LabelListAttribute,
) *bazel.LabelAttribute {
if !aidlLabelList.IsEmpty() {
aidlLibs, aidlSrcs := aidlLabelList.Partition(func(src bazel.Label) bool {
if fg, ok := android.ToFileGroupAsLibrary(ctx, src.OriginalModuleName); ok &&
fg.ShouldConvertToAidlLibrary(ctx) {
aidlLibraries.Add(&bazel.Label{
Label: fg.GetAidlLibraryLabel(ctx),
return true
}
return false
})
} else {
directAidlSrcs.Add(&aidlSrc)
}
}
if len(directAidlSrcs.Includes) > 0 {
aidlLibraryLabel := m.Name() + "_aidl_library"
if !aidlSrcs.IsEmpty() {
aidlLibName := m.Name() + "_aidl_library"
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "aidl_library",
Bzl_load_location: "//build/bazel/rules/aidl:library.bzl",
},
android.CommonAttributes{Name: aidlLibraryLabel},
android.CommonAttributes{Name: aidlLibName},
&aidlLibraryAttributes{
Srcs: bazel.MakeLabelListAttribute(directAidlSrcs),
Srcs: aidlSrcs,
},
)
aidlLibraries.Add(&bazel.Label{
Label: ":" + aidlLibraryLabel,
})
}
return aidlLibraries
}
func bp2buildCcAidlLibrary(
ctx android.Bp2buildMutatorContext,
m *Module,
aidlSrcs bazel.LabelListAttribute,
) *bazel.LabelAttribute {
suffix := "_cc_aidl_library"
ccAidlLibrarylabel := m.Name() + suffix
aidlLibraries := bp2buildAidlLibraries(ctx, m, aidlSrcs)
if aidlLibraries.IsEmpty() {
return nil
aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}})
}
if !aidlLibs.IsEmpty() {
ccAidlLibrarylabel := m.Name() + "_cc_aidl_library"
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "cc_aidl_library",
@@ -807,16 +784,19 @@ func bp2buildCcAidlLibrary(
},
android.CommonAttributes{Name: ccAidlLibrarylabel},
&ccAidlLibraryAttributes{
Deps: bazel.MakeLabelListAttribute(aidlLibraries),
Deps: aidlLibs,
},
)
label := &bazel.LabelAttribute{
Value: &bazel.Label{
Label: ":" + ccAidlLibrarylabel,
},
}
return label
}
}
return nil
}
func bp2BuildParseSdkAttributes(module *Module) sdkAttributes {