bp2build supports arch variant srcs for java_library
Bug: 209577426
Test: build/bazel/ci/bp2build.sh
Change-Id: I6799bda904d286616e580f2395601ce4f764180f
diff --git a/android/bazel.go b/android/bazel.go
index 86339ab..a923eb2 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -484,11 +484,12 @@
"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 @@
"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 42c1a54..b6095b2 100644
--- a/bp2build/android_app_conversion_test.go
+++ b/bp2build/android_app_conversion_test.go
@@ -94,3 +94,42 @@
}),
}})
}
+
+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 0a35908..895ce7a 100644
--- a/java/java.go
+++ b/java/java.go
@@ -2011,8 +2011,16 @@
}
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"