Loading aidl_library/aidl_library.go +4 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,10 @@ import ( "github.com/google/blueprint/proptools" ) var PrepareForTestWithAidlLibrary = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { registerAidlLibraryBuildComponents(ctx) }) func init() { registerAidlLibraryBuildComponents(android.InitRegistrationContext) } Loading aidl_library/aidl_library_test.go +0 −4 Original line number Diff line number Diff line Loading @@ -19,10 +19,6 @@ import ( "testing" ) var PrepareForTestWithAidlLibrary = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { registerAidlLibraryBuildComponents(ctx) }) func TestAidlLibrary(t *testing.T) { t.Parallel() ctx := android.GroupFixturePreparers( Loading bp2build/cc_library_conversion_test.go +112 −30 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import ( "fmt" "testing" "android/soong/aidl_library" "android/soong/android" "android/soong/cc" ) Loading Loading @@ -63,6 +64,7 @@ func registerCcLibraryModuleTypes(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) ctx.RegisterModuleType("aidl_library", aidl_library.AidlLibraryFactory) } func TestCcLibrarySimple(t *testing.T) { Loading Loading @@ -3315,6 +3317,46 @@ func TestCcLibraryArchVariantSuffix(t *testing.T) { }) } func TestCcLibraryWithAidlLibrary(t *testing.T) { runCcLibraryTestCase(t, Bp2buildTestCase{ Description: "cc_library with aidl_library", ModuleTypeUnderTest: "cc_library", ModuleTypeUnderTestFactory: cc.LibraryFactory, Blueprint: ` aidl_library { name: "A_aidl", srcs: ["aidl/A.aidl"], hdrs: ["aidl/Header.aidl"], strip_import_prefix: "aidl", } cc_library { name: "foo", aidl: { libs: ["A_aidl"], } }`, ExpectedBazelTargets: []string{ MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{ "srcs": `["aidl/A.aidl"]`, "hdrs": `["aidl/Header.aidl"]`, "strip_import_prefix": `"aidl"`, "tags": `["apex_available=//apex_available:anyapex"]`, }), MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ "deps": `[":A_aidl"]`, }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, }), }, }) } func TestCcLibraryWithAidlSrcs(t *testing.T) { runCcLibraryTestCase(t, Bp2buildTestCase{ Description: "cc_library with aidl srcs", Loading Loading @@ -3397,11 +3439,29 @@ cc_library { } func TestCcLibraryWithExportAidlHeaders(t *testing.T) { runCcLibraryTestCase(t, Bp2buildTestCase{ Description: "cc_library with export aidl headers", ModuleTypeUnderTest: "cc_library", ModuleTypeUnderTestFactory: cc.LibraryFactory, Blueprint: ` t.Parallel() expectedBazelTargets := []string{ MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ "deps": `[":foo_aidl_library"]`, }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, }), } testCases := []struct { description string bp string expectedBazelTargets []string }{ { description: "cc_library with aidl srcs and aidl.export_aidl_headers set", bp: ` cc_library { name: "foo", srcs: [ Loading @@ -3411,24 +3471,46 @@ cc_library { export_aidl_headers: true, } }`, ExpectedBazelTargets: []string{ expectedBazelTargets: append( expectedBazelTargets, MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ "srcs": `["Foo.aidl"]`, })), }, { description: "cc_library with aidl.libs and aidl.export_aidl_headers set", bp: ` aidl_library { name: "foo_aidl_library", srcs: ["Foo.aidl"], } cc_library { name: "foo", aidl: { libs: ["foo_aidl_library"], export_aidl_headers: true, } }`, expectedBazelTargets: append( expectedBazelTargets, MakeBazelTargetNoRestrictions("aidl_library", "foo_aidl_library", AttrNameToString{ "srcs": `["Foo.aidl"]`, "tags": `["apex_available=//apex_available:anyapex"]`, }), MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ "deps": `[":foo_aidl_library"]`, }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, }), ), }, } for _, testCase := range testCases { runCcLibraryTestCase(t, Bp2buildTestCase{ Description: "cc_library with export aidl headers", ModuleTypeUnderTest: "cc_library", ModuleTypeUnderTestFactory: cc.LibraryFactory, Blueprint: testCase.bp, ExpectedBazelTargets: testCase.expectedBazelTargets, }) } } func TestCcLibraryWithTargetApex(t *testing.T) { runCcLibraryTestCase(t, Bp2buildTestCase{ Loading cc/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ bootstrap_go_package { "blueprint", "blueprint-pathtools", "soong", "soong-aidl-library", "soong-android", "soong-bazel", "soong-cc-config", Loading @@ -22,7 +23,6 @@ bootstrap_go_package { srcs: [ "afdo.go", "fdo_profile.go", "androidmk.go", "api_level.go", "bp2build.go", Loading cc/bp2build.go +58 −40 Original line number Diff line number Diff line Loading @@ -742,6 +742,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 Loading @@ -762,6 +764,7 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) compilerAttrs.yaccGenPositionHeader.SetSelectValue(axis, cfg, baseCompilerProps.Yacc.Gen_position_hh) } (&compilerAttrs).bp2buildForAxisAndConfig(ctx, axis, cfg, baseCompilerProps) aidlLibs.Append(android.BazelLabelForModuleDeps(ctx, baseCompilerProps.Aidl.Libs)) } var exportHdrs []string Loading Loading @@ -834,7 +837,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) { Loading Loading @@ -979,11 +989,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 Loading @@ -991,26 +1005,29 @@ 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, }, &aidlLibraryAttributes{ Srcs: aidlFiles, }, ) aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}}) aidlLibsFromSrcs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}}) } } allAidlLibs := aidlLibs.Clone() allAidlLibs.Append(aidlLibsFromSrcs) if !aidlLibs.IsEmpty() { 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 Loading @@ -1019,6 +1036,8 @@ func bp2buildCcAidlLibrary( implementationDynamicDeps := linkerAttrs.dynamicDeps.Clone() implementationDynamicDeps.Append(linkerAttrs.implementationDynamicDeps) sdkAttrs := bp2BuildParseSdkAttributes(m) ctx.CreateBazelTargetModule( bazel.BazelTargetModuleProperties{ Rule_class: "cc_aidl_library", Loading @@ -1026,7 +1045,7 @@ func bp2buildCcAidlLibrary( }, android.CommonAttributes{Name: ccAidlLibrarylabel}, &ccAidlLibraryAttributes{ Deps: aidlLibs, Deps: *allAidlLibs, Implementation_deps: *implementationDeps, Implementation_dynamic_deps: *implementationDynamicDeps, Tags: apexAvailableTags, Loading @@ -1040,7 +1059,6 @@ func bp2buildCcAidlLibrary( } return label } } return nil } Loading Loading
aidl_library/aidl_library.go +4 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,10 @@ import ( "github.com/google/blueprint/proptools" ) var PrepareForTestWithAidlLibrary = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { registerAidlLibraryBuildComponents(ctx) }) func init() { registerAidlLibraryBuildComponents(android.InitRegistrationContext) } Loading
aidl_library/aidl_library_test.go +0 −4 Original line number Diff line number Diff line Loading @@ -19,10 +19,6 @@ import ( "testing" ) var PrepareForTestWithAidlLibrary = android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { registerAidlLibraryBuildComponents(ctx) }) func TestAidlLibrary(t *testing.T) { t.Parallel() ctx := android.GroupFixturePreparers( Loading
bp2build/cc_library_conversion_test.go +112 −30 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import ( "fmt" "testing" "android/soong/aidl_library" "android/soong/android" "android/soong/cc" ) Loading Loading @@ -63,6 +64,7 @@ func registerCcLibraryModuleTypes(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) ctx.RegisterModuleType("aidl_library", aidl_library.AidlLibraryFactory) } func TestCcLibrarySimple(t *testing.T) { Loading Loading @@ -3315,6 +3317,46 @@ func TestCcLibraryArchVariantSuffix(t *testing.T) { }) } func TestCcLibraryWithAidlLibrary(t *testing.T) { runCcLibraryTestCase(t, Bp2buildTestCase{ Description: "cc_library with aidl_library", ModuleTypeUnderTest: "cc_library", ModuleTypeUnderTestFactory: cc.LibraryFactory, Blueprint: ` aidl_library { name: "A_aidl", srcs: ["aidl/A.aidl"], hdrs: ["aidl/Header.aidl"], strip_import_prefix: "aidl", } cc_library { name: "foo", aidl: { libs: ["A_aidl"], } }`, ExpectedBazelTargets: []string{ MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{ "srcs": `["aidl/A.aidl"]`, "hdrs": `["aidl/Header.aidl"]`, "strip_import_prefix": `"aidl"`, "tags": `["apex_available=//apex_available:anyapex"]`, }), MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ "deps": `[":A_aidl"]`, }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, }), }, }) } func TestCcLibraryWithAidlSrcs(t *testing.T) { runCcLibraryTestCase(t, Bp2buildTestCase{ Description: "cc_library with aidl srcs", Loading Loading @@ -3397,11 +3439,29 @@ cc_library { } func TestCcLibraryWithExportAidlHeaders(t *testing.T) { runCcLibraryTestCase(t, Bp2buildTestCase{ Description: "cc_library with export aidl headers", ModuleTypeUnderTest: "cc_library", ModuleTypeUnderTestFactory: cc.LibraryFactory, Blueprint: ` t.Parallel() expectedBazelTargets := []string{ MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ "deps": `[":foo_aidl_library"]`, }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, }), } testCases := []struct { description string bp string expectedBazelTargets []string }{ { description: "cc_library with aidl srcs and aidl.export_aidl_headers set", bp: ` cc_library { name: "foo", srcs: [ Loading @@ -3411,24 +3471,46 @@ cc_library { export_aidl_headers: true, } }`, ExpectedBazelTargets: []string{ expectedBazelTargets: append( expectedBazelTargets, MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{ "srcs": `["Foo.aidl"]`, })), }, { description: "cc_library with aidl.libs and aidl.export_aidl_headers set", bp: ` aidl_library { name: "foo_aidl_library", srcs: ["Foo.aidl"], } cc_library { name: "foo", aidl: { libs: ["foo_aidl_library"], export_aidl_headers: true, } }`, expectedBazelTargets: append( expectedBazelTargets, MakeBazelTargetNoRestrictions("aidl_library", "foo_aidl_library", AttrNameToString{ "srcs": `["Foo.aidl"]`, "tags": `["apex_available=//apex_available:anyapex"]`, }), MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ "deps": `[":foo_aidl_library"]`, }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, }), ), }, } for _, testCase := range testCases { runCcLibraryTestCase(t, Bp2buildTestCase{ Description: "cc_library with export aidl headers", ModuleTypeUnderTest: "cc_library", ModuleTypeUnderTestFactory: cc.LibraryFactory, Blueprint: testCase.bp, ExpectedBazelTargets: testCase.expectedBazelTargets, }) } } func TestCcLibraryWithTargetApex(t *testing.T) { runCcLibraryTestCase(t, Bp2buildTestCase{ Loading
cc/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ bootstrap_go_package { "blueprint", "blueprint-pathtools", "soong", "soong-aidl-library", "soong-android", "soong-bazel", "soong-cc-config", Loading @@ -22,7 +23,6 @@ bootstrap_go_package { srcs: [ "afdo.go", "fdo_profile.go", "androidmk.go", "api_level.go", "bp2build.go", Loading
cc/bp2build.go +58 −40 Original line number Diff line number Diff line Loading @@ -742,6 +742,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 Loading @@ -762,6 +764,7 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) compilerAttrs.yaccGenPositionHeader.SetSelectValue(axis, cfg, baseCompilerProps.Yacc.Gen_position_hh) } (&compilerAttrs).bp2buildForAxisAndConfig(ctx, axis, cfg, baseCompilerProps) aidlLibs.Append(android.BazelLabelForModuleDeps(ctx, baseCompilerProps.Aidl.Libs)) } var exportHdrs []string Loading Loading @@ -834,7 +837,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) { Loading Loading @@ -979,11 +989,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 Loading @@ -991,26 +1005,29 @@ 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, }, &aidlLibraryAttributes{ Srcs: aidlFiles, }, ) aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}}) aidlLibsFromSrcs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}}) } } allAidlLibs := aidlLibs.Clone() allAidlLibs.Append(aidlLibsFromSrcs) if !aidlLibs.IsEmpty() { 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 Loading @@ -1019,6 +1036,8 @@ func bp2buildCcAidlLibrary( implementationDynamicDeps := linkerAttrs.dynamicDeps.Clone() implementationDynamicDeps.Append(linkerAttrs.implementationDynamicDeps) sdkAttrs := bp2BuildParseSdkAttributes(m) ctx.CreateBazelTargetModule( bazel.BazelTargetModuleProperties{ Rule_class: "cc_aidl_library", Loading @@ -1026,7 +1045,7 @@ func bp2buildCcAidlLibrary( }, android.CommonAttributes{Name: ccAidlLibrarylabel}, &ccAidlLibraryAttributes{ Deps: aidlLibs, Deps: *allAidlLibs, Implementation_deps: *implementationDeps, Implementation_dynamic_deps: *implementationDynamicDeps, Tags: apexAvailableTags, Loading @@ -1040,7 +1059,6 @@ func bp2buildCcAidlLibrary( } return label } } return nil } Loading