blob: 4b790c20ce9d3ae6a418a2af18e943a8cf518317 [file] [log] [blame]
James Lemieux2a2559e2018-01-28 02:56:27 -08001# Defines a target named $(my_target) for generating a coverage report.
2
3my_report_dir := $(my_coverage_dir)/reports
4my_coverage_output := $(my_report_dir)/coverage.xml
5
6# Private variables.
7$(my_coverage_output): PRIVATE_MODULE := $(LOCAL_MODULE)
8$(my_coverage_output): PRIVATE_COVERAGE_FILE := $(my_coverage_file)
9$(my_coverage_output): PRIVATE_COVERAGE_SRCS_JARS := $(my_coverage_srcs_jars)
Colin Crossc17f6af2019-05-07 22:30:24 -070010ifdef my_instrument_srcjars
11 $(my_coverage_output): PRIVATE_SRC_ARGS := --srcjars $(call normalize-path-list,$(my_instrument_srcjars))
12 $(my_coverage_output): $(my_instrument_srcjars)
13else
14 $(my_coverage_output): PRIVATE_SRC_ARGS := --srcs $(call normalize-path-list,$(my_instrument_source_dirs))
15endif
James Lemieux2a2559e2018-01-28 02:56:27 -080016$(my_coverage_output): PRIVATE_COVERAGE_REPORT_CLASS := $(my_coverage_report_class)
17$(my_coverage_output): PRIVATE_COVERAGE_REPORT_JAR := $(my_coverage_report_jar)
18$(my_coverage_output): PRIVATE_REPORT_DIR := $(my_report_dir)
19
20# Generate the coverage report.
Colin Cross72f772a2019-11-19 14:49:34 -080021# Touches the output file and continues on failure to avoid breaking the build when a test fails to
22# generate coverage data.
Dan Willemsen73b1bb52018-07-24 22:46:04 -070023$(my_coverage_output): $(my_collect_file) $(my_coverage_report_jar)
Colin Cross72f772a2019-11-19 14:49:34 -080024 $(hide) rm -f $@
James Lemieux2a2559e2018-01-28 02:56:27 -080025 $(hide) rm -rf $(PRIVATE_REPORT_DIR)
26 $(hide) mkdir -p $(PRIVATE_REPORT_DIR)
27 $(hide) $(JAVA) \
28 -cp $(PRIVATE_COVERAGE_REPORT_JAR) \
29 $(PRIVATE_COVERAGE_REPORT_CLASS) \
30 -classpath $(strip $(call normalize-path-list, $(PRIVATE_COVERAGE_SRCS_JARS))) \
31 --exec-file $(PRIVATE_COVERAGE_FILE) \
32 --name $(PRIVATE_MODULE) \
33 --report-dir $(PRIVATE_REPORT_DIR)/ \
Colin Crossc17f6af2019-05-07 22:30:24 -070034 $(PRIVATE_SRC_ARGS) \
Colin Cross72f772a2019-11-19 14:49:34 -080035 >$(PRIVATE_REPORT_DIR)/reporter.txt 2>&1 \
36 || touch $@
James Lemieux2a2559e2018-01-28 02:56:27 -080037 @echo "Coverage report: file://"$(realpath $(PRIVATE_REPORT_DIR))"/index.html"
38
39
40# Generate a ZIP file of the coverage report.
41my_coverage_output_zip := $(my_coverage_dir)/report-html.zip
42
43$(my_coverage_output_zip): PRIVATE_REPORT_DIR := $(my_report_dir)
44$(my_coverage_output_zip): $(my_coverage_output)
45 $(hide) cd $(PRIVATE_REPORT_DIR) && zip --quiet -r $(PWD)/$@ .
46
47# Add coverage report zip to dist files.
Dan Willemsen6255fe12018-10-18 10:59:05 -070048$(call dist-for-goals, $(my_report_target), \
James Lemieux2a2559e2018-01-28 02:56:27 -080049 $(my_coverage_output_zip):robotests-coverage/$(LOCAL_MODULE)/robolectric-html-coverage.zip \
50 $(my_coverage_output):robotests-coverage/$(LOCAL_MODULE)/robolectric-coverage.xml)
51
Bob Badour9357e3d2022-04-20 13:02:24 -070052ALL_TARGETS.$(my_coverage_output_zip).META_LIC:=$(module_license_metadata)
53ALL_TARGETS.$(my_coverage_output).META_LIC:=$(module_license_metadata)
54
James Lemieux2a2559e2018-01-28 02:56:27 -080055# Running the coverage will always generate the report.
56$(my_target): $(my_coverage_output)
57
58# Reset local variables.
59my_coverage_output :=
60my_coverage_output_zip :=
Dan Willemsen73b1bb52018-07-24 22:46:04 -070061my_report_dir :=