diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 0551a18f1..364929cb7 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -300,6 +300,37 @@ cc_library { copts = ["-Ifoo/bar"], srcs = ["a.cpp"], version_script = "v.map", +)`}, + }, + { + description: "cc_library shared_libs", + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, + depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, + dir: "foo/bar", + filesystem: map[string]string{ + "foo/bar/Android.bp": ` +cc_library { + name: "mylib", + bazel_module: { bp2build_available: true }, +} + +cc_library { + name: "a", + shared_libs: ["mylib",], + bazel_module: { bp2build_available: true }, +} +`, + }, + bp: soongCcLibraryPreamble, + expectedBazelTargets: []string{`cc_library( + name = "a", + copts = ["-Ifoo/bar"], + dynamic_deps = [":mylib"], +)`, `cc_library( + name = "mylib", + copts = ["-Ifoo/bar"], )`}, }, } diff --git a/cc/bp2build.go b/cc/bp2build.go index 1433f6f79..7f2554fc1 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -247,6 +247,7 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul // Convenience struct to hold all attributes parsed from linker properties. type linkerAttributes struct { deps bazel.LabelListAttribute + dynamicDeps bazel.LabelListAttribute linkopts bazel.StringListAttribute versionScript bazel.LabelAttribute } @@ -255,6 +256,7 @@ type linkerAttributes struct { // configurable attribute values. func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes { var deps bazel.LabelListAttribute + var dynamicDeps bazel.LabelListAttribute var linkopts bazel.StringListAttribute var versionScript bazel.LabelAttribute @@ -266,11 +268,16 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs = append(libs, baseLinkerProps.Whole_static_libs...) libs = android.SortedUniqueStrings(libs) deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs)) + linkopts.Value = baseLinkerProps.Ldflags if baseLinkerProps.Version_script != nil { versionScript.Value = android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script) } + + sharedLibs := baseLinkerProps.Shared_libs + dynamicDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, sharedLibs)) + break } } @@ -283,10 +290,15 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs = append(libs, baseLinkerProps.Whole_static_libs...) libs = android.SortedUniqueStrings(libs) deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs)) + linkopts.SetValueForArch(arch.Name, baseLinkerProps.Ldflags) + if baseLinkerProps.Version_script != nil { versionScript.SetValueForArch(arch.Name, android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)) + + sharedLibs := baseLinkerProps.Shared_libs + dynamicDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs)) } } } @@ -299,12 +311,17 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs = append(libs, baseLinkerProps.Whole_static_libs...) libs = android.SortedUniqueStrings(libs) deps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs)) + linkopts.SetValueForOS(os.Name, baseLinkerProps.Ldflags) + + sharedLibs := baseLinkerProps.Shared_libs + dynamicDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs)) } } return linkerAttributes{ deps: deps, + dynamicDeps: dynamicDeps, linkopts: linkopts, versionScript: versionScript, } diff --git a/cc/library.go b/cc/library.go index 7b631fa16..7e960a7fa 100644 --- a/cc/library.go +++ b/cc/library.go @@ -225,6 +225,7 @@ type bazelCcLibraryAttributes struct { Copts bazel.StringListAttribute Linkopts bazel.StringListAttribute Deps bazel.LabelListAttribute + Dynamic_deps bazel.LabelListAttribute User_link_flags bazel.StringListAttribute Includes bazel.StringListAttribute Static_deps_for_shared bazel.LabelListAttribute @@ -282,6 +283,7 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) { Copts: compilerAttrs.copts, Linkopts: linkerAttrs.linkopts, Deps: linkerAttrs.deps, + Dynamic_deps: linkerAttrs.dynamicDeps, Version_script: linkerAttrs.versionScript, Static_deps_for_shared: sharedAttrs.staticDeps, Includes: exportedIncludes,