1LOCAL_MODULE_CLASS := FAKE 2LOCAL_IS_HOST_MODULE := true 3LOCAL_DONT_CHECK_MODULE := true 4LOCAL_UNINSTALLABLE_MODULE := true 5LOCAL_BUILT_MODULE_STEM := test.fake 6 7# Construct the runtime classpath. 8classpath_jars := $(call java-lib-files, $(test_runtime_libraries), HOST) 9 10# Construct the list of test classes from the source file names. 11test_source_files := $(call find-files-in-subdirs, $(test_source_directory), "*Test.java", .) 12# Filter out tests that will not pass running under make. 13test_source_files := $(filter-out org/robolectric/shadows/SQLiteCursorTest.java, $(test_source_files)) 14 15# Build the command that honors the test class filter, if any. 16test_filter_command := $(if $(ROBOTEST_FILTER),grep -E "$(ROBOTEST_FILTER)",cat) 17 18# Convert the test source file paths into package names by removing ".java" extension and replacing "/" with "." 19test_class_names := $(subst /,., $(basename $(test_source_files))) 20# Remove whitespace and sort the tests in alphabetical order. 21test_class_names := $(sort $(shell echo '$(test_class_names)' | tr ' ' '\n' | $(test_filter_command))) 22 23include $(BUILD_SYSTEM)/base_rules.mk 24 25# Define rules that copy test resource files to the intermediates folder. 26intermediates := $(call local-intermediates-dir) 27copy_test_resource_files := 28ifdef test_resources_directory 29 test_resources_target_path := $(intermediates)/src/test/resources 30 test_resource_files := $(call find-files-in-subdirs, $(test_resources_directory), "*" -and -type f, .) 31 copy_test_resource_file_pairs := $(foreach j, $(test_resource_files), $(test_resources_directory)/$(j):$(test_resources_target_path)/$(j)) 32 copy_test_resource_files := $(call copy-many-files, $(copy_test_resource_file_pairs)) 33endif 34 35# Define rules that copy android-all jars to the intermediates folder. 36local_android_all_source_jar := $(call intermediates-dir-for, JAVA_LIBRARIES, robolectric_android-all-stub, , COMMON)/classes-with-res.jar 37android_all_source_dir := prebuilts/misc/common/robolectric/android-all 38android_all_target_dir := $(intermediates)/android-all 39copy_android_all_jar_pairs := \ 40 $(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 \ 41 $(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 \ 42 $(android_all_source_dir)/android-all-4.3_r2-robolectric-r1.jar:$(android_all_target_dir)/android-all-4.3_r2-robolectric-r1.jar \ 43 $(android_all_source_dir)/android-all-4.4_r1-robolectric-r2.jar:$(android_all_target_dir)/android-all-4.4_r1-robolectric-r2.jar \ 44 $(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 \ 45 $(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 \ 46 $(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 \ 47 $(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 \ 48 $(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 \ 49 $(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 \ 50 $(android_all_source_dir)/android-all-8.1.0-robolectric-4611349.jar:$(android_all_target_dir)/android-all-8.1.0-robolectric-4611349.jar \ 51 $(android_all_source_dir)/android-all-9-robolectric-4913185-2.jar:$(android_all_target_dir)/android-all-9-robolectric-4913185-2.jar \ 52 $(local_android_all_source_jar):$(android_all_target_dir)/android-all-Q-robolectric-r0.jar 53copy_android_all_jars := $(call copy-many-files, $(copy_android_all_jar_pairs)) 54 55# If debugging the tests was requested, set up the JVM parameters to enable it. 56debug_test_args := 57ifdef DEBUG_ROBOLECTRIC 58 # The arguments to the JVM needed to debug the tests. 59 # - server: wait for connection rather than connecting to a debugger 60 # - transport: how to accept debugger connections (sockets) 61 # - address: the host and port on which to accept debugger connections 62 # - suspend: do not execute any code until the debugger connects 63 debug_test_args := -Xdebug -agentlib:jdwp=server=y,transport=dt_socket,address=localhost:5005,suspend=y 64endif 65 66# Snapshot the variables so they cannot be polluted before the module is built. 67$(LOCAL_BUILT_MODULE): private_java := $(JAVA) 68$(LOCAL_BUILT_MODULE): private_debug_test_args := $(debug_test_args) 69$(LOCAL_BUILT_MODULE): private_test_base_dir := $(intermediates) 70$(LOCAL_BUILT_MODULE): private_test_class_names := $(test_class_names) 71$(LOCAL_BUILT_MODULE): private_host_jdk_tools_jar := $(HOST_JDK_TOOLS_JAR) 72$(LOCAL_BUILT_MODULE): private_android_all_dir := $(android_all_target_dir) 73$(LOCAL_BUILT_MODULE): private_classpath_jars := $(call normalize-path-list, $(classpath_jars)) 74 75# Always re-run the tests, even if nothing has changed. 76# Until the build system has a dedicated "no cache" option, claim to write 77# a file that is never produced. 78$(LOCAL_BUILT_MODULE): private_nocache := $(LOCAL_BUILT_MODULE).nocache 79$(LOCAL_BUILT_MODULE): .KATI_IMPLICIT_OUTPUTS := $(LOCAL_BUILT_MODULE).nocache 80 81# Define the basic recipe for building this module to execute the tests. 82$(LOCAL_BUILT_MODULE): $(copy_test_resource_files) $(copy_android_all_jars) $(classpath_jars) 83 $(hide) rm -f "$(private_nocache)" 84 $(hide) $(private_java) \ 85 -Drobolectric.offline=true \ 86 -Drobolectric.resourcesMode=binary \ 87 -Drobolectric-tests.base-dir=$(private_test_base_dir) \ 88 -Drobolectric.dependency.dir=$(private_android_all_dir) \ 89 $(private_debug_test_args) \ 90 -cp $(private_host_jdk_tools_jar):$(private_test_base_dir):$(private_classpath_jars) \ 91 org.junit.runner.JUnitCore \ 92 $(private_test_class_names) 93