From 484aa2587575006b33cd76b29c79c5aad8358090 Mon Sep 17 00:00:00 2001 From: Rupert Shuttleworth Date: Fri, 10 Dec 2021 07:22:53 -0500 Subject: [PATCH] Add initial support for use_version_lib. Test: Resolves build error for BP2BUILD_VERBOSE=1 b build //packages/modules/adb:libadbd_core Test: Added unit test Bug: 208481704 Change-Id: I4022c686c7baf050de3f97295fe4654515622a66 --- bp2build/cc_library_shared_conversion_test.go | 15 ++++++ bp2build/cc_library_static_conversion_test.go | 15 ++++++ cc/bp2build.go | 5 ++ cc/library.go | 49 +++++++++++-------- 4 files changed, 64 insertions(+), 20 deletions(-) diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go index e0331bee5..64f368ecc 100644 --- a/bp2build/cc_library_shared_conversion_test.go +++ b/bp2build/cc_library_shared_conversion_test.go @@ -450,3 +450,18 @@ func TestCcLibrarySharedProto(t *testing.T) { }, }) } + +func TestCcLibrarySharedUseVersionLib(t *testing.T) { + runCcLibrarySharedTestCase(t, bp2buildTestCase{ + blueprint: soongCcProtoPreamble + `cc_library_shared { + name: "foo", + use_version_lib: true, + include_build_directory: false, +}`, + expectedBazelTargets: []string{ + makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + "use_version_lib": "True", + }), + }, + }) +} diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go index 02229e51e..ef82c6b23 100644 --- a/bp2build/cc_library_static_conversion_test.go +++ b/bp2build/cc_library_static_conversion_test.go @@ -1443,3 +1443,18 @@ func TestCcLibraryStaticProto(t *testing.T) { }, }) } + +func TestCcLibraryStaticUseVersionLib(t *testing.T) { + runCcLibraryStaticTestCase(t, bp2buildTestCase{ + blueprint: soongCcProtoPreamble + `cc_library_static { + name: "foo", + use_version_lib: true, + include_build_directory: false, +}`, + expectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo", attrNameToString{ + "use_version_lib": "True", + }), + }, + }) +} diff --git a/cc/bp2build.go b/cc/bp2build.go index f9bbe8752..09aa1363c 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -496,6 +496,7 @@ type linkerAttributes struct { linkCrt bazel.BoolAttribute useLibcrt bazel.BoolAttribute + useVersionLib bazel.BoolAttribute linkopts bazel.StringListAttribute additionalLinkerInputs bazel.LabelListAttribute stripKeepSymbols bazel.BoolAttribute @@ -565,6 +566,10 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion la.linkopts.SetSelectValue(axis, config, linkerFlags) la.useLibcrt.SetSelectValue(axis, config, props.libCrt()) + if axis == bazel.NoConfigAxis { + la.useVersionLib.SetSelectValue(axis, config, props.Use_version_lib) + } + // it's very unlikely for nocrt to be arch variant, so bp2build doesn't support it. if props.crt() != nil { if axis == bazel.NoConfigAxis { diff --git a/cc/library.go b/cc/library.go index a081c7db0..771a6df36 100644 --- a/cc/library.go +++ b/cc/library.go @@ -2480,7 +2480,9 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext, attrs = &bazelCcLibraryStaticAttributes{ staticOrSharedAttributes: commonAttrs, - Use_libcrt: linkerAttrs.useLibcrt, + Use_libcrt: linkerAttrs.useLibcrt, + Use_version_lib: linkerAttrs.useVersionLib, + Rtti: compilerAttrs.rtti, Stl: compilerAttrs.stl, Cpp_std: compilerAttrs.cppStd, @@ -2505,14 +2507,16 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext, Cppflags: compilerAttrs.cppFlags, Conlyflags: compilerAttrs.conlyFlags, Asflags: asFlags, - Linkopts: linkerAttrs.linkopts, - Link_crt: linkerAttrs.linkCrt, - Use_libcrt: linkerAttrs.useLibcrt, - Rtti: compilerAttrs.rtti, - Stl: compilerAttrs.stl, - Cpp_std: compilerAttrs.cppStd, - C_std: compilerAttrs.cStd, + Linkopts: linkerAttrs.linkopts, + Link_crt: linkerAttrs.linkCrt, + Use_libcrt: linkerAttrs.useLibcrt, + Use_version_lib: linkerAttrs.useVersionLib, + + Rtti: compilerAttrs.rtti, + Stl: compilerAttrs.stl, + Cpp_std: compilerAttrs.cppStd, + C_std: compilerAttrs.cStd, Export_includes: exportedIncludes.Includes, Export_system_includes: exportedIncludes.SystemIncludes, @@ -2544,11 +2548,13 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext, type bazelCcLibraryStaticAttributes struct { staticOrSharedAttributes - Use_libcrt bazel.BoolAttribute - Rtti bazel.BoolAttribute - Stl *string - Cpp_std *string - C_std *string + Use_libcrt bazel.BoolAttribute + Use_version_lib bazel.BoolAttribute + + Rtti bazel.BoolAttribute + Stl *string + Cpp_std *string + C_std *string Export_includes bazel.StringListAttribute Export_system_includes bazel.StringListAttribute @@ -2579,13 +2585,16 @@ func CcLibraryStaticBp2Build(ctx android.TopDownMutatorContext) { type bazelCcLibrarySharedAttributes struct { staticOrSharedAttributes - Linkopts bazel.StringListAttribute - Link_crt bazel.BoolAttribute // Only for linking shared library (and cc_binary) - Use_libcrt bazel.BoolAttribute - Rtti bazel.BoolAttribute - Stl *string - Cpp_std *string - C_std *string + Linkopts bazel.StringListAttribute + Link_crt bazel.BoolAttribute // Only for linking shared library (and cc_binary) + + Use_libcrt bazel.BoolAttribute + Use_version_lib bazel.BoolAttribute + + Rtti bazel.BoolAttribute + Stl *string + Cpp_std *string + C_std *string Export_includes bazel.StringListAttribute Export_system_includes bazel.StringListAttribute