James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 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_xml := $(intermediates)/$(my_filename_stem)-output.xml |
| 12 | my_target_output := $(intermediates)/$(my_filename_stem)-output.txt |
| 13 | my_target_retval := $(intermediates)/$(my_filename_stem)-retval.txt |
| 14 | |
| 15 | # We should always re-run the tests, even if nothing has changed. |
Dan Willemsen | 31c4a3a | 2018-06-19 15:55:05 -0700 | [diff] [blame] | 16 | # So until the build system has a dedicated "no cache" option, claim |
| 17 | # to write a file that is never produced. |
| 18 | my_target_nocache := $(intermediates)/$(my_filename_stem)-nocache |
| 19 | |
James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 20 | # Private variables. |
| 21 | $(my_target_output): PRIVATE_MODULE := $(LOCAL_MODULE) |
| 22 | $(my_target_output): PRIVATE_TESTS := $(my_tests) |
| 23 | $(my_target_output): PRIVATE_JARS := $(my_jars) |
| 24 | $(my_target_output): PRIVATE_JAVA_ARGS := $(my_java_args) |
| 25 | $(my_target_output): PRIVATE_ROBOLECTRIC_PATH := $(my_robolectric_path) |
| 26 | $(my_target_output): PRIVATE_ROBOLECTRIC_SCRIPT_PATH := $(my_robolectric_script_path) |
| 27 | $(my_target_output): PRIVATE_TARGET_MESSAGE := $(my_target_message) |
| 28 | $(my_target_output): PRIVATE_TARGET_OUTPUT := $(my_target_output) |
| 29 | $(my_target_output): PRIVATE_TARGET_RETVAL := $(my_target_retval) |
Dan Willemsen | 31c4a3a | 2018-06-19 15:55:05 -0700 | [diff] [blame] | 30 | $(my_target_output): PRIVATE_TARGET_NOCACHE := $(my_target_nocache) |
James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 31 | $(my_target_output): PRIVATE_TIMEOUT := $(my_timeout) |
| 32 | $(my_target_output): PRIVATE_XML_OUTPUT_FILE := $(my_target_xml) |
Dan Willemsen | 31c4a3a | 2018-06-19 15:55:05 -0700 | [diff] [blame] | 33 | $(my_target_output): .KATI_IMPLICIT_OUTPUTS := $(my_target_xml) $(my_target_retval) $(my_target_nocache) |
James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 34 | # Runs the Robolectric tests and saves the output and return value. |
| 35 | $(my_target_output): $(my_jars) |
| 36 | @echo "host Robolectric: $(PRIVATE_MODULE)" |
| 37 | # Run `touch` to always create the output XML file, so the build doesn't break even if the |
| 38 | # runner failed to create the XML output |
| 39 | $(hide) touch "$(PRIVATE_XML_OUTPUT_FILE)" |
Dan Willemsen | 31c4a3a | 2018-06-19 15:55:05 -0700 | [diff] [blame] | 40 | $(hide) rm -f "$(PRIVATE_TARGET_NOCACHE)" |
James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 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 | XML_OUTPUT_FILE="$(PRIVATE_XML_OUTPUT_FILE)" \ |
| 52 | TEST_WORKSPACE="$(PRIVATE_MODULE)" \ |
| 53 | $(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)/wrapper.sh \ |
| 54 | "$(PRIVATE_MODULE)" \ |
| 55 | "$(PRIVATE_TARGET_OUTPUT)" \ |
| 56 | "$(PRIVATE_TARGET_RETVAL)" \ |
| 57 | wrap \ |
| 58 | $(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)/robotest.sh |
| 59 | |
James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 60 | # Private variables. |
| 61 | $(my_target): PRIVATE_MODULE := $(LOCAL_MODULE) |
| 62 | $(my_target): PRIVATE_TARGET_OUTPUT := $(my_target_output) |
| 63 | $(my_target): PRIVATE_TARGET_RETVAL := $(my_target_retval) |
| 64 | $(my_target): PRIVATE_FAILURE_FATAL := $(my_failure_fatal) |
| 65 | $(my_target): PRIVATE_ROBOLECTRIC_SCRIPT_PATH := $(my_robolectric_script_path) |
| 66 | # Process the output and the return value of the tests. This will fail if the |
| 67 | # return value is non-zero. |
| 68 | $(my_target): $(my_target_output) $(my_target_xml) |
| 69 | $(hide) \ |
| 70 | result=0; \ |
| 71 | $(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)/wrapper.sh \ |
| 72 | "$(PRIVATE_MODULE)" \ |
| 73 | "$(PRIVATE_TARGET_OUTPUT)" \ |
| 74 | "$(PRIVATE_TARGET_RETVAL)" \ |
| 75 | eval \ |
| 76 | || result=$$?; \ |
| 77 | if [ "$(strip $(PRIVATE_FAILURE_FATAL))" = true ]; then \ |
| 78 | exit "$$result"; \ |
| 79 | fi |
Dan Willemsen | 31c4a3a | 2018-06-19 15:55:05 -0700 | [diff] [blame] | 80 | $(hide) touch $@ |
James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 81 | |
| 82 | # Add the output of the tests to the dist list, so that we will include it even |
| 83 | # if the tests fail. |
Dan Willemsen | 6255fe1 | 2018-10-18 10:59:05 -0700 | [diff] [blame] | 84 | $(call dist-for-goals, $(my_phony_target), \ |
James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 85 | $(my_target_output):robotests/$(LOCAL_MODULE)-$(notdir $(my_target_output)) \ |
| 86 | $(my_target_xml):robotests/$(LOCAL_MODULE)-$(notdir $(my_target_xml))) |
| 87 | |
| 88 | # Clean up local variables. |
| 89 | my_target_output := |
| 90 | my_target_retval := |
| 91 | my_target_xml := |
Dan Willemsen | 31c4a3a | 2018-06-19 15:55:05 -0700 | [diff] [blame] | 92 | my_target_nocache := |
Maurice Lam | 90f0b8e | 2018-02-26 17:20:41 -0800 | [diff] [blame] | 93 | my_filename_stem := |