Add apex_available aidl + aidl&lang libraries

Test: b build com.android.neuralnetworks com.android.media.swcodec
Change-Id: I008b915b22e4c8c2cf1f0aee6cfdaf17374cb3a9
This commit is contained in:
Liz Kammer
2023-03-23 11:51:49 -04:00
parent 10e5a0e987
commit 2b3f56ed22
8 changed files with 55 additions and 14 deletions

View File

@@ -118,6 +118,7 @@ func (fg *fileGroup) ConvertWithBp2build(ctx TopDownMutatorContext) {
// If the module has a mixed bag of AIDL and non-AIDL files, split the filegroup manually // If the module has a mixed bag of AIDL and non-AIDL files, split the filegroup manually
// and then convert // and then convert
if fg.ShouldConvertToAidlLibrary(ctx) { if fg.ShouldConvertToAidlLibrary(ctx) {
tags := []string{"apex_available=//apex_available:anyapex"}
attrs := &bazelAidlLibraryAttributes{ attrs := &bazelAidlLibraryAttributes{
Srcs: srcs, Srcs: srcs,
Strip_import_prefix: fg.properties.Path, Strip_import_prefix: fg.properties.Path,
@@ -128,17 +129,25 @@ func (fg *fileGroup) ConvertWithBp2build(ctx TopDownMutatorContext) {
Bzl_load_location: "//build/bazel/rules/aidl:library.bzl", Bzl_load_location: "//build/bazel/rules/aidl:library.bzl",
} }
ctx.CreateBazelTargetModule(props, CommonAttributes{Name: fg.Name()}, attrs) ctx.CreateBazelTargetModule(
props,
CommonAttributes{
Name: fg.Name(),
Tags: bazel.MakeStringListAttribute(tags),
},
attrs)
} else { } else {
if fg.ShouldConvertToProtoLibrary(ctx) { if fg.ShouldConvertToProtoLibrary(ctx) {
// TODO(b/246997908): we can remove this tag if we could figure out a
// solution for this bug.
attrs := &ProtoAttrs{ attrs := &ProtoAttrs{
Srcs: srcs, Srcs: srcs,
Strip_import_prefix: fg.properties.Path, Strip_import_prefix: fg.properties.Path,
} }
tags := []string{"manual"} tags := []string{
"apex_available=//apex_available:anyapex",
// TODO(b/246997908): we can remove this tag if we could figure out a solution for this bug.
"manual",
}
ctx.CreateBazelTargetModule( ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"}, bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
CommonAttributes{ CommonAttributes{

View File

@@ -2425,7 +2425,10 @@ cc_library {
"whole_archive_deps": `[":a_cc_proto_lite"]`, "whole_archive_deps": `[":a_cc_proto_lite"]`,
}), MakeBazelTargetNoRestrictions("proto_library", "a_fg_proto_bp2build_converted", AttrNameToString{ }), MakeBazelTargetNoRestrictions("proto_library", "a_fg_proto_bp2build_converted", AttrNameToString{
"srcs": `["a_fg.proto"]`, "srcs": `["a_fg.proto"]`,
"tags": `["manual"]`, "tags": `[
"apex_available=//apex_available:anyapex",
"manual",
]`,
}), MakeBazelTargetNoRestrictions("filegroup", "a_fg_proto", AttrNameToString{ }), MakeBazelTargetNoRestrictions("filegroup", "a_fg_proto", AttrNameToString{
"srcs": `["a_fg.proto"]`, "srcs": `["a_fg.proto"]`,
}), }),
@@ -2464,7 +2467,10 @@ cc_library {
"whole_archive_deps": `[":a_cc_proto_lite"]`, "whole_archive_deps": `[":a_cc_proto_lite"]`,
}), MakeBazelTargetNoRestrictions("proto_library", "a_fg_proto_bp2build_converted", AttrNameToString{ }), MakeBazelTargetNoRestrictions("proto_library", "a_fg_proto_bp2build_converted", AttrNameToString{
"srcs": `["a_fg.proto"]`, "srcs": `["a_fg.proto"]`,
"tags": `["manual"]`, "tags": `[
"apex_available=//apex_available:anyapex",
"manual",
]`,
}), MakeBazelTargetNoRestrictions("filegroup", "a_fg_proto", AttrNameToString{ }), MakeBazelTargetNoRestrictions("filegroup", "a_fg_proto", AttrNameToString{
"srcs": `["a_fg.proto"]`, "srcs": `["a_fg.proto"]`,
}), }),
@@ -3322,6 +3328,7 @@ cc_library {
MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{ MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{
"srcs": `["aidl/A.aidl"]`, "srcs": `["aidl/A.aidl"]`,
"strip_import_prefix": `"aidl"`, "strip_import_prefix": `"aidl"`,
"tags": `["apex_available=//apex_available:anyapex"]`,
}), }),
MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{
"srcs": `["B.aidl"]`, "srcs": `["B.aidl"]`,

View File

@@ -74,6 +74,7 @@ func TestFilegroupWithAidlSrcs(t *testing.T) {
expectedBazelAttrs: AttrNameToString{ expectedBazelAttrs: AttrNameToString{
"srcs": `["aidl/foo.aidl"]`, "srcs": `["aidl/foo.aidl"]`,
"strip_import_prefix": `"aidl"`, "strip_import_prefix": `"aidl"`,
"tags": `["apex_available=//apex_available:anyapex"]`,
}, },
}, },
{ {
@@ -85,11 +86,13 @@ func TestFilegroupWithAidlSrcs(t *testing.T) {
}`, }`,
expectedBazelAttrs: AttrNameToString{ expectedBazelAttrs: AttrNameToString{
"srcs": `["aidl/foo.aidl"]`, "srcs": `["aidl/foo.aidl"]`,
"tags": `["apex_available=//apex_available:anyapex"]`,
}, },
}, },
} }
for _, test := range testcases { for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
expectedBazelTargets := []string{ expectedBazelTargets := []string{
MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs), MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs),
} }
@@ -98,6 +101,7 @@ func TestFilegroupWithAidlSrcs(t *testing.T) {
Blueprint: test.bp, Blueprint: test.bp,
ExpectedBazelTargets: expectedBazelTargets, ExpectedBazelTargets: expectedBazelTargets,
}) })
})
} }
} }
@@ -136,7 +140,11 @@ filegroup {
MakeBazelTargetNoRestrictions("proto_library", "foo_bp2build_converted", AttrNameToString{ MakeBazelTargetNoRestrictions("proto_library", "foo_bp2build_converted", AttrNameToString{
"srcs": `["proto/foo.proto"]`, "srcs": `["proto/foo.proto"]`,
"strip_import_prefix": `"proto"`, "strip_import_prefix": `"proto"`,
"tags": `["manual"]`}), "tags": `[
"apex_available=//apex_available:anyapex",
"manual",
]`,
}),
MakeBazelTargetNoRestrictions("filegroup", "foo", AttrNameToString{ MakeBazelTargetNoRestrictions("filegroup", "foo", AttrNameToString{
"srcs": `["proto/foo.proto"]`}), "srcs": `["proto/foo.proto"]`}),
}}) }})

View File

@@ -493,6 +493,7 @@ java_library {
"a.aidl", "a.aidl",
"b.aidl", "b.aidl",
]`, ]`,
"tags": `["apex_available=//apex_available:anyapex"]`,
}), }),
MakeBazelTarget("java_aidl_library", "example_lib_java_aidl_library", AttrNameToString{ MakeBazelTarget("java_aidl_library", "example_lib_java_aidl_library", AttrNameToString{
"deps": `[":aidl_files"]`, "deps": `[":aidl_files"]`,

View File

@@ -228,6 +228,7 @@ type BazelTestResult struct {
// //
// If ignoreUnexpected=true then it will ignore directories for which there are no expected targets. // If ignoreUnexpected=true then it will ignore directories for which there are no expected targets.
func (b BazelTestResult) CompareAllBazelTargets(t *testing.T, description string, expectedTargets map[string][]string, ignoreUnexpected bool) { func (b BazelTestResult) CompareAllBazelTargets(t *testing.T, description string, expectedTargets map[string][]string, ignoreUnexpected bool) {
t.Helper()
actualTargets := b.buildFileToTargets actualTargets := b.buildFileToTargets
// Generate the sorted set of directories to check. // Generate the sorted set of directories to check.

View File

@@ -907,6 +907,9 @@ func bp2buildCcAidlLibrary(
return false return false
}) })
apexAvailableTags := android.ApexAvailableTags(ctx.Module())
sdkAttrs := bp2BuildParseSdkAttributes(m)
if !aidlSrcs.IsEmpty() { if !aidlSrcs.IsEmpty() {
aidlLibName := m.Name() + "_aidl_library" aidlLibName := m.Name() + "_aidl_library"
ctx.CreateBazelTargetModule( ctx.CreateBazelTargetModule(
@@ -917,6 +920,7 @@ func bp2buildCcAidlLibrary(
android.CommonAttributes{Name: aidlLibName}, android.CommonAttributes{Name: aidlLibName},
&aidlLibraryAttributes{ &aidlLibraryAttributes{
Srcs: aidlSrcs, Srcs: aidlSrcs,
Tags: apexAvailableTags,
}, },
) )
aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}}) aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}})
@@ -941,6 +945,8 @@ func bp2buildCcAidlLibrary(
Deps: aidlLibs, Deps: aidlLibs,
Implementation_deps: *implementationDeps, Implementation_deps: *implementationDeps,
Implementation_dynamic_deps: *implementationDynamicDeps, Implementation_dynamic_deps: *implementationDynamicDeps,
Tags: apexAvailableTags,
sdkAttributes: sdkAttrs,
}, },
) )
label := &bazel.LabelAttribute{ label := &bazel.LabelAttribute{

View File

@@ -264,12 +264,15 @@ type bazelCcLibraryAttributes struct {
type aidlLibraryAttributes struct { type aidlLibraryAttributes struct {
Srcs bazel.LabelListAttribute Srcs bazel.LabelListAttribute
Include_dir *string Include_dir *string
Tags bazel.StringListAttribute
} }
type ccAidlLibraryAttributes struct { type ccAidlLibraryAttributes struct {
Deps bazel.LabelListAttribute Deps bazel.LabelListAttribute
Implementation_deps bazel.LabelListAttribute Implementation_deps bazel.LabelListAttribute
Implementation_dynamic_deps bazel.LabelListAttribute Implementation_dynamic_deps bazel.LabelListAttribute
Tags bazel.StringListAttribute
sdkAttributes
} }
type stripAttributes struct { type stripAttributes struct {

View File

@@ -2625,10 +2625,12 @@ type eventLogTagsAttributes struct {
type aidlLibraryAttributes struct { type aidlLibraryAttributes struct {
Srcs bazel.LabelListAttribute Srcs bazel.LabelListAttribute
Tags bazel.StringListAttribute
} }
type javaAidlLibraryAttributes struct { type javaAidlLibraryAttributes struct {
Deps bazel.LabelListAttribute Deps bazel.LabelListAttribute
Tags bazel.StringListAttribute
} }
// bp2BuildJavaInfo has information needed for the conversion of java*_modules // bp2BuildJavaInfo has information needed for the conversion of java*_modules
@@ -2700,6 +2702,8 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
return android.IsConvertedToAidlLibrary(ctx, src.OriginalModuleName) return android.IsConvertedToAidlLibrary(ctx, src.OriginalModuleName)
}) })
apexAvailableTags := android.ApexAvailableTags(ctx.Module())
if !aidlSrcs.IsEmpty() { if !aidlSrcs.IsEmpty() {
aidlLibName := m.Name() + "_aidl_library" aidlLibName := m.Name() + "_aidl_library"
ctx.CreateBazelTargetModule( ctx.CreateBazelTargetModule(
@@ -2710,6 +2714,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
android.CommonAttributes{Name: aidlLibName}, android.CommonAttributes{Name: aidlLibName},
&aidlLibraryAttributes{ &aidlLibraryAttributes{
Srcs: aidlSrcs, Srcs: aidlSrcs,
Tags: apexAvailableTags,
}, },
) )
aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}}) aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}})
@@ -2724,6 +2729,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
android.CommonAttributes{Name: javaAidlLibName}, android.CommonAttributes{Name: javaAidlLibName},
&javaAidlLibraryAttributes{ &javaAidlLibraryAttributes{
Deps: aidlLibs, Deps: aidlLibs,
Tags: apexAvailableTags,
}, },
) )