Convert cc_test targets with bp2build.
Starting with libutils_test, adb_test, libcutils_test, (and ~47 other host_supported tests).
Test: $ b build --config=android_x86_64 //system/core/libutils:libutils_test && adb push bazel-bin/system/core/libutils/. /data/tmp/libutils_test_files/ && adb shell /data/tmp/libutils_test_files/libutils_test
Test: presubmits with newly converted cc_test targets
Test: $ b test //system/... --config=linux_x86_64 --verbose_failures --test_output=errors --keep_going --build_tests_only
Fixes: 242038415
Change-Id: I10051aadb880c3aabeba6d7fb079523e6fb4ac43
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 3223b04..380c0a0 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -139,6 +139,7 @@
"external/lzma/C": Bp2BuildDefaultTrueRecursively,
"external/mdnsresponder": Bp2BuildDefaultTrueRecursively,
"external/minijail": Bp2BuildDefaultTrueRecursively,
+ "external/openscreen": Bp2BuildDefaultTrueRecursively,
"external/pcre": Bp2BuildDefaultTrueRecursively,
"external/protobuf": Bp2BuildDefaultTrueRecursively,
"external/python/six": Bp2BuildDefaultTrueRecursively,
@@ -225,6 +226,8 @@
"prebuilts/sdk/current/support": Bp2BuildDefaultTrue,
"prebuilts/tools/common/m2": Bp2BuildDefaultTrue,
+ "platform_testing/tests/example": Bp2BuildDefaultTrueRecursively,
+
"system/apex": Bp2BuildDefaultFalse, // TODO(b/207466993): flaky failures
"system/apex/apexer": Bp2BuildDefaultTrue,
"system/apex/libs": Bp2BuildDefaultTrueRecursively,
@@ -268,6 +271,7 @@
"system/memory/libion": Bp2BuildDefaultTrueRecursively,
"system/memory/libmemunreachable": Bp2BuildDefaultTrueRecursively,
"system/sepolicy/apex": Bp2BuildDefaultTrueRecursively,
+ "system/testing/gtest_extras": Bp2BuildDefaultTrueRecursively,
"system/timezone/apex": Bp2BuildDefaultTrueRecursively,
"system/timezone/output_data": Bp2BuildDefaultTrueRecursively,
"system/tools/sysprop": Bp2BuildDefaultTrue,
@@ -432,6 +436,8 @@
// needed for aidl_interface's ndk backend
"libbinder_ndk",
+
+ "libusb",
}
Bp2buildModuleTypeAlwaysConvertList = []string{
@@ -446,7 +452,13 @@
"libactivitymanager_aidl", // TODO(b/207426160): Unsupported use of aidl sources (via Dactivity_manager_procstate_aidl) in a cc_library
"gen-kotlin-build-file.py", // TODO(b/198619163) module has same name as source
"libgtest_ndk_c++", "libgtest_main_ndk_c++", // TODO(b/201816222): Requires sdk_version support.
- "linkerconfig", "mdnsd", // TODO(b/202876379): has arch-variant static_executable
+
+ // TODO(b/202876379): has arch-variant static_executable
+ "linkerconfig",
+ "mdnsd",
+ "libcutils_test_static",
+ "KernelLibcutilsTest",
+
"linker", // TODO(b/228316882): cc_binary uses link_crt
"libdebuggerd", // TODO(b/228314770): support product variable-specific header_libs
"versioner", // TODO(b/228313961): depends on prebuilt shared library libclang-cpp_host as a shared library, which does not supply expected providers for a shared library
@@ -516,7 +528,6 @@
"generated_android_icu4j_resources", // depends on unconverted modules: android_icu4j_srcgen_binary, soong_zip
"generated_android_icu4j_test_resources", // depends on unconverted modules: android_icu4j_srcgen_binary, soong_zip
"host-libprotobuf-java-nano", // b/220869005, depends on libprotobuf-java-nano
- "libadb_host", // depends on unconverted modules: AdbWinApi, libopenscreen-discovery, libopenscreen-platform-impl, libusb
"libapexutil", // depends on unconverted modules: apex-info-list-tinyxml
"libart", // depends on unconverted modules: apex-info-list-tinyxml, libtinyxml2, libnativeloader-headers, heapprofd_client_api, art_operator_srcs, libcpu_features, libodrstatslog, libelffile, art_cmdlineparser_headers, cpp-define-generator-definitions, libdexfile, libnativebridge, libnativeloader, libsigchain, libartbase, libprofile, cpp-define-generator-asm-support
"libart-runtime-gtest", // depends on unconverted modules: libgtest_isolated, libart-compiler, libdexfile, libprofile, libartbase, libartbase-art-gtest
@@ -555,23 +566,467 @@
// '//bionic/libc:libc_bp2build_cc_library_static' is duplicated in the 'deps' attribute of rule
"toybox-static",
- // Do not convert the following modules because of duplicate labels checking in Bazel.
- // See b/241283350. They should be removed from this list once the bug is fixed.
- "libartpalette",
- "libartbase",
- "libdexfile",
- "libartbased",
- "libdexfile_static",
- "libartbase-testing",
- "libartbased-testing",
- "libdexfile_support",
- "libunwindstack",
- "libunwindstack_local",
- "libfdtrack",
- "libc_malloc_debug",
- "libutilscallstack",
- "libunwindstack_utils",
- "unwind_for_offline",
+ // cc_test related.
+ // Failing host cc_tests
+ "memunreachable_unit_test",
+ "libprocinfo_test",
+ "ziparchive-tests",
+ "gtest_isolated_tests",
+ "libunwindstack_unit_test",
+ "task_profiles_test",
+ "power_tests", // failing test on server, but not on host
+
+ // reflect: call of reflect.Value.NumField on interface Value
+ // affects all cc_tests that depend on art_defaults
+ "libnativebridge-tests",
+ "libnativeloader_test",
+ "art_libnativebridge_cts_tests",
+ "art_standalone_libdexfile_external_tests",
+ "art_standalone_libdexfile_support_tests",
+ "libnativebridge-lazy-tests",
+ "libnativebridge-test-case",
+ "libnativebridge2-test-case",
+ "libnativebridge3-test-case",
+ "libnativebridge6-test-case",
+ "libnativebridge6prezygotefork",
+
+ // cc_test with unconverted deps, or are device-only (and not verified to pass yet)
+ "AMRWBEncTest",
+ "AmrnbDecoderTest", // depends on unconverted modules: libaudioutils, libsndfile
+ "AmrnbEncoderTest", // depends on unconverted modules: libaudioutils, libsndfile
+ "AmrwbDecoderTest", // depends on unconverted modules: libsndfile, libaudioutils
+ "AmrwbEncoderTest", // depends on unconverted modules: libaudioutils, libsndfile
+ "CtsLiblogTestCases",
+ "Mp3DecoderTest", // depends on unconverted modules: libsndfile, libaudioutils
+ "Mpeg4H263DecoderTest", // depends on unconverted modules: libstagefright_foundation
+ "Mpeg4H263EncoderTest",
+ "adb_crypto_test",
+ "adb_pairing_auth_test",
+ "adb_pairing_connection_test",
+ "adb_tls_connection_test",
+ "adbd_test", // depends on unconverted modules: libusb
+ "avcdec",
+ "avcenc",
+ "bionic-benchmarks-tests",
+ "bionic-fortify-runtime-asan-test",
+ "bionic-stress-tests",
+ "bionic-unit-tests",
+ "bionic-unit-tests-glibc",
+ "bionic-unit-tests-static",
+ "boringssl_crypto_test",
+ "boringssl_ssl_test",
+ "cfi_test_helper",
+ "cfi_test_helper2",
+ "cintltst32",
+ "cintltst64",
+ "compare",
+ "cpuid",
+ "debuggerd_test", // depends on unconverted modules: libdebuggerd
+ "elftls_dlopen_ie_error_helper",
+ "exec_linker_helper",
+ "fastdeploy_test", // depends on unconverted modules: AdbWinApi, libadb_host, libandroidfw, libfastdeploy_host, libopenscreen-discovery, libopenscreen-platform-impl, libusb
+ "fdtrack_test",
+ "google-benchmark-test",
+ "googletest-param-test-test_ndk", // depends on unconverted modules: libgtest_ndk_c++
+ "gtest-typed-test_test",
+ "gtest-typed-test_test_ndk", // depends on unconverted modules: libgtest_ndk_c++, libgtest_main_ndk_c++
+ "gtest_ndk_tests", // depends on unconverted modules: libgtest_ndk_c++, libgtest_main_ndk_c++
+ "gtest_ndk_tests_no_main", // depends on unconverted modules: libgtest_ndk_c++
+ "gtest_prod_test_ndk", // depends on unconverted modules: libgtest_ndk_c++, libgtest_main_ndk_c++
+ "gtest_tests",
+ "gtest_tests_no_main",
+ "gwp_asan_unittest",
+ "half_test",
+ "hashcombine_test",
+ "hevcdec",
+ "hevcenc",
+ "hwbinderThroughputTest", // depends on unconverted modules: android.hardware.tests.libhwbinder@1.0-impl.test, android.hardware.tests.libhwbinder@1.0
+ "i444tonv12_eg",
+ "icu4c_sample_break",
+ "intltest32",
+ "intltest64",
+ "ion-unit-tests",
+ "jemalloc5_integrationtests",
+ "jemalloc5_unittests",
+ "ld_config_test_helper",
+ "ld_preload_test_helper",
+ "libBionicCtsGtestMain", // depends on unconverted modules: libgtest_isolated
+ "libBionicLoaderTests", // depends on unconverted modules: libmeminfo
+ "libapexutil_tests", // depends on unconverted modules: apex-info-list-tinyxml, libapexutil
+ "libavservices_minijail_unittest",
+ "libcutils_sockets_test",
+ "libexpectedutils_test",
+ "libhwbinder_latency",
+ "liblog-host-test",
+ "liblog-unit-tests",
+ "libminijail_test",
+ "libminijail_unittest_gtest",
+ "libpackagelistparser_test",
+ "libprotobuf_vendor_suffix_test",
+ "libstagefright_amrnbdec_test", // depends on unconverted modules: libsndfile, libaudioutils
+ "libstagefright_amrnbenc_test",
+ "libstagefright_amrwbdec_test", // depends on unconverted modules: libsndfile, libaudioutils
+ "libstagefright_m4vh263enc_test",
+ "libstagefright_mp3dec_test", // depends on unconverted modules: libsndfile, libaudioutils
+ "libstatssocket_test",
+ "libvndksupport-tests",
+ "libyuv_unittest",
+ "linker-unit-tests",
+ "malloc_debug_system_tests",
+ "malloc_debug_unit_tests",
+ "malloc_hooks_system_tests",
+ "mat_test",
+ "mathtest",
+ "memunreachable_binder_test", // depends on unconverted modules: libbinder
+ "memunreachable_test",
+ "metadata_tests",
+ "minijail0_cli_unittest_gtest",
+ "mpeg2dec",
+ "mvcdec",
+ "ns_hidden_child_helper",
+ "pngtest",
+ "preinit_getauxval_test_helper",
+ "preinit_syscall_test_helper",
+ "psnr",
+ "quat_test",
+ "rappor-tests", // depends on unconverted modules: jsr305, guava
+ "scudo_unit_tests",
+ "stats-log-api-gen-test", // depends on unconverted modules: libstats_proto_host
+ "syscall_filter_unittest_gtest",
+ "sysprop_test", // depends on unconverted modules: libcom.android.sysprop.tests
+ "thread_exit_cb_helper",
+ "tls_properties_helper",
+ "ulp",
+ "vec_test",
+ "yuvconstants",
+ "yuvconvert",
+ "zipalign_tests",
+ // "zlib_tests",
+
+ // cc_test_library
+ "clang_diagnostic_tests",
+ "exec_linker_helper_lib",
+ "fortify_disabled_for_tidy",
+ "ld_config_test_helper_lib1",
+ "ld_config_test_helper_lib2",
+ "ld_config_test_helper_lib3",
+ "ld_preload_test_helper_lib1",
+ "ld_preload_test_helper_lib2",
+ "libBionicElfTlsLoaderTests",
+ "libBionicElfTlsTests",
+ "libBionicElfTlsTests",
+ "libBionicFramePointerTests",
+ "libBionicFramePointerTests",
+ "libBionicStandardTests",
+ "libBionicStandardTests",
+ "libBionicTests",
+ "libart-broken",
+ "libatest_simple_zip",
+ "libcfi-test",
+ "libcfi-test-bad",
+ "libcrash_test",
+ // "libcrypto_fuzz_unsafe",
+ "libdl_preempt_test_1",
+ "libdl_preempt_test_2",
+ "libdl_test_df_1_global",
+ "libdlext_test",
+ "libdlext_test_different_soname",
+ "libdlext_test_fd",
+ "libdlext_test_norelro",
+ "libdlext_test_recursive",
+ "libdlext_test_zip",
+ "libfortify1-new-tests-clang",
+ "libfortify1-new-tests-clang",
+ "libfortify1-tests-clang",
+ "libfortify1-tests-clang",
+ "libfortify2-new-tests-clang",
+ "libfortify2-new-tests-clang",
+ "libfortify2-tests-clang",
+ "libfortify2-tests-clang",
+ "libgnu-hash-table-library",
+ "libicutest_static",
+ "liblinker_reloc_bench_000",
+ "liblinker_reloc_bench_001",
+ "liblinker_reloc_bench_002",
+ "liblinker_reloc_bench_003",
+ "liblinker_reloc_bench_004",
+ "liblinker_reloc_bench_005",
+ "liblinker_reloc_bench_006",
+ "liblinker_reloc_bench_007",
+ "liblinker_reloc_bench_008",
+ "liblinker_reloc_bench_009",
+ "liblinker_reloc_bench_010",
+ "liblinker_reloc_bench_011",
+ "liblinker_reloc_bench_012",
+ "liblinker_reloc_bench_013",
+ "liblinker_reloc_bench_014",
+ "liblinker_reloc_bench_015",
+ "liblinker_reloc_bench_016",
+ "liblinker_reloc_bench_017",
+ "liblinker_reloc_bench_018",
+ "liblinker_reloc_bench_019",
+ "liblinker_reloc_bench_020",
+ "liblinker_reloc_bench_021",
+ "liblinker_reloc_bench_022",
+ "liblinker_reloc_bench_023",
+ "liblinker_reloc_bench_024",
+ "liblinker_reloc_bench_025",
+ "liblinker_reloc_bench_026",
+ "liblinker_reloc_bench_027",
+ "liblinker_reloc_bench_028",
+ "liblinker_reloc_bench_029",
+ "liblinker_reloc_bench_030",
+ "liblinker_reloc_bench_031",
+ "liblinker_reloc_bench_032",
+ "liblinker_reloc_bench_033",
+ "liblinker_reloc_bench_034",
+ "liblinker_reloc_bench_035",
+ "liblinker_reloc_bench_036",
+ "liblinker_reloc_bench_037",
+ "liblinker_reloc_bench_038",
+ "liblinker_reloc_bench_039",
+ "liblinker_reloc_bench_040",
+ "liblinker_reloc_bench_041",
+ "liblinker_reloc_bench_042",
+ "liblinker_reloc_bench_043",
+ "liblinker_reloc_bench_044",
+ "liblinker_reloc_bench_045",
+ "liblinker_reloc_bench_046",
+ "liblinker_reloc_bench_047",
+ "liblinker_reloc_bench_048",
+ "liblinker_reloc_bench_049",
+ "liblinker_reloc_bench_050",
+ "liblinker_reloc_bench_051",
+ "liblinker_reloc_bench_052",
+ "liblinker_reloc_bench_053",
+ "liblinker_reloc_bench_054",
+ "liblinker_reloc_bench_055",
+ "liblinker_reloc_bench_056",
+ "liblinker_reloc_bench_057",
+ "liblinker_reloc_bench_058",
+ "liblinker_reloc_bench_059",
+ "liblinker_reloc_bench_060",
+ "liblinker_reloc_bench_061",
+ "liblinker_reloc_bench_062",
+ "liblinker_reloc_bench_063",
+ "liblinker_reloc_bench_064",
+ "liblinker_reloc_bench_065",
+ "liblinker_reloc_bench_066",
+ "liblinker_reloc_bench_067",
+ "liblinker_reloc_bench_068",
+ "liblinker_reloc_bench_069",
+ "liblinker_reloc_bench_070",
+ "liblinker_reloc_bench_071",
+ "liblinker_reloc_bench_072",
+ "liblinker_reloc_bench_073",
+ "liblinker_reloc_bench_074",
+ "liblinker_reloc_bench_075",
+ "liblinker_reloc_bench_076",
+ "liblinker_reloc_bench_077",
+ "liblinker_reloc_bench_078",
+ "liblinker_reloc_bench_079",
+ "liblinker_reloc_bench_080",
+ "liblinker_reloc_bench_081",
+ "liblinker_reloc_bench_082",
+ "liblinker_reloc_bench_083",
+ "liblinker_reloc_bench_084",
+ "liblinker_reloc_bench_085",
+ "liblinker_reloc_bench_086",
+ "liblinker_reloc_bench_087",
+ "liblinker_reloc_bench_088",
+ "liblinker_reloc_bench_089",
+ "liblinker_reloc_bench_090",
+ "liblinker_reloc_bench_091",
+ "liblinker_reloc_bench_092",
+ "liblinker_reloc_bench_093",
+ "liblinker_reloc_bench_094",
+ "liblinker_reloc_bench_095",
+ "liblinker_reloc_bench_096",
+ "liblinker_reloc_bench_097",
+ "liblinker_reloc_bench_098",
+ "liblinker_reloc_bench_099",
+ "liblinker_reloc_bench_100",
+ "liblinker_reloc_bench_101",
+ "liblinker_reloc_bench_102",
+ "liblinker_reloc_bench_103",
+ "liblinker_reloc_bench_104",
+ "liblinker_reloc_bench_105",
+ "liblinker_reloc_bench_106",
+ "liblinker_reloc_bench_107",
+ "liblinker_reloc_bench_108",
+ "liblinker_reloc_bench_109",
+ "liblinker_reloc_bench_110",
+ "liblinker_reloc_bench_111",
+ "liblinker_reloc_bench_112",
+ "liblinker_reloc_bench_113",
+ "liblinker_reloc_bench_114",
+ "liblinker_reloc_bench_115",
+ "liblinker_reloc_bench_116",
+ "liblinker_reloc_bench_117",
+ "liblinker_reloc_bench_118",
+ "liblinker_reloc_bench_119",
+ "liblinker_reloc_bench_120",
+ "liblinker_reloc_bench_121",
+ "liblinker_reloc_bench_122",
+ "liblinker_reloc_bench_123",
+ "liblinker_reloc_bench_124",
+ "liblinker_reloc_bench_125",
+ "liblinker_reloc_bench_126",
+ "liblinker_reloc_bench_127",
+ "liblinker_reloc_bench_128",
+ "liblinker_reloc_bench_129",
+ "liblinker_reloc_bench_130",
+ "liblinker_reloc_bench_131",
+ "liblinker_reloc_bench_132",
+ "liblinker_reloc_bench_133",
+ "liblinker_reloc_bench_134",
+ "liblinker_reloc_bench_135",
+ "liblinker_reloc_bench_136",
+ "liblinker_reloc_bench_137",
+ "liblinker_reloc_bench_138",
+ "liblinker_reloc_bench_139",
+ "liblinker_reloc_bench_140",
+ "liblinker_reloc_bench_141",
+ "liblinker_reloc_bench_142",
+ "liblinker_reloc_bench_143",
+ "liblinker_reloc_bench_144",
+ "liblinker_reloc_bench_145",
+ "liblinker_reloc_bench_146",
+ "liblinker_reloc_bench_147",
+ "liblinker_reloc_bench_148",
+ "liblinker_reloc_bench_149",
+ "liblinker_reloc_bench_150",
+ "liblinker_reloc_bench_151",
+ "liblinker_reloc_bench_152",
+ "liblinker_reloc_bench_153",
+ "liblinker_reloc_bench_154",
+ "liblinker_reloc_bench_155",
+ "liblinker_reloc_bench_156",
+ "liblinker_reloc_bench_157",
+ "liblinker_reloc_bench_158",
+ "liblinker_reloc_bench_159",
+ "liblinker_reloc_bench_160",
+ "liblinker_reloc_bench_161",
+ "liblinker_reloc_bench_162",
+ "liblinker_reloc_bench_163",
+ "liblinker_reloc_bench_164",
+ "liblinker_reloc_bench_165",
+ "liblinker_reloc_bench_166",
+ "liblinker_reloc_bench_167",
+ "liblinker_reloc_bench_168",
+ "libns_hidden_child_app",
+ "libns_hidden_child_global",
+ "libns_hidden_child_internal",
+ "libns_hidden_child_public",
+ "libnstest_dlopened",
+ "libnstest_ns_a_public1",
+ "libnstest_ns_a_public1_internal",
+ "libnstest_ns_b_public2",
+ "libnstest_ns_b_public3",
+ "libnstest_private",
+ "libnstest_private_external",
+ "libnstest_public",
+ "libnstest_public_internal",
+ "libnstest_root",
+ "libnstest_root_not_isolated",
+ "librelocations-ANDROID_REL",
+ "librelocations-ANDROID_RELR",
+ "librelocations-RELR",
+ "librelocations-fat",
+ "libsegment_gap_inner",
+ "libsegment_gap_outer",
+ // "libssl_fuzz_unsafe",
+ "libstatssocket_private",
+ "libsysv-hash-table-library",
+ "libtest_atexit",
+ "libtest_check_order_dlsym",
+ "libtest_check_order_dlsym_1_left",
+ "libtest_check_order_dlsym_2_right",
+ "libtest_check_order_dlsym_3_c",
+ "libtest_check_order_dlsym_a",
+ "libtest_check_order_dlsym_b",
+ "libtest_check_order_dlsym_d",
+ "libtest_check_order_reloc_root",
+ "libtest_check_order_reloc_root_1",
+ "libtest_check_order_reloc_root_2",
+ "libtest_check_order_reloc_siblings",
+ "libtest_check_order_reloc_siblings_1",
+ "libtest_check_order_reloc_siblings_2",
+ "libtest_check_order_reloc_siblings_3",
+ "libtest_check_order_reloc_siblings_a",
+ "libtest_check_order_reloc_siblings_b",
+ "libtest_check_order_reloc_siblings_c",
+ "libtest_check_order_reloc_siblings_c_1",
+ "libtest_check_order_reloc_siblings_c_2",
+ "libtest_check_order_reloc_siblings_d",
+ "libtest_check_order_reloc_siblings_e",
+ "libtest_check_order_reloc_siblings_f",
+ "libtest_check_rtld_next_from_library",
+ "libtest_dlopen_df_1_global",
+ "libtest_dlopen_from_ctor",
+ "libtest_dlopen_from_ctor_main",
+ "libtest_dlopen_weak_undefined_func",
+ "libtest_dlsym_df_1_global",
+ "libtest_dlsym_from_this",
+ "libtest_dlsym_from_this_child",
+ "libtest_dlsym_from_this_grandchild",
+ "libtest_dlsym_weak_func",
+ "libtest_dt_runpath_a",
+ "libtest_dt_runpath_b",
+ "libtest_dt_runpath_c",
+ "libtest_dt_runpath_d",
+ "libtest_dt_runpath_d_zip",
+ "libtest_dt_runpath_x",
+ "libtest_dt_runpath_y",
+ "libtest_elftls_dynamic",
+ "libtest_elftls_dynamic_filler_1",
+ "libtest_elftls_dynamic_filler_2",
+ "libtest_elftls_dynamic_filler_3",
+ "libtest_elftls_shared_var",
+ "libtest_elftls_shared_var_ie",
+ "libtest_elftls_tprel",
+ "libtest_empty",
+ "libtest_ifunc",
+ "libtest_ifunc_variable",
+ "libtest_ifunc_variable_impl",
+ "libtest_indirect_thread_local_dtor",
+ "libtest_init_fini_order_child",
+ "libtest_init_fini_order_grand_child",
+ "libtest_init_fini_order_root",
+ "libtest_init_fini_order_root2",
+ "libtest_missing_symbol",
+ "libtest_missing_symbol_child_private",
+ "libtest_missing_symbol_child_public",
+ "libtest_missing_symbol_root",
+ "libtest_nodelete_1",
+ "libtest_nodelete_2",
+ "libtest_nodelete_dt_flags_1",
+ "libtest_pthread_atfork",
+ "libtest_relo_check_dt_needed_order",
+ "libtest_relo_check_dt_needed_order_1",
+ "libtest_relo_check_dt_needed_order_2",
+ "libtest_simple",
+ "libtest_thread_local_dtor",
+ "libtest_thread_local_dtor2",
+ "libtest_two_parents_child",
+ "libtest_two_parents_parent1",
+ "libtest_two_parents_parent2",
+ "libtest_versioned_lib",
+ "libtest_versioned_libv1",
+ "libtest_versioned_libv2",
+ "libtest_versioned_otherlib",
+ "libtest_versioned_otherlib_empty",
+ "libtest_versioned_uselibv1",
+ "libtest_versioned_uselibv2",
+ "libtest_versioned_uselibv2_other",
+ "libtest_versioned_uselibv3_other",
+ "libtest_with_dependency",
+ "libtest_with_dependency_loop",
+ "libtest_with_dependency_loop_a",
+ "libtest_with_dependency_loop_b",
+ "libtest_with_dependency_loop_b_tmp",
+ "libtest_with_dependency_loop_c",
+ "libtestshared",
}
Bp2buildCcLibraryStaticOnlyList = []string{}
diff --git a/bp2build/Android.bp b/bp2build/Android.bp
index cb25627..da90f30 100644
--- a/bp2build/Android.bp
+++ b/bp2build/Android.bp
@@ -51,6 +51,7 @@
"cc_prebuilt_library_conversion_test.go",
"cc_prebuilt_library_shared_test.go",
"cc_prebuilt_library_static_test.go",
+ "cc_test_conversion_test.go",
"cc_yasm_conversion_test.go",
"conversion_test.go",
"filegroup_conversion_test.go",
diff --git a/bp2build/cc_test_conversion_test.go b/bp2build/cc_test_conversion_test.go
new file mode 100644
index 0000000..9b7748f
--- /dev/null
+++ b/bp2build/cc_test_conversion_test.go
@@ -0,0 +1,150 @@
+// Copyright 2022 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package bp2build
+
+import (
+ "fmt"
+ "testing"
+
+ "android/soong/android"
+ "android/soong/cc"
+ "android/soong/genrule"
+)
+
+type ccTestBp2buildTestCase struct {
+ description string
+ blueprint string
+ targets []testBazelTarget
+}
+
+func registerCcTestModuleTypes(ctx android.RegistrationContext) {
+ cc.RegisterCCBuildComponents(ctx)
+ ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
+ ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
+ ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
+ ctx.RegisterModuleType("cc_test_library", cc.TestLibraryFactory)
+ ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
+}
+
+func runCcTestTestCase(t *testing.T, testCase ccTestBp2buildTestCase) {
+ t.Helper()
+ moduleTypeUnderTest := "cc_test"
+
+ description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description)
+ t.Run(description, func(t *testing.T) {
+ t.Helper()
+ RunBp2BuildTestCase(t, registerCcTestModuleTypes, Bp2buildTestCase{
+ ExpectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.HostAndDeviceSupported),
+ ModuleTypeUnderTest: moduleTypeUnderTest,
+ ModuleTypeUnderTestFactory: cc.TestFactory,
+ Description: description,
+ Blueprint: testCase.blueprint,
+ })
+ })
+}
+
+func TestBasicCcTest(t *testing.T) {
+ runCcTestTestCase(t, ccTestBp2buildTestCase{
+ description: "basic cc_test with commonly used attributes",
+ blueprint: `
+cc_test {
+ name: "mytest",
+ host_supported: true,
+ srcs: ["test.cpp"],
+ target: {
+ android: {
+ srcs: ["android.cpp"],
+ shared_libs: ["foolib"],
+ },
+ linux: {
+ srcs: ["linux.cpp"],
+ },
+ host: {
+ static_libs: ["hostlib"],
+ },
+ },
+ data: [":data_mod", "file.txt"],
+ data_bins: [":cc_bin"],
+ data_libs: [":cc_lib"],
+ cflags: ["-Wall"],
+}
+` + simpleModuleDoNotConvertBp2build("cc_library", "foolib") +
+ simpleModuleDoNotConvertBp2build("cc_library_static", "hostlib") +
+ simpleModuleDoNotConvertBp2build("genrule", "data_mod") +
+ simpleModuleDoNotConvertBp2build("cc_binary", "cc_bin") +
+ simpleModuleDoNotConvertBp2build("cc_test_library", "cc_lib"),
+ targets: []testBazelTarget{
+ {"cc_test", "mytest", AttrNameToString{
+ "copts": `["-Wall"]`,
+ "data": `[
+ ":data_mod",
+ "file.txt",
+ ":cc_bin",
+ ":cc_lib",
+ ]`,
+ "deps": `select({
+ "//build/bazel/platforms/os:darwin": [":hostlib"],
+ "//build/bazel/platforms/os:linux": [":hostlib"],
+ "//build/bazel/platforms/os:linux_bionic": [":hostlib"],
+ "//build/bazel/platforms/os:linux_musl": [":hostlib"],
+ "//build/bazel/platforms/os:windows": [":hostlib"],
+ "//conditions:default": [],
+ })`,
+ "gtest": "True",
+ "isolated": "True",
+ "local_includes": `["."]`,
+ "dynamic_deps": `select({
+ "//build/bazel/platforms/os:android": [":foolib"],
+ "//conditions:default": [],
+ })`,
+ "srcs": `["test.cpp"] + select({
+ "//build/bazel/platforms/os:android": [
+ "linux.cpp",
+ "android.cpp",
+ ],
+ "//build/bazel/platforms/os:linux": ["linux.cpp"],
+ "//build/bazel/platforms/os:linux_bionic": ["linux.cpp"],
+ "//build/bazel/platforms/os:linux_musl": ["linux.cpp"],
+ "//conditions:default": [],
+ })`,
+ },
+ },
+ },
+ })
+}
+
+func TestBasicCcTestGtestIsolatedDisabled(t *testing.T) {
+ runCcTestTestCase(t, ccTestBp2buildTestCase{
+ description: "cc test with disabled gtest and isolated props",
+ blueprint: `
+cc_test {
+ name: "mytest",
+ host_supported: true,
+ srcs: ["test.cpp"],
+ gtest: false,
+ isolated: false,
+}
+`,
+ targets: []testBazelTarget{
+ {"cc_test", "mytest", AttrNameToString{
+ "gtest": "False",
+ "isolated": "False",
+ "local_includes": `["."]`,
+ "srcs": `["test.cpp"]`,
+ },
+ },
+ },
+ })
+}
diff --git a/cc/binary.go b/cc/binary.go
index 849aafa..3351fd7 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -18,6 +18,7 @@
"path/filepath"
"android/soong/bazel/cquery"
+
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -591,7 +592,7 @@
handler.module.linker.(*binaryDecorator).unstrippedOutputFile = outputFilePath
}
-func binaryBp2build(ctx android.TopDownMutatorContext, m *Module, typ string) {
+func binaryBp2buildAttrs(ctx android.TopDownMutatorContext, m *Module) binaryAttributes {
baseAttrs := bp2BuildParseBaseProps(ctx, m)
binaryLinkerAttrs := bp2buildBinaryLinkerProps(ctx, m)
@@ -601,7 +602,7 @@
baseAttrs.implementationDeps.Add(baseAttrs.protoDependency)
}
- attrs := &binaryAttributes{
+ attrs := binaryAttributes{
binaryLinkerAttrs: binaryLinkerAttrs,
Srcs: baseAttrs.srcs,
@@ -644,12 +645,19 @@
sdkAttributes: bp2BuildParseSdkAttributes(m),
}
+ return attrs
+}
+
+func binaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
+ // shared with cc_test
+ binaryAttrs := binaryBp2buildAttrs(ctx, m)
+
ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
Rule_class: "cc_binary",
Bzl_load_location: "//build/bazel/rules/cc:cc_binary.bzl",
},
android.CommonAttributes{Name: m.Name()},
- attrs)
+ &binaryAttrs)
}
// binaryAttributes contains Bazel attributes corresponding to a cc binary
diff --git a/cc/cc.go b/cc/cc.go
index cded946..0ed9bb6 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -3376,6 +3376,15 @@
return false
}
+func (c *Module) testLibrary() bool {
+ if test, ok := c.linker.(interface {
+ testLibrary() bool
+ }); ok {
+ return test.testLibrary()
+ }
+ return false
+}
+
func (c *Module) benchmarkBinary() bool {
if b, ok := c.linker.(interface {
benchmarkBinary() bool
@@ -3654,13 +3663,25 @@
staticLibrary
sharedLibrary
headerLibrary
+ testBin // testBinary already declared
)
func (c *Module) typ() moduleType {
- if c.Binary() {
+ if c.testBinary() {
+ // testBinary is also a binary, so this comes before the c.Binary()
+ // conditional. A testBinary has additional implicit dependencies and
+ // other test-only semantics.
+ return testBin
+ } else if c.Binary() {
return binary
} else if c.Object() {
return object
+ } else if c.testLibrary() {
+ // TODO(b/244431896) properly convert cc_test_library to its own macro. This
+ // will let them add implicit compile deps on gtest, for example.
+ //
+ // For now, treat them as regular shared libraries.
+ return sharedLibrary
} else if c.CcLibrary() {
static := false
shared := false
@@ -3689,7 +3710,11 @@
switch c.typ() {
case binary:
if !prebuilt {
- binaryBp2build(ctx, c, ctx.ModuleType())
+ binaryBp2build(ctx, c)
+ }
+ case testBin:
+ if !prebuilt {
+ testBinaryBp2build(ctx, c)
}
case object:
if !prebuilt {
diff --git a/cc/test.go b/cc/test.go
index f5abc45..3e85e2d 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -22,6 +22,7 @@
"github.com/google/blueprint/proptools"
"android/soong/android"
+ "android/soong/bazel"
"android/soong/tradefed"
)
@@ -133,7 +134,7 @@
// specific functionality on a device. The executable binary gets an implicit
// static_libs dependency on libgtests unless the gtest flag is set to false.
func TestFactory() android.Module {
- module := NewTest(android.HostAndDeviceSupported)
+ module := NewTest(android.HostAndDeviceSupported, true)
return module.Init()
}
@@ -156,7 +157,7 @@
// cc_test_host compiles a test host binary.
func TestHostFactory() android.Module {
- module := NewTest(android.HostSupported)
+ module := NewTest(android.HostSupported, true)
return module.Init()
}
@@ -204,6 +205,10 @@
test.binaryDecorator.Properties.Stem = StringPtr("")
}
+func (test *testBinary) testBinary() bool {
+ return true
+}
+
var _ testPerSrc = (*testBinary)(nil)
func TestPerSrcMutator(mctx android.BottomUpMutatorContext) {
@@ -257,16 +262,10 @@
}
func (test *testDecorator) isolated(ctx BaseModuleContext) bool {
- if !ctx.Windows() {
- return BoolDefault(test.LinkerProperties.Isolated, false)
- }
return BoolDefault(test.LinkerProperties.Isolated, false)
}
-func (test *testDecorator) testBinary() bool {
- return true
-}
-
+// NOTE: Keep this in sync with cc/cc_test.bzl#gtest_copts
func (test *testDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
if !test.gtest() {
return flags
@@ -480,8 +479,8 @@
test.binaryDecorator.baseInstaller.install(ctx, file)
}
-func NewTest(hod android.HostOrDeviceSupported) *Module {
- module, binary := newBinary(hod, false)
+func NewTest(hod android.HostOrDeviceSupported, bazelable bool) *Module {
+ module, binary := newBinary(hod, bazelable)
module.multilib = android.MultilibBoth
binary.baseInstaller = NewTestInstaller()
@@ -504,6 +503,10 @@
*libraryDecorator
}
+func (test *testLibrary) testLibrary() bool {
+ return true
+}
+
func (test *testLibrary) linkerProps() []interface{} {
var props []interface{}
props = append(props, test.testDecorator.linkerProps()...)
@@ -543,6 +546,7 @@
}
module.linker = test
module.installer = test
+ module.bazelable = true
return module
}
@@ -632,3 +636,56 @@
module.installer = benchmark
return module
}
+
+// binaryAttributes contains Bazel attributes corresponding to a cc test
+type testBinaryAttributes struct {
+ binaryAttributes
+
+ Gtest bool
+ Isolated bool
+ Data bazel.LabelListAttribute
+}
+
+// testBinaryBp2build is the bp2build converter for cc_test modules. A cc_test's
+// dependency graph and compilation/linking steps are functionally similar to a
+// cc_binary, but has additional dependencies on test deps like gtest, and
+// produces additional runfiles like XML plans for Tradefed orchestration
+//
+// TODO(b/244432609): handle `isolated` property.
+// TODO(b/244432134): handle custom runpaths for tests that assume runfile layouts not
+// default to bazel. (see linkerInit function)
+// TODO(b/244432500): handle test.testConfig generation (see install function)
+func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
+ var testBinaryAttrs testBinaryAttributes
+ testBinaryAttrs.binaryAttributes = binaryBp2buildAttrs(ctx, m)
+
+ testBinaryProps := m.GetArchVariantProperties(ctx, &TestBinaryProperties{})
+ for axis, configToProps := range testBinaryProps {
+ for config, props := range configToProps {
+ if p, ok := props.(*TestBinaryProperties); ok {
+ // Combine data, data_bins and data_libs into a single 'data' attribute.
+ var combinedData bazel.LabelList
+ combinedData.Append(android.BazelLabelForModuleSrc(ctx, p.Data))
+ combinedData.Append(android.BazelLabelForModuleDeps(ctx, p.Data_bins))
+ combinedData.Append(android.BazelLabelForModuleDeps(ctx, p.Data_libs))
+ testBinaryAttrs.Data.SetSelectValue(axis, config, combinedData)
+ }
+ }
+ }
+
+ for _, propIntf := range m.GetProperties() {
+ if testLinkerProps, ok := propIntf.(*TestLinkerProperties); ok {
+ testBinaryAttrs.Gtest = proptools.BoolDefault(testLinkerProps.Gtest, true)
+ testBinaryAttrs.Isolated = proptools.BoolDefault(testLinkerProps.Isolated, true)
+ break
+ }
+ }
+
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "cc_test",
+ Bzl_load_location: "//build/bazel/rules/cc:cc_test.bzl",
+ },
+ android.CommonAttributes{Name: m.Name()},
+ &testBinaryAttrs)
+}