1 # Defines a target named $(my_target) for running robolectric tests. 2 3 # Running the tests is done in two stages: we first generate the test output to 4 # $(my_target_output), which is also added to the dist list, and store the 5 # return value of running the tests in $(my_target_retval). After that we 6 # process the output and return value as part of $(my_target). This is needed 7 # to make sure that we can install the test output even if the tests actually 8 # fail. 9 10 # Files in which to store the output and return value of the tests. 11 my_target_output := $(basename $(my_target))-output.txt 12 my_target_retval := $(basename $(my_target))-retval.txt 13 14 # We should always re-run the tests, even if nothing has changed. 15 .PHONY: $(my_target_output) $(my_target_retval) 16 # Private variables. 17 $(my_target_output): \ 18 PRIVATE_MODULE := $(LOCAL_MODULE) 19 $(my_target_output): \ 20 PRIVATE_TESTS := $(my_tests) 21 $(my_target_output): \ 22 PRIVATE_JARS := $(my_jars) 23 $(my_target_output): \ 24 PRIVATE_JAVA_ARGS := $(my_java_args) 25 $(my_target_output): \ 26 PRIVATE_ROBOLECTRIC_PATH := $(my_robolectric_path) 27 $(my_target_output): \ 28 PRIVATE_ROBOLECTRIC_SCRIPT_PATH := $(my_robolectric_script_path) 29 $(my_target_output): \ 30 PRIVATE_TARGET_MESSAGE := $(my_target_message) 31 $(my_target_output): \ 32 PRIVATE_TARGET_OUTPUT := $(my_target_output) 33 $(my_target_output): \ 34 PRIVATE_TARGET_RETVAL := $(my_target_retval) 35 $(my_target_output): \ 36 PRIVATE_TIMEOUT := $(my_timeout) 37 # Runs the Robolectric tests and saves the output and return value. 38 $(my_target_output) $(my_target_retval): \ 39 $(my_jars) 40 $(hide) echo "host Robolectric: $(PRIVATE_MODULE) ($(dir $@))" 41 $(hide) \ 42 PRIVATE_INTERMEDIATES="$(dir $@)" \ 43 PRIVATE_JARS="$(PRIVATE_JARS)" \ 44 PRIVATE_JAVA_ARGS="$(PRIVATE_JAVA_ARGS)" \ 45 PRIVATE_ROBOLECTRIC_PATH="$(PRIVATE_ROBOLECTRIC_PATH)" \ 46 PRIVATE_ROBOLECTRIC_SCRIPT_PATH="$(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)" \ 47 PRIVATE_RUN_INDIVIDUALLY="$(ROBOTEST_RUN_INDIVIDUALLY)" \ 48 PRIVATE_TARGET_MESSAGE="$(PRIVATE_TARGET_MESSAGE)" \ 49 PRIVATE_TIMEOUT="$(PRIVATE_TIMEOUT)" \ 50 PRIVATE_TESTS="$(PRIVATE_TESTS)" \ 51 $(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)/wrapper.sh \ 52 "$(PRIVATE_MODULE)" \ 53 "$(PRIVATE_TARGET_OUTPUT)" \ 54 "$(PRIVATE_TARGET_RETVAL)" \ 55 wrap \ 56 $(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)/robotest.sh 57 58 # This does not actually generate a file. 59 .PHONY: $(my_target) 60 # Private variables. 61 $(my_target): \ 62 PRIVATE_MODULE := $(LOCAL_MODULE) 63 $(my_target): \ 64 PRIVATE_TARGET_OUTPUT := $(my_target_output) 65 $(my_target): \ 66 PRIVATE_TARGET_RETVAL := $(my_target_retval) 67 $(my_target): \ 68 PRIVATE_FAILURE_FATAL := $(my_failure_fatal) 69 $(my_target): \ 70 PRIVATE_ROBOLECTRIC_SCRIPT_PATH := $(my_robolectric_script_path) 71 # Process the output and the return value of the tests. This will fail if the 72 # return value is non-zero. 73 $(my_target): $(my_target_output) 74 $(hide) \ 75 result=0; \ 76 $(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)/wrapper.sh \ 77 "$(PRIVATE_MODULE)" \ 78 "$(PRIVATE_TARGET_OUTPUT)" \ 79 "$(PRIVATE_TARGET_RETVAL)" \ 80 eval \ 81 || result=$$?; \ 82 if [ "$(strip $(PRIVATE_FAILURE_FATAL))" = true ]; then \ 83 exit "$$result"; \ 84 fi 85 86 # Add the output of the tests to the dist list, so that we will include it even 87 # if the tests fail. 88 $(call dist-for-goals, $(my_target), \ 89 $(my_target_output):robotests/$(LOCAL_MODULE)-$(notdir $(my_target_output))) 90 91 # Clean up local variables. 92 my_target_output := 93 my_target_retval := 94