Use aidl_library in cc libraries

Introduce aidl.libs prop on cc libraries to pass in aidl_library. The goal is to eventually disallow aidl.include_dirs (a pattern for passing aidl headers dir for aidl compilation) and enforce aidl headers to be explicitly specified in Android.bp.

Bug: 278704136
Test: go test
Change-Id: Ia78bc11dfa12f47d2d1bb90dc65372ddb17f7e14
This commit is contained in:
Vinh Tran
2023-04-28 11:21:25 -04:00
parent a2f2ed081b
commit 367d89da78
10 changed files with 324 additions and 90 deletions

View File

@@ -728,6 +728,8 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
compilerAttrs := compilerAttributes{}
linkerAttrs := linkerAttributes{}
var aidlLibs bazel.LabelList
// Iterate through these axes in a deterministic order. This is required
// because processing certain dependencies may result in concatenating
// elements along other axes. (For example, processing NoConfig may result
@@ -743,6 +745,7 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
compilerAttrs.lexopts.SetSelectValue(axis, cfg, baseCompilerProps.Lex.Flags)
}
(&compilerAttrs).bp2buildForAxisAndConfig(ctx, axis, cfg, baseCompilerProps)
aidlLibs.Append(android.BazelLabelForModuleDeps(ctx, baseCompilerProps.Aidl.Libs))
}
var exportHdrs []string
@@ -815,7 +818,14 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
(&linkerAttrs).wholeArchiveDeps.Add(protoDep.wholeStaticLib)
(&linkerAttrs).implementationWholeArchiveDeps.Add(protoDep.implementationWholeStaticLib)
aidlDep := bp2buildCcAidlLibrary(ctx, module, compilerAttrs.aidlSrcs, linkerAttrs)
aidlDep := bp2buildCcAidlLibrary(
ctx, module,
compilerAttrs.aidlSrcs,
bazel.LabelListAttribute{
Value: aidlLibs,
},
linkerAttrs,
)
if aidlDep != nil {
if lib, ok := module.linker.(*libraryDecorator); ok {
if proptools.Bool(lib.Properties.Aidl.Export_aidl_headers) {
@@ -912,11 +922,15 @@ func bp2buildFdoProfile(
func bp2buildCcAidlLibrary(
ctx android.Bp2buildMutatorContext,
m *Module,
aidlLabelList bazel.LabelListAttribute,
aidlSrcs bazel.LabelListAttribute,
aidlLibs bazel.LabelListAttribute,
linkerAttrs linkerAttributes,
) *bazel.LabelAttribute {
if !aidlLabelList.IsEmpty() {
aidlLibs, aidlSrcs := aidlLabelList.Partition(func(src bazel.Label) bool {
var aidlLibsFromSrcs, aidlFiles bazel.LabelListAttribute
apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module())
if !aidlSrcs.IsEmpty() {
aidlLibsFromSrcs, aidlFiles = aidlSrcs.Partition(func(src bazel.Label) bool {
if fg, ok := android.ToFileGroupAsLibrary(ctx, src.OriginalModuleName); ok &&
fg.ShouldConvertToAidlLibrary(ctx) {
return true
@@ -924,57 +938,61 @@ func bp2buildCcAidlLibrary(
return false
})
apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module())
sdkAttrs := bp2BuildParseSdkAttributes(m)
if !aidlSrcs.IsEmpty() {
if !aidlFiles.IsEmpty() {
aidlLibName := m.Name() + "_aidl_library"
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "aidl_library",
Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl",
},
android.CommonAttributes{Name: aidlLibName},
&aidlLibraryAttributes{
Srcs: aidlSrcs,
android.CommonAttributes{
Name: aidlLibName,
Tags: apexAvailableTags,
},
)
aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}})
}
if !aidlLibs.IsEmpty() {
ccAidlLibrarylabel := m.Name() + "_cc_aidl_library"
// Since parent cc_library already has these dependencies, we can add them as implementation
// deps so that they don't re-export
implementationDeps := linkerAttrs.deps.Clone()
implementationDeps.Append(linkerAttrs.implementationDeps)
implementationDynamicDeps := linkerAttrs.dynamicDeps.Clone()
implementationDynamicDeps.Append(linkerAttrs.implementationDynamicDeps)
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "cc_aidl_library",
Bzl_load_location: "//build/bazel/rules/cc:cc_aidl_library.bzl",
},
android.CommonAttributes{Name: ccAidlLibrarylabel},
&ccAidlLibraryAttributes{
Deps: aidlLibs,
Implementation_deps: *implementationDeps,
Implementation_dynamic_deps: *implementationDynamicDeps,
Tags: apexAvailableTags,
sdkAttributes: sdkAttrs,
&aidlLibraryAttributes{
Srcs: aidlFiles,
},
)
label := &bazel.LabelAttribute{
Value: &bazel.Label{
Label: ":" + ccAidlLibrarylabel,
},
}
return label
aidlLibsFromSrcs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}})
}
}
allAidlLibs := aidlLibs.Clone()
allAidlLibs.Append(aidlLibsFromSrcs)
if !allAidlLibs.IsEmpty() {
ccAidlLibrarylabel := m.Name() + "_cc_aidl_library"
// Since parent cc_library already has these dependencies, we can add them as implementation
// deps so that they don't re-export
implementationDeps := linkerAttrs.deps.Clone()
implementationDeps.Append(linkerAttrs.implementationDeps)
implementationDynamicDeps := linkerAttrs.dynamicDeps.Clone()
implementationDynamicDeps.Append(linkerAttrs.implementationDynamicDeps)
sdkAttrs := bp2BuildParseSdkAttributes(m)
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "cc_aidl_library",
Bzl_load_location: "//build/bazel/rules/cc:cc_aidl_library.bzl",
},
android.CommonAttributes{Name: ccAidlLibrarylabel},
&ccAidlLibraryAttributes{
Deps: *allAidlLibs,
Implementation_deps: *implementationDeps,
Implementation_dynamic_deps: *implementationDynamicDeps,
Tags: apexAvailableTags,
sdkAttributes: sdkAttrs,
},
)
label := &bazel.LabelAttribute{
Value: &bazel.Label{
Label: ":" + ccAidlLibrarylabel,
},
}
return label
}
return nil
}