Add support for shared_libs in cc_library targets.
Test: cd bp2build; go test
Test: bazel build //bionic/...
Test: ./build/bazel/scripts/run_presubmits.sh
Change-Id: I71e279470a0d69b243dd0a2b53ce31842fd36ee4
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 0551a18..364929c 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -302,6 +302,37 @@
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"],
+)`},
+ },
}
dir := "."
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 1433f6f..7f2554f 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -247,6 +247,7 @@
// 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 @@
// 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 @@
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 @@
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 @@
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 7b631fa..7e960a7 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -225,6 +225,7 @@
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 @@
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,