Merge "Handle product config specific header_libs prop in cc bp2build"

This commit is contained in:
Treehugger Robot 2022-09-02 13:02:04 +00:00 committed by Gerrit Code Review
commit f20433b15f
3 changed files with 48 additions and 1 deletions

View file

@ -470,7 +470,6 @@ var (
"KernelLibcutilsTest",
"linker", // TODO(b/228316882): cc_binary uses link_crt
"libdebuggerd", // TODO(b/228314770): support product variable-specific header_libs
"versioner", // TODO(b/228313961): depends on prebuilt shared library libclang-cpp_host as a shared library, which does not supply expected providers for a shared library
"libvpx", // TODO(b/240756936): Arm neon variant not supported
"art_libartbase_headers", // TODO(b/236268577): Header libraries do not support export_shared_libs_headers
@ -546,6 +545,7 @@ var (
"libartbased-art-gtest", // depends on unconverted modules: libgtest_isolated, libartd, libartd-compiler, libdexfiled, libprofiled
"libartd", // depends on unconverted modules: art_operator_srcs, libcpu_features, libodrstatslog, libelffiled, art_cmdlineparser_headers, cpp-define-generator-definitions, libdexfiled, libnativebridge, libnativeloader, libsigchain, libartbased, libprofiled, cpp-define-generator-asm-support, apex-info-list-tinyxml, libtinyxml2, libnativeloader-headers, heapprofd_client_api
"libartd-runtime-gtest", // depends on unconverted modules: libgtest_isolated, libartd-compiler, libdexfiled, libprofiled, libartbased, libartbased-art-gtest
"libdebuggerd", // depends on unconverted module: libdexfile
"libdebuggerd_handler", // depends on unconverted module libdebuggerd_handler_core
"libdebuggerd_handler_core", "libdebuggerd_handler_fallback", // depends on unconverted module libdebuggerd
"libdexfiled", // depends on unconverted modules: dexfile_operator_srcs, libartbased, libartpalette

View file

@ -1199,6 +1199,40 @@ cc_library {
)
}
func TestCcLibraryProductVariablesHeaderLibs(t *testing.T) {
runCcLibraryTestCase(t, Bp2buildTestCase{
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Filesystem: map[string]string{},
Blueprint: soongCcLibraryStaticPreamble + `
cc_library {
name: "foo_static",
srcs: ["common.c"],
product_variables: {
malloc_not_svelte: {
header_libs: ["malloc_not_svelte_header_lib"],
},
},
include_build_directory: false,
}
cc_library {
name: "malloc_not_svelte_header_lib",
bazel_module: { bp2build_available: false },
}
`,
ExpectedBazelTargets: makeCcLibraryTargets("foo_static", AttrNameToString{
"implementation_deps": `select({
"//build/bazel/product_variables:malloc_not_svelte": [":malloc_not_svelte_header_lib"],
"//conditions:default": [],
})`,
"srcs_c": `["common.c"]`,
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
}),
},
)
}
func TestCCLibraryNoCrtTrue(t *testing.T) {
runCcLibraryTestCase(t, Bp2buildTestCase{
Description: "cc_library - nocrt: true emits attribute",

View file

@ -1026,11 +1026,17 @@ func (la *linkerAttributes) convertProductVariables(ctx android.BazelConversionP
depResolutionFunc func(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList
}
// an intermediate attribute that holds Header_libs info, and will be appended to
// implementationDeps at the end, to solve the confliction that both header_libs
// and static_libs use implementationDeps.
var headerDeps bazel.LabelListAttribute
productVarToDepFields := map[string]productVarDep{
// product variables do not support exclude_shared_libs
"Shared_libs": {attribute: &la.implementationDynamicDeps, depResolutionFunc: bazelLabelForSharedDepsExcludes},
"Static_libs": {"Exclude_static_libs", &la.implementationDeps, bazelLabelForStaticDepsExcludes},
"Whole_static_libs": {"Exclude_static_libs", &la.wholeArchiveDeps, bazelLabelForWholeDepsExcludes},
"Header_libs": {attribute: &headerDeps, depResolutionFunc: bazelLabelForHeaderDepsExcludes},
}
for name, dep := range productVarToDepFields {
@ -1072,6 +1078,7 @@ func (la *linkerAttributes) convertProductVariables(ctx android.BazelConversionP
)
}
}
la.implementationDeps.Append(headerDeps)
}
func (la *linkerAttributes) finalize(ctx android.BazelConversionPathContext) {
@ -1200,6 +1207,12 @@ func bazelLabelForHeaderDeps(ctx android.BazelConversionPathContext, modules []s
return bazelLabelForSharedDeps(ctx, modules)
}
func bazelLabelForHeaderDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
// This is only used when product_variable header_libs is processed, to follow
// the pattern of depResolutionFunc
return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForSharedModule)
}
func bazelLabelForSharedDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForSharedModule)
}