Merge "Be more explicit about headers in cc_library_static targets."

This commit is contained in:
Rupert Shuttleworth 2021-04-08 16:30:40 +00:00 committed by Gerrit Code Review
commit a18b3b66cd
2 changed files with 51 additions and 2 deletions

View File

@ -101,6 +101,9 @@ func TestCcLibraryStaticBp2Build(t *testing.T) {
"export_include_dir_1/export_include_dir_1_b.h": "",
"export_include_dir_2/export_include_dir_2_a.h": "",
"export_include_dir_2/export_include_dir_2_b.h": "",
// NOTE: Soong implicitly includes headers in the current directory
"implicit_include_1.h": "",
"implicit_include_2.h": "",
},
bp: soongCcLibraryStaticPreamble + `
cc_library_headers {
@ -203,34 +206,65 @@ cc_library_static {
"include_dir_2",
"local_include_dir_1",
"local_include_dir_2",
".",
],
linkstatic = True,
srcs = [
"foo_static1.cc",
"foo_static2.cc",
"implicit_include_1.h",
"implicit_include_2.h",
"include_dir_1/include_dir_1_a.h",
"include_dir_1/include_dir_1_b.h",
"include_dir_2/include_dir_2_a.h",
"include_dir_2/include_dir_2_b.h",
"local_include_dir_1/local_include_dir_1_a.h",
"local_include_dir_1/local_include_dir_1_b.h",
"local_include_dir_2/local_include_dir_2_a.h",
"local_include_dir_2/local_include_dir_2_b.h",
],
)`, `cc_library_static(
name = "static_lib_1",
includes = [
".",
],
linkstatic = True,
srcs = [
"implicit_include_1.h",
"implicit_include_2.h",
"static_lib_1.cc",
],
)`, `cc_library_static(
name = "static_lib_2",
includes = [
".",
],
linkstatic = True,
srcs = [
"implicit_include_1.h",
"implicit_include_2.h",
"static_lib_2.cc",
],
)`, `cc_library_static(
name = "whole_static_lib_1",
includes = [
".",
],
linkstatic = True,
srcs = [
"implicit_include_1.h",
"implicit_include_2.h",
"whole_static_lib_1.cc",
],
)`, `cc_library_static(
name = "whole_static_lib_2",
includes = [
".",
],
linkstatic = True,
srcs = [
"implicit_include_1.h",
"implicit_include_2.h",
"whole_static_lib_2.cc",
],
)`},

View File

@ -2104,7 +2104,22 @@ func CcLibraryStaticBp2Build(ctx android.TopDownMutatorContext) {
break
}
}
srcsLabels := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, srcs))
// Soong implicitly includes headers from the module's directory.
// For Bazel builds to work we have to make these header includes explicit.
if module.compiler.(*libraryDecorator).includeBuildDirectory() {
localIncludeDirs = append(localIncludeDirs, ".")
}
srcsLabels := android.BazelLabelForModuleSrc(ctx, srcs)
// For Bazel, be more explicit about headers - list all header files in include dirs as srcs
for _, includeDir := range includeDirs {
srcsLabels.Append(bp2BuildListHeadersInDir(ctx, includeDir))
}
for _, localIncludeDir := range localIncludeDirs {
srcsLabels.Append(bp2BuildListHeadersInDir(ctx, localIncludeDir))
}
var staticLibs []string
var wholeStaticLibs []string
@ -2135,7 +2150,7 @@ func CcLibraryStaticBp2Build(ctx android.TopDownMutatorContext) {
attrs := &bazelCcLibraryStaticAttributes{
Copts: copts,
Srcs: srcsLabels,
Srcs: bazel.MakeLabelListAttribute(srcsLabels),
Deps: bazel.MakeLabelListAttribute(depsLabels),
Linkstatic: true,
Includes: allIncludes,