From 7fa0696eb7844517cddd1100f74f73a21a3d7eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20M=C3=A1rquez=20P=C3=A9rez=20Mu=C3=B1=C3=ADz=20D?= =?UTF-8?q?=C3=ADaz=20P=C3=BAras=20Thaureaux?= Date: Mon, 25 Oct 2021 10:28:33 -0400 Subject: [PATCH] cc_prebuilt_library_shared converted via bp2build Bug: b/203699063 Test: bp2build/cc_prebuilt_library_shared_test.go Test: USE_BAZEL_ANALYSIS=1 m nothing Test: mixed_{libc,droid}.sh Change-Id: I4c58224e88c31507a4b285f8c55bdc066bd47232 --- bp2build/cc_prebuilt_library_shared_test.go | 65 +++++++++++++++++++++ cc/prebuilt.go | 39 +++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 bp2build/cc_prebuilt_library_shared_test.go diff --git a/bp2build/cc_prebuilt_library_shared_test.go b/bp2build/cc_prebuilt_library_shared_test.go new file mode 100644 index 000000000..97545c886 --- /dev/null +++ b/bp2build/cc_prebuilt_library_shared_test.go @@ -0,0 +1,65 @@ +package bp2build + +import ( + "testing" + + "android/soong/cc" +) + +func TestSharedPrebuiltLibrary(t *testing.T) { + runBp2BuildTestCaseSimple(t, + bp2buildTestCase{ + description: "prebuilt library shared simple", + moduleTypeUnderTest: "cc_prebuilt_library_shared", + moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory, + moduleTypeUnderTestBp2BuildMutator: cc.PrebuiltLibrarySharedBp2Build, + filesystem: map[string]string{ + "libf.so": "", + }, + blueprint: ` +cc_prebuilt_library_shared { + name: "libtest", + srcs: ["libf.so"], + bazel_module: { bp2build_available: true }, +}`, + expectedBazelTargets: []string{ + `prebuilt_library_shared( + name = "libtest", + shared_library = "libf.so", +)`, + }, + }) +} + +func TestSharedPrebuiltLibraryWithArchVariance(t *testing.T) { + runBp2BuildTestCaseSimple(t, + bp2buildTestCase{ + description: "prebuilt library shared with arch variance", + moduleTypeUnderTest: "cc_prebuilt_library_shared", + moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory, + moduleTypeUnderTestBp2BuildMutator: cc.PrebuiltLibrarySharedBp2Build, + filesystem: map[string]string{ + "libf.so": "", + "libg.so": "", + }, + blueprint: ` +cc_prebuilt_library_shared { + name: "libtest", + arch: { + arm64: { srcs: ["libf.so"], }, + arm: { srcs: ["libg.so"], }, + }, + bazel_module: { bp2build_available: true }, +}`, + expectedBazelTargets: []string{ + `prebuilt_library_shared( + name = "libtest", + shared_library = select({ + "//build/bazel/platforms/arch:arm": "libg.so", + "//build/bazel/platforms/arch:arm64": "libf.so", + "//conditions:default": None, + }), +)`, + }, + }) +} diff --git a/cc/prebuilt.go b/cc/prebuilt.go index 4a2c451f5..3401e3658 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -18,6 +18,7 @@ import ( "path/filepath" "android/soong/android" + "android/soong/bazel" ) func init() { @@ -31,6 +32,8 @@ func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_prebuilt_test_library_shared", PrebuiltSharedTestLibraryFactory) ctx.RegisterModuleType("cc_prebuilt_object", prebuiltObjectFactory) ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) + + android.RegisterBp2BuildMutator("cc_prebuilt_library_shared", PrebuiltLibrarySharedBp2Build) } type prebuiltLinkerInterface interface { @@ -309,6 +312,42 @@ func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libr return module, library } +type bazelPrebuiltLibrarySharedAttributes struct { + Shared_library bazel.LabelAttribute +} + +func PrebuiltLibrarySharedBp2Build(ctx android.TopDownMutatorContext) { + module, ok := ctx.Module().(*Module) + if !ok { + // Not a cc module + return + } + if !module.ConvertWithBp2build(ctx) { + return + } + if ctx.ModuleType() != "cc_prebuilt_library_shared" { + return + } + + prebuiltLibrarySharedBp2BuildInternal(ctx, module) +} + +func prebuiltLibrarySharedBp2BuildInternal(ctx android.TopDownMutatorContext, module *Module) { + prebuiltAttrs := Bp2BuildParsePrebuiltLibraryProps(ctx, module) + + attrs := &bazelPrebuiltLibrarySharedAttributes{ + Shared_library: prebuiltAttrs.Src, + } + + props := bazel.BazelTargetModuleProperties{ + Rule_class: "prebuilt_library_shared", + Bzl_load_location: "//build/bazel/rules:prebuilt_library_shared.bzl", + } + + name := android.RemoveOptionalPrebuiltPrefix(module.Name()) + ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs) +} + type prebuiltObjectProperties struct { Srcs []string `android:"path,arch_variant"` }