James Lemieux | 3165e86 | 2017-12-01 13:23:47 -0800 | [diff] [blame] | 1 | LOCAL_MODULE_CLASS := FAKE |
| 2 | LOCAL_IS_HOST_MODULE := true |
| 3 | LOCAL_DONT_CHECK_MODULE := true |
| 4 | LOCAL_UNINSTALLABLE_MODULE := true |
| 5 | LOCAL_BUILT_MODULE_STEM := test.fake |
| 6 | |
| 7 | # Construct the runtime classpath. |
| 8 | classpath_jars := $(call java-lib-files, $(test_runtime_libraries), HOST) |
| 9 | |
| 10 | # Construct the list of test classes from the source file names. |
| 11 | test_source_files := $(call find-files-in-subdirs, $(test_source_directory), "*Test.java", .) |
| 12 | # Filter out tests that will not pass running under make. |
James Lemieux | 0ea9560 | 2018-10-10 12:57:30 -0700 | [diff] [blame] | 13 | test_source_files := $(filter-out org/robolectric/shadows/SQLiteCursorTest.java, $(test_source_files)) |
James Lemieux | 3165e86 | 2017-12-01 13:23:47 -0800 | [diff] [blame] | 14 | |
James Lemieux | 81a053c | 2018-03-14 17:31:33 -0700 | [diff] [blame] | 15 | # Build the command that honors the test class filter, if any. |
Dan Willemsen | 481836e | 2020-01-21 14:37:29 -0800 | [diff] [blame] | 16 | test_filter_command := $(if $(ROBOTEST_FILTER),grep -E "$(ROBOTEST_FILTER)",) |
James Lemieux | 81a053c | 2018-03-14 17:31:33 -0700 | [diff] [blame] | 17 | |
James Lemieux | 3165e86 | 2017-12-01 13:23:47 -0800 | [diff] [blame] | 18 | # Convert the test source file paths into package names by removing ".java" extension and replacing "/" with "." |
Dan Willemsen | 481836e | 2020-01-21 14:37:29 -0800 | [diff] [blame] | 19 | test_class_names := $(sort $(subst /,., $(basename $(test_source_files)))) |
James Lemieux | 3165e86 | 2017-12-01 13:23:47 -0800 | [diff] [blame] | 20 | # Remove whitespace and sort the tests in alphabetical order. |
Dan Willemsen | 481836e | 2020-01-21 14:37:29 -0800 | [diff] [blame] | 21 | ifdef test_filter_command |
| 22 | test_class_names := $(sort $(shell echo '$(test_class_names)' | tr ' ' '\n' | $(test_filter_command))) |
| 23 | endif |
James Lemieux | 3165e86 | 2017-12-01 13:23:47 -0800 | [diff] [blame] | 24 | |
| 25 | include $(BUILD_SYSTEM)/base_rules.mk |
| 26 | |
| 27 | # Define rules that copy test resource files to the intermediates folder. |
| 28 | intermediates := $(call local-intermediates-dir) |
| 29 | copy_test_resource_files := |
| 30 | ifdef test_resources_directory |
| 31 | test_resources_target_path := $(intermediates)/src/test/resources |
| 32 | test_resource_files := $(call find-files-in-subdirs, $(test_resources_directory), "*" -and -type f, .) |
| 33 | copy_test_resource_file_pairs := $(foreach j, $(test_resource_files), $(test_resources_directory)/$(j):$(test_resources_target_path)/$(j)) |
| 34 | copy_test_resource_files := $(call copy-many-files, $(copy_test_resource_file_pairs)) |
| 35 | endif |
| 36 | |
| 37 | # Define rules that copy android-all jars to the intermediates folder. |
Anton Hansson | 55539aa | 2020-07-20 18:32:22 +0100 | [diff] [blame] | 38 | local_android_all_source_jar := $(call java-lib-files,robolectric-host-android_all,HOST) |
James Lemieux | 3165e86 | 2017-12-01 13:23:47 -0800 | [diff] [blame] | 39 | android_all_source_dir := prebuilts/misc/common/robolectric/android-all |
| 40 | android_all_target_dir := $(intermediates)/android-all |
| 41 | copy_android_all_jar_pairs := \ |
| 42 | $(android_all_source_dir)/android-all-4.1.2_r1-robolectric-r1.jar:$(android_all_target_dir)/android-all-4.1.2_r1-robolectric-r1.jar \ |
| 43 | $(android_all_source_dir)/android-all-4.2.2_r1.2-robolectric-r1.jar:$(android_all_target_dir)/android-all-4.2.2_r1.2-robolectric-r1.jar \ |
| 44 | $(android_all_source_dir)/android-all-4.3_r2-robolectric-r1.jar:$(android_all_target_dir)/android-all-4.3_r2-robolectric-r1.jar \ |
| 45 | $(android_all_source_dir)/android-all-4.4_r1-robolectric-r2.jar:$(android_all_target_dir)/android-all-4.4_r1-robolectric-r2.jar \ |
| 46 | $(android_all_source_dir)/android-all-5.0.2_r3-robolectric-r0.jar:$(android_all_target_dir)/android-all-5.0.2_r3-robolectric-r0.jar \ |
| 47 | $(android_all_source_dir)/android-all-5.1.1_r9-robolectric-r2.jar:$(android_all_target_dir)/android-all-5.1.1_r9-robolectric-r2.jar \ |
| 48 | $(android_all_source_dir)/android-all-6.0.1_r3-robolectric-r1.jar:$(android_all_target_dir)/android-all-6.0.1_r3-robolectric-r1.jar \ |
| 49 | $(android_all_source_dir)/android-all-7.0.0_r1-robolectric-r1.jar:$(android_all_target_dir)/android-all-7.0.0_r1-robolectric-r1.jar \ |
| 50 | $(android_all_source_dir)/android-all-7.1.0_r7-robolectric-r1.jar:$(android_all_target_dir)/android-all-7.1.0_r7-robolectric-r1.jar \ |
| 51 | $(android_all_source_dir)/android-all-8.0.0_r4-robolectric-r1.jar:$(android_all_target_dir)/android-all-8.0.0_r4-robolectric-r1.jar \ |
James Lemieux | 0ea9560 | 2018-10-10 12:57:30 -0700 | [diff] [blame] | 52 | $(android_all_source_dir)/android-all-8.1.0-robolectric-4611349.jar:$(android_all_target_dir)/android-all-8.1.0-robolectric-4611349.jar \ |
| 53 | $(android_all_source_dir)/android-all-9-robolectric-4913185-2.jar:$(android_all_target_dir)/android-all-9-robolectric-4913185-2.jar \ |
Annie Meng | 589f9dd | 2019-07-03 16:10:39 +0100 | [diff] [blame] | 54 | $(android_all_source_dir)/android-all-9plus-robolectric-5616371.jar:$(android_all_target_dir)/android-all-9plus-robolectric-5616371.jar \ |
Victor Chang | b84738f | 2020-07-03 16:35:02 +0100 | [diff] [blame] | 55 | $(android_all_source_dir)/android-all-R-beta2-robolectric-6625208.jar:$(android_all_target_dir)/android-all-R-beta2-robolectric-6625208.jar \ |
Colin Cross | c2d0082 | 2021-07-16 12:03:33 -0700 | [diff] [blame] | 56 | $(android_all_source_dir)/android-all-S-beta3-robolectric-7541949.jar:$(android_all_target_dir)/android-all-S-beta3-robolectric-7541949.jar \ |
Joseph Murphy | 9572ee8 | 2021-07-20 13:42:45 -0700 | [diff] [blame] | 57 | $(local_android_all_source_jar):$(android_all_target_dir)/android-all-current-robolectric-r0.jar |
James Lemieux | 3165e86 | 2017-12-01 13:23:47 -0800 | [diff] [blame] | 58 | copy_android_all_jars := $(call copy-many-files, $(copy_android_all_jar_pairs)) |
| 59 | |
James Lemieux | b0d9a6c | 2018-01-23 16:17:17 -0800 | [diff] [blame] | 60 | # If debugging the tests was requested, set up the JVM parameters to enable it. |
| 61 | debug_test_args := |
James Lemieux | 81a053c | 2018-03-14 17:31:33 -0700 | [diff] [blame] | 62 | ifdef DEBUG_ROBOLECTRIC |
James Lemieux | b0d9a6c | 2018-01-23 16:17:17 -0800 | [diff] [blame] | 63 | # The arguments to the JVM needed to debug the tests. |
| 64 | # - server: wait for connection rather than connecting to a debugger |
| 65 | # - transport: how to accept debugger connections (sockets) |
| 66 | # - address: the host and port on which to accept debugger connections |
James Lemieux | 0ea9560 | 2018-10-10 12:57:30 -0700 | [diff] [blame] | 67 | # - suspend: do not execute any code until the debugger connects |
James Lemieux | b0d9a6c | 2018-01-23 16:17:17 -0800 | [diff] [blame] | 68 | debug_test_args := -Xdebug -agentlib:jdwp=server=y,transport=dt_socket,address=localhost:5005,suspend=y |
| 69 | endif |
| 70 | |
James Lemieux | 3165e86 | 2017-12-01 13:23:47 -0800 | [diff] [blame] | 71 | # Snapshot the variables so they cannot be polluted before the module is built. |
| 72 | $(LOCAL_BUILT_MODULE): private_java := $(JAVA) |
James Lemieux | b0d9a6c | 2018-01-23 16:17:17 -0800 | [diff] [blame] | 73 | $(LOCAL_BUILT_MODULE): private_debug_test_args := $(debug_test_args) |
| 74 | $(LOCAL_BUILT_MODULE): private_test_base_dir := $(intermediates) |
James Lemieux | 3165e86 | 2017-12-01 13:23:47 -0800 | [diff] [blame] | 75 | $(LOCAL_BUILT_MODULE): private_test_class_names := $(test_class_names) |
| 76 | $(LOCAL_BUILT_MODULE): private_host_jdk_tools_jar := $(HOST_JDK_TOOLS_JAR) |
| 77 | $(LOCAL_BUILT_MODULE): private_android_all_dir := $(android_all_target_dir) |
| 78 | $(LOCAL_BUILT_MODULE): private_classpath_jars := $(call normalize-path-list, $(classpath_jars)) |
| 79 | |
Dan Willemsen | 31c4a3a | 2018-06-19 15:55:05 -0700 | [diff] [blame] | 80 | # Always re-run the tests, even if nothing has changed. |
| 81 | # Until the build system has a dedicated "no cache" option, claim to write |
| 82 | # a file that is never produced. |
| 83 | $(LOCAL_BUILT_MODULE): private_nocache := $(LOCAL_BUILT_MODULE).nocache |
| 84 | $(LOCAL_BUILT_MODULE): .KATI_IMPLICIT_OUTPUTS := $(LOCAL_BUILT_MODULE).nocache |
James Lemieux | 3165e86 | 2017-12-01 13:23:47 -0800 | [diff] [blame] | 85 | |
| 86 | # Define the basic recipe for building this module to execute the tests. |
| 87 | $(LOCAL_BUILT_MODULE): $(copy_test_resource_files) $(copy_android_all_jars) $(classpath_jars) |
Dan Willemsen | 31c4a3a | 2018-06-19 15:55:05 -0700 | [diff] [blame] | 88 | $(hide) rm -f "$(private_nocache)" |
James Lemieux | 3165e86 | 2017-12-01 13:23:47 -0800 | [diff] [blame] | 89 | $(hide) $(private_java) \ |
| 90 | -Drobolectric.offline=true \ |
James Lemieux | 0ea9560 | 2018-10-10 12:57:30 -0700 | [diff] [blame] | 91 | -Drobolectric.resourcesMode=binary \ |
James Lemieux | b0d9a6c | 2018-01-23 16:17:17 -0800 | [diff] [blame] | 92 | -Drobolectric-tests.base-dir=$(private_test_base_dir) \ |
James Lemieux | 0ea9560 | 2018-10-10 12:57:30 -0700 | [diff] [blame] | 93 | -Drobolectric.dependency.dir=$(private_android_all_dir) \ |
James Lemieux | b0d9a6c | 2018-01-23 16:17:17 -0800 | [diff] [blame] | 94 | $(private_debug_test_args) \ |
| 95 | -cp $(private_host_jdk_tools_jar):$(private_test_base_dir):$(private_classpath_jars) \ |
James Lemieux | 3165e86 | 2017-12-01 13:23:47 -0800 | [diff] [blame] | 96 | org.junit.runner.JUnitCore \ |
Dan Willemsen | 31c4a3a | 2018-06-19 15:55:05 -0700 | [diff] [blame] | 97 | $(private_test_class_names) |