Loading android/bazel.go +26 −18 Original line number Diff line number Diff line Loading @@ -393,8 +393,6 @@ var ( // A module can either be in this list or its directory allowlisted entirely // in bp2buildDefaultConfig, but not both at the same time. bp2buildModuleAlwaysConvertList = []string{ "prebuilt_junit-params-assertj-core", //external/avb "avbtool", "libavb", Loading @@ -419,9 +417,11 @@ var ( "fec", } // Per-module-type allowlist to always opt modules in of both bp2build and mixed builds // Per-module-type allowlist to always opt modules in to both bp2build and mixed builds // when they have the same type as one listed. bp2buildModuleTypeAlwaysConvertList = []string{} bp2buildModuleTypeAlwaysConvertList = []string{ "java_import", } // Per-module denylist to always opt modules out of both bp2build and mixed builds. bp2buildModuleDoNotConvertList = []string{ Loading Loading @@ -485,18 +485,12 @@ var ( "libprotobuf-java-full", // b/210751803, we don't handle path property for filegroups "host-libprotobuf-java-full", // b/210751803, we don't handle path property for filegroups "libprotobuf-java-util-full", // b/210751803, we don't handle path property for filegroups "apex_manifest_proto_java", // b/210751803, depends on libprotobuf-java-full "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 "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 "libprotobuf-java-nano", // b/220869005, depends on non-public_current SDK "host-libprotobuf-java-nano", // b/220869005, depends on libprotobuf-java-nano "libc_musl_sysroot_bionic_arch_headers", // b/218405924, depends on soong_zip "libc_musl_sysroot_bionic_headers", // b/218405924, depends on soong_zip and generates duplicate srcs Loading Loading @@ -566,9 +560,23 @@ var ( "art-script", // depends on unconverted modules: dalvikvm, dex2oat "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 // TODO(b/221082840) convert java_imports in //packages/apps/Car/libs/car-ui-lib/... "prebuilt_car-ui-androidx-annotation", "prebuilt_car-ui-androidx-annotation-nodeps", "prebuilt_car-ui-androidx-collection", "prebuilt_car-ui-androidx-collection-nodeps", "prebuilt_car-ui-androidx-core-common", "prebuilt_car-ui-androidx-core-common-nodeps", "prebuilt_car-ui-androidx-lifecycle-common", "prebuilt_car-ui-androidx-lifecycle-common-nodeps", "prebuilt_car-ui-androidx-constraintlayout-solver", "prebuilt_car-ui-androidx-constraintlayout-solver-nodeps", "prebuilt_art-module-host-exports_okhttp-norepackage@current", // aosp/1999250, needs Jars (arch variant) "prebuilt_conscrypt-unbundled", // aosp/1999250, needs Jars (arch variant) "prebuilt_conscrypt-module-host-exports_conscrypt-unbundled@current", // aosp/1999250, needs Jars (arch variant) "prebuilt_platform-robolectric-4.4-prebuilt", // aosp/1999250, needs .aar support in Jars "prebuilt_platform-robolectric-4.5.1-prebuilt", // aosp/1999250, needs .aar support in Jars } // Per-module denylist of cc_library modules to only generate the static Loading bazel/properties.go +17 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,14 @@ type LabelList struct { Excludes []Label } // MakeLabelList creates a LabelList from a list Label func MakeLabelList(labels []Label) LabelList { return LabelList{ Includes: labels, Excludes: nil, } } func (ll *LabelList) Equals(other LabelList) bool { if len(ll.Includes) != len(other.Includes) || len(ll.Excludes) != len(other.Excludes) { return false Loading Loading @@ -354,6 +362,15 @@ func (la *LabelAttribute) SortedConfigurationAxes() []ConfigurationAxis { return keys } // MakeLabelAttribute turns a string into a LabelAttribute func MakeLabelAttribute(label string) *LabelAttribute { return &LabelAttribute{ Value: &Label{ Label: label, }, } } type configToBools map[string]bool func (ctb configToBools) setValue(config string, value *bool) { Loading bp2build/android_app_conversion_test.go +1 −6 Original line number Diff line number Diff line Loading @@ -51,7 +51,6 @@ android_app { "srcs": `["app.java"]`, "manifest": `"AndroidManifest.xml"`, "resource_files": `["res/res.png"]`, "deps": `["//prebuilts/sdk:public_current_android_sdk_java_import"]`, }), }}) } Loading Loading @@ -87,10 +86,7 @@ android_app { "resb/res.png", ]`, "custom_package": `"com.google"`, "deps": `[ "//prebuilts/sdk:public_current_android_sdk_java_import", ":static_lib_dep", ]`, "deps": `[":static_lib_dep"]`, }), }}) } Loading Loading @@ -129,7 +125,6 @@ android_app { })`, "manifest": `"AndroidManifest.xml"`, "resource_files": `["res/res.png"]`, "deps": `["//prebuilts/sdk:public_current_android_sdk_java_import"]`, }), }}) } bp2build/java_binary_host_conversion_test.go +31 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ func runJavaBinaryHostTestCase(t *testing.T, tc bp2buildTestCase) { (&tc).moduleTypeUnderTestFactory = java.BinaryHostFactory runBp2BuildTestCase(t, func(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_library_host_shared", cc.LibraryHostSharedFactory) ctx.RegisterModuleType("java_library", java.LibraryFactory) }, tc) } Loading Loading @@ -67,3 +68,33 @@ func TestJavaBinaryHost(t *testing.T) { }, }) } func TestJavaBinaryHostRuntimeDeps(t *testing.T) { runJavaBinaryHostTestCase(t, bp2buildTestCase{ description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.", filesystem: fs, blueprint: `java_binary_host { name: "java-binary-host-1", static_libs: ["java-dep-1"], manifest: "test.mf", bazel_module: { bp2build_available: true }, } java_library { name: "java-dep-1", srcs: ["a.java"], bazel_module: { bp2build_available: false }, } `, expectedBazelTargets: []string{ makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{ "main_class": `"com.android.test.MainClass"`, "runtime_deps": `[":java-dep-1"]`, "target_compatible_with": `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//conditions:default": [], })`, }), }, }) } bp2build/java_library_conversion_test.go +74 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ package bp2build import ( "fmt" "testing" "android/soong/android" Loading Loading @@ -55,3 +56,76 @@ java_library { }, }) } func TestJavaLibraryConvertsStaticLibsToDepsAndExports(t *testing.T) { runJavaLibraryTestCase(t, bp2buildTestCase{ blueprint: `java_library { name: "java-lib-1", srcs: ["a.java"], libs: ["java-lib-2"], static_libs: ["java-lib-3"], bazel_module: { bp2build_available: true }, } java_library { name: "java-lib-2", srcs: ["b.java"], bazel_module: { bp2build_available: false }, } java_library { name: "java-lib-3", srcs: ["c.java"], bazel_module: { bp2build_available: false }, }`, expectedBazelTargets: []string{ makeBazelTarget("java_library", "java-lib-1", attrNameToString{ "srcs": `["a.java"]`, "deps": `[ ":java-lib-2", ":java-lib-3", ]`, "exports": `[":java-lib-3"]`, }), }, }) } func TestJavaLibraryConvertsStaticLibsToExportsIfNoSrcs(t *testing.T) { runJavaLibraryTestCase(t, bp2buildTestCase{ blueprint: `java_library { name: "java-lib-1", static_libs: ["java-lib-2"], bazel_module: { bp2build_available: true }, } java_library { name: "java-lib-2", srcs: ["a.java"], bazel_module: { bp2build_available: false }, }`, expectedBazelTargets: []string{ makeBazelTarget("java_library", "java-lib-1", attrNameToString{ "exports": `[":java-lib-2"]`, }), }, }) } func TestJavaLibraryFailsToConvertLibsWithNoSrcs(t *testing.T) { runJavaLibraryTestCase(t, bp2buildTestCase{ expectedErr: fmt.Errorf("Module has direct dependencies but no sources. Bazel will not allow this."), blueprint: `java_library { name: "java-lib-1", libs: ["java-lib-2"], bazel_module: { bp2build_available: true }, } java_library { name: "java-lib-2", srcs: ["a.java"], bazel_module: { bp2build_available: false }, }`, expectedBazelTargets: []string{}, }) } Loading
android/bazel.go +26 −18 Original line number Diff line number Diff line Loading @@ -393,8 +393,6 @@ var ( // A module can either be in this list or its directory allowlisted entirely // in bp2buildDefaultConfig, but not both at the same time. bp2buildModuleAlwaysConvertList = []string{ "prebuilt_junit-params-assertj-core", //external/avb "avbtool", "libavb", Loading @@ -419,9 +417,11 @@ var ( "fec", } // Per-module-type allowlist to always opt modules in of both bp2build and mixed builds // Per-module-type allowlist to always opt modules in to both bp2build and mixed builds // when they have the same type as one listed. bp2buildModuleTypeAlwaysConvertList = []string{} bp2buildModuleTypeAlwaysConvertList = []string{ "java_import", } // Per-module denylist to always opt modules out of both bp2build and mixed builds. bp2buildModuleDoNotConvertList = []string{ Loading Loading @@ -485,18 +485,12 @@ var ( "libprotobuf-java-full", // b/210751803, we don't handle path property for filegroups "host-libprotobuf-java-full", // b/210751803, we don't handle path property for filegroups "libprotobuf-java-util-full", // b/210751803, we don't handle path property for filegroups "apex_manifest_proto_java", // b/210751803, depends on libprotobuf-java-full "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 "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 "libprotobuf-java-nano", // b/220869005, depends on non-public_current SDK "host-libprotobuf-java-nano", // b/220869005, depends on libprotobuf-java-nano "libc_musl_sysroot_bionic_arch_headers", // b/218405924, depends on soong_zip "libc_musl_sysroot_bionic_headers", // b/218405924, depends on soong_zip and generates duplicate srcs Loading Loading @@ -566,9 +560,23 @@ var ( "art-script", // depends on unconverted modules: dalvikvm, dex2oat "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 // TODO(b/221082840) convert java_imports in //packages/apps/Car/libs/car-ui-lib/... "prebuilt_car-ui-androidx-annotation", "prebuilt_car-ui-androidx-annotation-nodeps", "prebuilt_car-ui-androidx-collection", "prebuilt_car-ui-androidx-collection-nodeps", "prebuilt_car-ui-androidx-core-common", "prebuilt_car-ui-androidx-core-common-nodeps", "prebuilt_car-ui-androidx-lifecycle-common", "prebuilt_car-ui-androidx-lifecycle-common-nodeps", "prebuilt_car-ui-androidx-constraintlayout-solver", "prebuilt_car-ui-androidx-constraintlayout-solver-nodeps", "prebuilt_art-module-host-exports_okhttp-norepackage@current", // aosp/1999250, needs Jars (arch variant) "prebuilt_conscrypt-unbundled", // aosp/1999250, needs Jars (arch variant) "prebuilt_conscrypt-module-host-exports_conscrypt-unbundled@current", // aosp/1999250, needs Jars (arch variant) "prebuilt_platform-robolectric-4.4-prebuilt", // aosp/1999250, needs .aar support in Jars "prebuilt_platform-robolectric-4.5.1-prebuilt", // aosp/1999250, needs .aar support in Jars } // Per-module denylist of cc_library modules to only generate the static Loading
bazel/properties.go +17 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,14 @@ type LabelList struct { Excludes []Label } // MakeLabelList creates a LabelList from a list Label func MakeLabelList(labels []Label) LabelList { return LabelList{ Includes: labels, Excludes: nil, } } func (ll *LabelList) Equals(other LabelList) bool { if len(ll.Includes) != len(other.Includes) || len(ll.Excludes) != len(other.Excludes) { return false Loading Loading @@ -354,6 +362,15 @@ func (la *LabelAttribute) SortedConfigurationAxes() []ConfigurationAxis { return keys } // MakeLabelAttribute turns a string into a LabelAttribute func MakeLabelAttribute(label string) *LabelAttribute { return &LabelAttribute{ Value: &Label{ Label: label, }, } } type configToBools map[string]bool func (ctb configToBools) setValue(config string, value *bool) { Loading
bp2build/android_app_conversion_test.go +1 −6 Original line number Diff line number Diff line Loading @@ -51,7 +51,6 @@ android_app { "srcs": `["app.java"]`, "manifest": `"AndroidManifest.xml"`, "resource_files": `["res/res.png"]`, "deps": `["//prebuilts/sdk:public_current_android_sdk_java_import"]`, }), }}) } Loading Loading @@ -87,10 +86,7 @@ android_app { "resb/res.png", ]`, "custom_package": `"com.google"`, "deps": `[ "//prebuilts/sdk:public_current_android_sdk_java_import", ":static_lib_dep", ]`, "deps": `[":static_lib_dep"]`, }), }}) } Loading Loading @@ -129,7 +125,6 @@ android_app { })`, "manifest": `"AndroidManifest.xml"`, "resource_files": `["res/res.png"]`, "deps": `["//prebuilts/sdk:public_current_android_sdk_java_import"]`, }), }}) }
bp2build/java_binary_host_conversion_test.go +31 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ func runJavaBinaryHostTestCase(t *testing.T, tc bp2buildTestCase) { (&tc).moduleTypeUnderTestFactory = java.BinaryHostFactory runBp2BuildTestCase(t, func(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_library_host_shared", cc.LibraryHostSharedFactory) ctx.RegisterModuleType("java_library", java.LibraryFactory) }, tc) } Loading Loading @@ -67,3 +68,33 @@ func TestJavaBinaryHost(t *testing.T) { }, }) } func TestJavaBinaryHostRuntimeDeps(t *testing.T) { runJavaBinaryHostTestCase(t, bp2buildTestCase{ description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.", filesystem: fs, blueprint: `java_binary_host { name: "java-binary-host-1", static_libs: ["java-dep-1"], manifest: "test.mf", bazel_module: { bp2build_available: true }, } java_library { name: "java-dep-1", srcs: ["a.java"], bazel_module: { bp2build_available: false }, } `, expectedBazelTargets: []string{ makeBazelTarget("java_binary", "java-binary-host-1", attrNameToString{ "main_class": `"com.android.test.MainClass"`, "runtime_deps": `[":java-dep-1"]`, "target_compatible_with": `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//conditions:default": [], })`, }), }, }) }
bp2build/java_library_conversion_test.go +74 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ package bp2build import ( "fmt" "testing" "android/soong/android" Loading Loading @@ -55,3 +56,76 @@ java_library { }, }) } func TestJavaLibraryConvertsStaticLibsToDepsAndExports(t *testing.T) { runJavaLibraryTestCase(t, bp2buildTestCase{ blueprint: `java_library { name: "java-lib-1", srcs: ["a.java"], libs: ["java-lib-2"], static_libs: ["java-lib-3"], bazel_module: { bp2build_available: true }, } java_library { name: "java-lib-2", srcs: ["b.java"], bazel_module: { bp2build_available: false }, } java_library { name: "java-lib-3", srcs: ["c.java"], bazel_module: { bp2build_available: false }, }`, expectedBazelTargets: []string{ makeBazelTarget("java_library", "java-lib-1", attrNameToString{ "srcs": `["a.java"]`, "deps": `[ ":java-lib-2", ":java-lib-3", ]`, "exports": `[":java-lib-3"]`, }), }, }) } func TestJavaLibraryConvertsStaticLibsToExportsIfNoSrcs(t *testing.T) { runJavaLibraryTestCase(t, bp2buildTestCase{ blueprint: `java_library { name: "java-lib-1", static_libs: ["java-lib-2"], bazel_module: { bp2build_available: true }, } java_library { name: "java-lib-2", srcs: ["a.java"], bazel_module: { bp2build_available: false }, }`, expectedBazelTargets: []string{ makeBazelTarget("java_library", "java-lib-1", attrNameToString{ "exports": `[":java-lib-2"]`, }), }, }) } func TestJavaLibraryFailsToConvertLibsWithNoSrcs(t *testing.T) { runJavaLibraryTestCase(t, bp2buildTestCase{ expectedErr: fmt.Errorf("Module has direct dependencies but no sources. Bazel will not allow this."), blueprint: `java_library { name: "java-lib-1", libs: ["java-lib-2"], bazel_module: { bp2build_available: true }, } java_library { name: "java-lib-2", srcs: ["a.java"], bazel_module: { bp2build_available: false }, }`, expectedBazelTargets: []string{}, }) }