• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
11my_target_xml := $(intermediates)/$(my_filename_stem)-output.xml
12my_target_output := $(intermediates)/$(my_filename_stem)-output.txt
13my_target_retval := $(intermediates)/$(my_filename_stem)-retval.txt
14
15# We should always re-run the tests, even if nothing has changed.
16# So until the build system has a dedicated "no cache" option, claim
17# to write a file that is never produced.
18my_target_nocache := $(intermediates)/$(my_filename_stem)-nocache
19
20# OpenJDK 10+ java binaries include v54+ classfiles which require ASM 7.0 or higher.
21# While this build is still using ASM 6.0, pin to an OpenJDK 9 java binary:
22my_require_v53_or_lower_class_files := true
23
24# Private variables.
25$(my_target_output): PRIVATE_MODULE := $(LOCAL_MODULE)
26$(my_target_output): PRIVATE_TESTS := $(my_tests)
27$(my_target_output): PRIVATE_JARS := $(my_jars)
28$(my_target_output): PRIVATE_JAVA_ARGS := $(my_java_args)
29$(my_target_output): PRIVATE_JAVA_PATH := $(if $(my_require_v53_or_lower_class_files),$(ANDROID_JAVA9_HOME)/bin:,)
30$(my_target_output): PRIVATE_ROBOLECTRIC_PATH := $(my_robolectric_path)
31$(my_target_output): PRIVATE_ROBOLECTRIC_SCRIPT_PATH := $(my_robolectric_script_path)
32$(my_target_output): PRIVATE_TARGET_MESSAGE := $(my_target_message)
33$(my_target_output): PRIVATE_TARGET_OUTPUT := $(my_target_output)
34$(my_target_output): PRIVATE_TARGET_RETVAL := $(my_target_retval)
35$(my_target_output): PRIVATE_TARGET_NOCACHE := $(my_target_nocache)
36$(my_target_output): PRIVATE_TIMEOUT := $(my_timeout)
37$(my_target_output): PRIVATE_XML_OUTPUT_FILE := $(my_target_xml)
38$(my_target_output): .KATI_IMPLICIT_OUTPUTS := $(my_target_xml) $(my_target_retval) $(my_target_nocache)
39# Runs the Robolectric tests and saves the output and return value.
40$(my_target_output): $(my_jars)
41	@echo "host Robolectric: $(PRIVATE_MODULE)"
42	# Run `touch` to always create the output XML file, so the build doesn't break even if the
43	# runner failed to create the XML output
44	$(hide) touch "$(PRIVATE_XML_OUTPUT_FILE)"
45	$(hide) rm -f "$(PRIVATE_TARGET_NOCACHE)"
46	$(hide) \
47	  PRIVATE_INTERMEDIATES="$(dir $@)" \
48	  PRIVATE_JARS="$(PRIVATE_JARS)" \
49	  PRIVATE_JAVA_ARGS="$(PRIVATE_JAVA_ARGS)" \
50	  PRIVATE_ROBOLECTRIC_PATH="$(PRIVATE_ROBOLECTRIC_PATH)" \
51	  PRIVATE_ROBOLECTRIC_SCRIPT_PATH="$(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)" \
52	  PRIVATE_RUN_INDIVIDUALLY="$(ROBOTEST_RUN_INDIVIDUALLY)" \
53	  PRIVATE_TARGET_MESSAGE="$(PRIVATE_TARGET_MESSAGE)" \
54	  PRIVATE_TIMEOUT="$(PRIVATE_TIMEOUT)" \
55	  PRIVATE_TESTS="$(PRIVATE_TESTS)" \
56	  XML_OUTPUT_FILE="$(PRIVATE_XML_OUTPUT_FILE)" \
57	  TEST_WORKSPACE="$(PRIVATE_MODULE)" \
58	  EVENT_FILE_ROBOLECTRIC="$(EVENT_FILE_ROBOLECTRIC)" \
59	  PATH=$(PRIVATE_JAVA_PATH)$${PATH} \
60	  $(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)/wrapper.sh \
61	    "$(PRIVATE_MODULE)" \
62	    "$(PRIVATE_TARGET_OUTPUT)" \
63	    "$(PRIVATE_TARGET_RETVAL)" \
64	    wrap \
65	    $(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)/robotest.sh
66
67# Private variables.
68$(my_target): PRIVATE_MODULE := $(LOCAL_MODULE)
69$(my_target): PRIVATE_TARGET_OUTPUT := $(my_target_output)
70$(my_target): PRIVATE_TARGET_RETVAL := $(my_target_retval)
71$(my_target): PRIVATE_FAILURE_FATAL := $(my_failure_fatal)
72$(my_target): PRIVATE_ROBOLECTRIC_SCRIPT_PATH := $(my_robolectric_script_path)
73# Process the output and the return value of the tests. This will fail if the
74# return value is non-zero.
75$(my_target): $(my_target_output) $(my_target_xml)
76	$(hide) \
77	  result=0; \
78	  $(PRIVATE_ROBOLECTRIC_SCRIPT_PATH)/wrapper.sh \
79	    "$(PRIVATE_MODULE)" \
80	    "$(PRIVATE_TARGET_OUTPUT)" \
81	    "$(PRIVATE_TARGET_RETVAL)" \
82	    eval \
83	      || result=$$?; \
84	  if [ "$(strip $(PRIVATE_FAILURE_FATAL))" = true ]; then \
85	    exit "$$result"; \
86	  fi
87	$(hide) touch $@
88
89# Add the output of the tests to the dist list, so that we will include it even
90# if the tests fail.
91$(call dist-for-goals, $(my_phony_target), \
92    $(my_target_output):robotests/$(LOCAL_MODULE)-$(notdir $(my_target_output)) \
93    $(my_target_xml):robotests/$(LOCAL_MODULE)-$(notdir $(my_target_xml)))
94
95# Clean up local variables.
96my_target_output :=
97my_target_retval :=
98my_target_xml :=
99my_target_nocache :=
100my_filename_stem :=
101my_require_v53_or_lower_class_files :=
102