From cc2c1efc9a2519fba77ed82268b29d9e5680fa7d Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Mon, 21 Mar 2022 09:03:29 -0400 Subject: [PATCH] Dedupe libraries in both static and whole static In Soong, libraries can appear in both static and whole static libs; however, in Bazel, this results in errors due to duplicate libraries. Test: bp2build.sh Change-Id: I9dda4f7a7812340d28a6160d0e25f421c9db6612 --- bp2build/cc_library_conversion_test.go | 11 +++++++++-- cc/bp2build.go | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 8fde6550f..640adbaad 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -279,8 +279,8 @@ cc_library { srcs: ["both.cpp"], cflags: ["bothflag"], shared_libs: ["shared_dep_for_both"], - static_libs: ["static_dep_for_both"], - whole_static_libs: ["whole_static_lib_for_both"], + static_libs: ["static_dep_for_both", "whole_and_static_lib_for_both"], + whole_static_libs: ["whole_static_lib_for_both", "whole_and_static_lib_for_both"], static: { srcs: ["staticonly.cpp"], cflags: ["staticflag"], @@ -328,6 +328,11 @@ cc_library_static { bazel_module: { bp2build_available: false }, } +cc_library_static { + name: "whole_and_static_lib_for_both", + bazel_module: { bp2build_available: false }, +} + cc_library { name: "shared_dep_for_shared", bazel_module: { bp2build_available: false }, @@ -363,6 +368,7 @@ cc_library { ]`, "whole_archive_deps": `[ ":whole_static_lib_for_both", + ":whole_and_static_lib_for_both", ":whole_static_lib_for_static", ]`}), makeBazelTarget("cc_library_shared", "a", attrNameToString{ @@ -384,6 +390,7 @@ cc_library { ]`, "whole_archive_deps": `[ ":whole_static_lib_for_both", + ":whole_and_static_lib_for_both", ":whole_static_lib_for_shared", ]`, }), diff --git a/cc/bp2build.go b/cc/bp2build.go index 379d6f246..11de740a1 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -571,9 +571,12 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion // Use a single variable to capture usage of nocrt in arch variants, so there's only 1 error message for this module var axisFeatures []string + wholeStaticLibs := android.FirstUniqueStrings(props.Whole_static_libs) + la.wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeStaticLibs, props.Exclude_static_libs)) // Excludes to parallel Soong: // https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0 - staticLibs := android.FirstUniqueStrings(props.Static_libs) + staticLibs := android.FirstUniqueStrings(android.RemoveListFromList(props.Static_libs, wholeStaticLibs)) + staticDeps := maybePartitionExportedAndImplementationsDepsExcludes(ctx, !isBinary, staticLibs, props.Exclude_static_libs, props.Export_static_lib_headers, bazelLabelForStaticDepsExcludes) headerLibs := android.FirstUniqueStrings(props.Header_libs) @@ -585,9 +588,6 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion (&hDeps.implementation).Append(staticDeps.implementation) la.implementationDeps.SetSelectValue(axis, config, hDeps.implementation) - wholeStaticLibs := android.FirstUniqueStrings(props.Whole_static_libs) - la.wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeStaticLibs, props.Exclude_static_libs)) - systemSharedLibs := props.System_shared_libs // systemSharedLibs distinguishes between nil/empty list behavior: // nil -> use default values