James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 1 | # Defines a target named $(my_target) for generating a coverage report. |
| 2 | |
| 3 | my_report_dir := $(my_coverage_dir)/reports |
| 4 | my_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 Cross | c17f6af | 2019-05-07 22:30:24 -0700 | [diff] [blame] | 10 | ifdef 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) |
| 13 | else |
| 14 | $(my_coverage_output): PRIVATE_SRC_ARGS := --srcs $(call normalize-path-list,$(my_instrument_source_dirs)) |
| 15 | endif |
James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 16 | $(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 Cross | 72f772a | 2019-11-19 14:49:34 -0800 | [diff] [blame] | 21 | # Touches the output file and continues on failure to avoid breaking the build when a test fails to |
| 22 | # generate coverage data. |
Dan Willemsen | 73b1bb5 | 2018-07-24 22:46:04 -0700 | [diff] [blame] | 23 | $(my_coverage_output): $(my_collect_file) $(my_coverage_report_jar) |
Colin Cross | 72f772a | 2019-11-19 14:49:34 -0800 | [diff] [blame] | 24 | $(hide) rm -f $@ |
James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 25 | $(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 Cross | c17f6af | 2019-05-07 22:30:24 -0700 | [diff] [blame] | 34 | $(PRIVATE_SRC_ARGS) \ |
Colin Cross | 72f772a | 2019-11-19 14:49:34 -0800 | [diff] [blame] | 35 | >$(PRIVATE_REPORT_DIR)/reporter.txt 2>&1 \ |
| 36 | || touch $@ |
James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 37 | @echo "Coverage report: file://"$(realpath $(PRIVATE_REPORT_DIR))"/index.html" |
| 38 | |
| 39 | |
| 40 | # Generate a ZIP file of the coverage report. |
| 41 | my_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 Willemsen | 6255fe1 | 2018-10-18 10:59:05 -0700 | [diff] [blame] | 48 | $(call dist-for-goals, $(my_report_target), \ |
James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 49 | $(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 Badour | 9357e3d | 2022-04-20 13:02:24 -0700 | [diff] [blame] | 52 | ALL_TARGETS.$(my_coverage_output_zip).META_LIC:=$(module_license_metadata) |
| 53 | ALL_TARGETS.$(my_coverage_output).META_LIC:=$(module_license_metadata) |
| 54 | |
James Lemieux | 2a2559e | 2018-01-28 02:56:27 -0800 | [diff] [blame] | 55 | # Running the coverage will always generate the report. |
| 56 | $(my_target): $(my_coverage_output) |
| 57 | |
| 58 | # Reset local variables. |
| 59 | my_coverage_output := |
| 60 | my_coverage_output_zip := |
Dan Willemsen | 73b1bb5 | 2018-07-24 22:46:04 -0700 | [diff] [blame] | 61 | my_report_dir := |