From e91d0303f2f1c71eec9e9f89da8b1985a966e81a Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Wed, 23 Feb 2022 15:28:33 +0000 Subject: [PATCH] bp2build supports arch variant srcs for java_library Bug: 209577426 Test: build/bazel/ci/bp2build.sh Change-Id: I6799bda904d286616e580f2395601ce4f764180f --- android/bazel.go | 13 +++++---- bp2build/android_app_conversion_test.go | 39 +++++++++++++++++++++++++ java/java.go | 12 ++++++-- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/android/bazel.go b/android/bazel.go index 86339ab3f..a923eb287 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -484,11 +484,12 @@ var ( "conscrypt", // b/210751803, we don't handle path property for filegroups "conscrypt-for-host", // b/210751803, we don't handle path property for filegroups - "host-libprotobuf-java-lite", // b/217236083, java_library cannot have deps without srcs - "host-libprotobuf-java-micro", // b/217236083, java_library cannot have deps without srcs - "host-libprotobuf-java-nano", // b/217236083, java_library cannot have deps without srcs - "error_prone_core", // b/217236083, java_library cannot have deps without srcs - "bouncycastle-host", // b/217236083, java_library cannot have deps without srcs + "host-libprotobuf-java-lite", // b/217236083, java_library cannot have deps without srcs + "host-libprotobuf-java-micro", // b/217236083, java_library cannot have deps without srcs + "host-libprotobuf-java-nano", // b/217236083, java_library cannot have deps without srcs + "error_prone_core", // b/217236083, java_library cannot have deps without srcs + "bouncycastle-host", // b/217236083, java_library cannot have deps without srcs + "mockito-robolectric-prebuilt", // b/217236083, java_library cannot have deps without srcs "apex_manifest_proto_java", // b/215230097, we don't handle .proto files in java_library srcs attribute @@ -558,6 +559,8 @@ var ( "dex2oat-script", // depends on unconverted modules: dex2oat "error_prone_checkerframework_dataflow_nullaway", // TODO(b/219908977): "Error in fail: deps not allowed without srcs; move to runtime_deps?" + + "libprotobuf-java-nano", // b/220869005, depends on non-public_current SDK } // Per-module denylist of cc_library modules to only generate the static diff --git a/bp2build/android_app_conversion_test.go b/bp2build/android_app_conversion_test.go index 42c1a5458..b6095b2ef 100644 --- a/bp2build/android_app_conversion_test.go +++ b/bp2build/android_app_conversion_test.go @@ -94,3 +94,42 @@ android_app { }), }}) } + +func TestAndroidAppArchVariantSrcs(t *testing.T) { + runAndroidAppTestCase(t, bp2buildTestCase{ + description: "Android app - arch variant srcs", + moduleTypeUnderTest: "android_app", + moduleTypeUnderTestFactory: java.AndroidAppFactory, + filesystem: map[string]string{ + "arm.java": "", + "x86.java": "", + "res/res.png": "", + "AndroidManifest.xml": "", + }, + blueprint: ` +android_app { + name: "TestApp", + sdk_version: "current", + arch: { + arm: { + srcs: ["arm.java"], + }, + x86: { + srcs: ["x86.java"], + } + } +} +`, + expectedBazelTargets: []string{ + makeBazelTarget("android_binary", "TestApp", attrNameToString{ + "srcs": `select({ + "//build/bazel/platforms/arch:arm": ["arm.java"], + "//build/bazel/platforms/arch:x86": ["x86.java"], + "//conditions:default": [], + })`, + "manifest": `"AndroidManifest.xml"`, + "resource_files": `["res/res.png"]`, + "deps": `["//prebuilts/sdk:public_current_android_sdk_java_import"]`, + }), + }}) +} diff --git a/java/java.go b/java/java.go index 0a35908dd..895ce7af1 100644 --- a/java/java.go +++ b/java/java.go @@ -2011,8 +2011,16 @@ type javaLibraryAttributes struct { } func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) *javaLibraryAttributes { - //TODO(b/209577426): Support multiple arch variants - srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs)) + var srcs bazel.LabelListAttribute + archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{}) + for axis, configToProps := range archVariantProps { + for config, _props := range configToProps { + if archProps, ok := _props.(*CommonProperties); ok { + archSrcs := android.BazelLabelForModuleSrcExcludes(ctx, archProps.Srcs, archProps.Exclude_srcs) + srcs.SetSelectValue(axis, config, archSrcs) + } + } + } javaSrcPartition := "java" protoSrcPartition := "proto"