From 947dfa760b5dbd6e0b8fd1f1729efb97eded5696 Mon Sep 17 00:00:00 2001 From: Romain Jobredeaux Date: Mon, 12 Jun 2023 15:40:35 -0400 Subject: [PATCH] Bp2build support for JNI deps of android_app. Change-Id: I3f934ecb0323129e1bb1eb75527395e39467380d Bug: 297405812 --- android/allowlists/allowlists.go | 4 ++++ bp2build/android_app_conversion_test.go | 19 +++++++++++++------ java/app.go | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index 5b77ba97d..9997f544c 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -852,6 +852,10 @@ var ( "libstagefright_headers", + // Apps with JNI libs + "SimpleJNI", + "libsimplejni", + // aidl "aidl", "libaidl-common", diff --git a/bp2build/android_app_conversion_test.go b/bp2build/android_app_conversion_test.go index 0daa4fe69..7f04e2ac2 100644 --- a/bp2build/android_app_conversion_test.go +++ b/bp2build/android_app_conversion_test.go @@ -16,6 +16,7 @@ package bp2build import ( "android/soong/android" + "android/soong/cc" "android/soong/java" "testing" @@ -29,6 +30,7 @@ func runAndroidAppTestCase(t *testing.T, tc Bp2buildTestCase) { func registerAndroidAppModuleTypes(ctx android.RegistrationContext) { ctx.RegisterModuleType("filegroup", android.FileGroupFactory) ctx.RegisterModuleType("java_library", java.LibraryFactory) + ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory) } func TestMinimalAndroidApp(t *testing.T) { @@ -78,8 +80,9 @@ func TestAndroidAppAllSupportedFields(t *testing.T) { "manifest/AndroidManifest.xml": "", "assets_/asset.png": "", }, - StubbedBuildDefinitions: []string{"static_lib_dep"}, - Blueprint: simpleModule("android_app", "static_lib_dep") + ` + StubbedBuildDefinitions: []string{"static_lib_dep", "jni_lib"}, + Blueprint: simpleModule("android_app", "static_lib_dep") + + simpleModule("cc_library_shared", "jni_lib") + ` android_app { name: "TestApp", srcs: ["app.java"], @@ -100,6 +103,7 @@ android_app { obfuscate: false, ignore_warnings: true, }, + jni_libs: ["jni_lib"], } `, ExpectedBazelTargets: []string{ @@ -110,10 +114,13 @@ android_app { "resa/res.png", "resb/res.png", ]`, - "assets": `["assets_/asset.png"]`, - "assets_dir": `"assets_"`, - "custom_package": `"com.google"`, - "deps": `[":static_lib_dep"]`, + "assets": `["assets_/asset.png"]`, + "assets_dir": `"assets_"`, + "custom_package": `"com.google"`, + "deps": `[ + ":static_lib_dep", + ":jni_lib", + ]`, "java_version": `"7"`, "sdk_version": `"current"`, "certificate_name": `"foocert"`, diff --git a/java/app.go b/java/app.go index 2edd3f74b..611d0a6b9 100755 --- a/java/app.go +++ b/java/app.go @@ -1716,6 +1716,20 @@ func convertWithBp2build(ctx android.Bp2buildMutatorContext, a *AndroidApp) (boo deps := depLabels.Deps deps.Append(depLabels.StaticDeps) + var jniDeps bazel.LabelListAttribute + archVariantProps := a.GetArchVariantProperties(ctx, &appProperties{}) + for axis, configToProps := range archVariantProps { + for config, _props := range configToProps { + if archProps, ok := _props.(*appProperties); ok { + archJniLibs := android.BazelLabelForModuleDeps( + ctx, + android.LastUniqueStrings(android.CopyOf(archProps.Jni_libs))) + jniDeps.SetSelectValue(axis, config, archJniLibs) + } + } + } + deps.Append(jniDeps) + if !bp2BuildInfo.hasKotlin { appAttrs.javaCommonAttributes = commonAttrs appAttrs.bazelAapt = aapt