diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 8c090d881..5f3ff6217 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -3330,7 +3330,8 @@ cc_library { name: "foo", aidl: { libs: ["A_aidl"], - } + }, + export_include_dirs: ["include"], }`, ExpectedBazelTargets: []string{ MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{ @@ -3340,15 +3341,19 @@ cc_library { "tags": `["apex_available=//apex_available:anyapex"]`, }), MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ - "deps": `[":A_aidl"]`, + "deps": `[":A_aidl"]`, + "local_includes": `["."]`, + "export_includes": `["include"]`, }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, + "export_includes": `["include"]`, }), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, "local_includes": `["."]`, + "export_includes": `["include"]`, }), }, }) @@ -3382,6 +3387,7 @@ cc_library { "srcs": `["B.aidl"]`, }), MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ + "local_includes": `["."]`, "deps": `[ ":A_aidl", ":foo_aidl_library", @@ -3421,7 +3427,8 @@ cc_library { }`, ExpectedBazelTargets: []string{ MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ - "deps": `["//path/to/A:A_aidl"]`, + "local_includes": `["."]`, + "deps": `["//path/to/A:A_aidl"]`, }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, @@ -3440,7 +3447,8 @@ func TestCcLibraryWithExportAidlHeaders(t *testing.T) { expectedBazelTargets := []string{ MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ - "deps": `[":foo_aidl_library"]`, + "local_includes": `["."]`, + "deps": `[":foo_aidl_library"]`, }), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ "whole_archive_deps": `[":foo_cc_aidl_library"]`, @@ -3721,7 +3729,8 @@ cc_library_static { "srcs": `["Foo.aidl"]`, }), MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ - "deps": `[":foo_aidl_library"]`, + "local_includes": `["."]`, + "deps": `[":foo_aidl_library"]`, "implementation_deps": `[ ":baz-static", ":bar-static", diff --git a/cc/bp2build.go b/cc/bp2build.go index 1980ab971..202eebce1 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -844,6 +844,7 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) Value: aidlLibs, }, linkerAttrs, + compilerAttrs, ) if aidlDep != nil { if lib, ok := module.linker.(*libraryDecorator); ok { @@ -992,6 +993,7 @@ func bp2buildCcAidlLibrary( aidlSrcs bazel.LabelListAttribute, aidlLibs bazel.LabelListAttribute, linkerAttrs linkerAttributes, + compilerAttrs compilerAttributes, ) *bazel.LabelAttribute { var aidlLibsFromSrcs, aidlFiles bazel.LabelListAttribute apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module()) @@ -1038,6 +1040,15 @@ func bp2buildCcAidlLibrary( sdkAttrs := bp2BuildParseSdkAttributes(m) + exportedIncludes := bp2BuildParseExportedIncludes(ctx, m, &compilerAttrs.includes) + includeAttrs := includesAttributes{ + Export_includes: exportedIncludes.Includes, + Export_absolute_includes: exportedIncludes.AbsoluteIncludes, + Export_system_includes: exportedIncludes.SystemIncludes, + Local_includes: compilerAttrs.localIncludes, + Absolute_includes: compilerAttrs.absoluteIncludes, + } + ctx.CreateBazelTargetModule( bazel.BazelTargetModuleProperties{ Rule_class: "cc_aidl_library", @@ -1050,6 +1061,7 @@ func bp2buildCcAidlLibrary( Implementation_dynamic_deps: *implementationDynamicDeps, Tags: apexAvailableTags, sdkAttributes: sdkAttrs, + includesAttributes: includeAttrs, }, ) label := &bazel.LabelAttribute{ diff --git a/cc/cc_test.go b/cc/cc_test.go index d3d55e8ee..422df7310 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -39,6 +39,7 @@ func TestMain(m *testing.M) { var prepareForCcTest = android.GroupFixturePreparers( PrepareForTestWithCcIncludeVndk, + aidl_library.PrepareForTestWithAidlLibrary, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { variables.DeviceVndkVersion = StringPtr("current") variables.ProductVndkVersion = StringPtr("current") diff --git a/cc/library.go b/cc/library.go index ad4688fe6..09a7253ab 100644 --- a/cc/library.go +++ b/cc/library.go @@ -271,7 +271,9 @@ type ccAidlLibraryAttributes struct { Implementation_deps bazel.LabelListAttribute Implementation_dynamic_deps bazel.LabelListAttribute Tags bazel.StringListAttribute + sdkAttributes + includesAttributes } type stripAttributes struct { @@ -335,6 +337,14 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) { Native_coverage: baseAttributes.Native_coverage, } + includeAttrs := includesAttributes{ + Export_includes: exportedIncludes.Includes, + Export_absolute_includes: exportedIncludes.AbsoluteIncludes, + Export_system_includes: exportedIncludes.SystemIncludes, + Local_includes: compilerAttrs.localIncludes, + Absolute_includes: compilerAttrs.absoluteIncludes, + } + sharedCommonAttrs := staticOrSharedAttributes{ Srcs: *srcs.Clone().Append(sharedAttrs.Srcs), Srcs_c: *compilerAttrs.cSrcs.Clone().Append(sharedAttrs.Srcs_c), @@ -356,41 +366,34 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) { staticTargetAttrs := &bazelCcLibraryStaticAttributes{ staticOrSharedAttributes: staticCommonAttrs, + includesAttributes: includeAttrs, Cppflags: compilerAttrs.cppFlags, Conlyflags: compilerAttrs.conlyFlags, Asflags: asFlags, - Export_includes: exportedIncludes.Includes, - Export_absolute_includes: exportedIncludes.AbsoluteIncludes, - Export_system_includes: exportedIncludes.SystemIncludes, - Local_includes: compilerAttrs.localIncludes, - Absolute_includes: compilerAttrs.absoluteIncludes, - Rtti: compilerAttrs.rtti, - Stl: compilerAttrs.stl, - Cpp_std: compilerAttrs.cppStd, - C_std: compilerAttrs.cStd, + Rtti: compilerAttrs.rtti, + Stl: compilerAttrs.stl, + Cpp_std: compilerAttrs.cppStd, + C_std: compilerAttrs.cStd, Features: *staticFeatures, } sharedTargetAttrs := &bazelCcLibrarySharedAttributes{ staticOrSharedAttributes: sharedCommonAttrs, - Cppflags: compilerAttrs.cppFlags, - Conlyflags: compilerAttrs.conlyFlags, - Asflags: asFlags, + includesAttributes: includeAttrs, - Export_includes: exportedIncludes.Includes, - Export_absolute_includes: exportedIncludes.AbsoluteIncludes, - Export_system_includes: exportedIncludes.SystemIncludes, - Local_includes: compilerAttrs.localIncludes, - Absolute_includes: compilerAttrs.absoluteIncludes, - Linkopts: linkerAttrs.linkopts, - Rtti: compilerAttrs.rtti, - Stl: compilerAttrs.stl, - Cpp_std: compilerAttrs.cppStd, - C_std: compilerAttrs.cStd, - Use_version_lib: linkerAttrs.useVersionLib, + Cppflags: compilerAttrs.cppFlags, + Conlyflags: compilerAttrs.conlyFlags, + Asflags: asFlags, + + Linkopts: linkerAttrs.linkopts, + Rtti: compilerAttrs.rtti, + Stl: compilerAttrs.stl, + Cpp_std: compilerAttrs.cppStd, + C_std: compilerAttrs.cStd, + Use_version_lib: linkerAttrs.useVersionLib, Additional_linker_inputs: linkerAttrs.additionalLinkerInputs, @@ -2880,6 +2883,13 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo linkerAttrs := baseAttributes.linkerAttributes exportedIncludes := bp2BuildParseExportedIncludes(ctx, module, &compilerAttrs.includes) + includeAttrs := includesAttributes{ + Export_includes: exportedIncludes.Includes, + Export_absolute_includes: exportedIncludes.AbsoluteIncludes, + Export_system_includes: exportedIncludes.SystemIncludes, + Local_includes: compilerAttrs.localIncludes, + Absolute_includes: compilerAttrs.absoluteIncludes, + } // Append shared/static{} stanza properties. These won't be specified on // cc_library_* itself, but may be specified in cc_defaults that this module @@ -2937,11 +2947,7 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo Cpp_std: compilerAttrs.cppStd, C_std: compilerAttrs.cStd, - Export_includes: exportedIncludes.Includes, - Export_absolute_includes: exportedIncludes.AbsoluteIncludes, - Export_system_includes: exportedIncludes.SystemIncludes, - Local_includes: compilerAttrs.localIncludes, - Absolute_includes: compilerAttrs.absoluteIncludes, + includesAttributes: includeAttrs, Cppflags: compilerAttrs.cppFlags, Conlyflags: compilerAttrs.conlyFlags, @@ -2967,11 +2973,8 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo Cpp_std: compilerAttrs.cppStd, C_std: compilerAttrs.cStd, - Export_includes: exportedIncludes.Includes, - Export_absolute_includes: exportedIncludes.AbsoluteIncludes, - Export_system_includes: exportedIncludes.SystemIncludes, - Local_includes: compilerAttrs.localIncludes, - Absolute_includes: compilerAttrs.absoluteIncludes, + includesAttributes: includeAttrs, + Additional_linker_inputs: linkerAttrs.additionalLinkerInputs, Strip: stripAttrsFromLinkerAttrs(&linkerAttrs), @@ -3007,9 +3010,18 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name(), Tags: tags}, attrs) } +type includesAttributes struct { + Export_includes bazel.StringListAttribute + Export_absolute_includes bazel.StringListAttribute + Export_system_includes bazel.StringListAttribute + Local_includes bazel.StringListAttribute + Absolute_includes bazel.StringListAttribute +} + // TODO(b/199902614): Can this be factored to share with the other Attributes? type bazelCcLibraryStaticAttributes struct { staticOrSharedAttributes + includesAttributes Use_version_lib bazel.BoolAttribute Rtti bazel.BoolAttribute @@ -3017,12 +3029,7 @@ type bazelCcLibraryStaticAttributes struct { Cpp_std *string C_std *string - Export_includes bazel.StringListAttribute - Export_absolute_includes bazel.StringListAttribute - Export_system_includes bazel.StringListAttribute - Local_includes bazel.StringListAttribute - Absolute_includes bazel.StringListAttribute - Hdrs bazel.LabelListAttribute + Hdrs bazel.LabelListAttribute Cppflags bazel.StringListAttribute Conlyflags bazel.StringListAttribute @@ -3034,6 +3041,7 @@ type bazelCcLibraryStaticAttributes struct { // TODO(b/199902614): Can this be factored to share with the other Attributes? type bazelCcLibrarySharedAttributes struct { staticOrSharedAttributes + includesAttributes Linkopts bazel.StringListAttribute Use_version_lib bazel.BoolAttribute @@ -3043,12 +3051,7 @@ type bazelCcLibrarySharedAttributes struct { Cpp_std *string C_std *string - Export_includes bazel.StringListAttribute - Export_absolute_includes bazel.StringListAttribute - Export_system_includes bazel.StringListAttribute - Local_includes bazel.StringListAttribute - Absolute_includes bazel.StringListAttribute - Hdrs bazel.LabelListAttribute + Hdrs bazel.LabelListAttribute Strip stripAttributes Additional_linker_inputs bazel.LabelListAttribute