huangcm
2025-07-01 676035278781360996553c427a12bf358249ebf7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Defines a target named $(my_target) for generating a coverage report.
 
my_report_dir := $(my_coverage_dir)/reports
my_coverage_output := $(my_report_dir)/coverage.xml
 
# Private variables.
$(my_coverage_output): PRIVATE_MODULE := $(LOCAL_MODULE)
$(my_coverage_output): PRIVATE_COVERAGE_FILE := $(my_coverage_file)
$(my_coverage_output): PRIVATE_COVERAGE_SRCS_JARS := $(my_coverage_srcs_jars)
$(my_coverage_output): PRIVATE_INSTRUMENT_SOURCE_DIRS := $(my_instrument_source_dirs)
$(my_coverage_output): PRIVATE_COVERAGE_REPORT_CLASS := $(my_coverage_report_class)
$(my_coverage_output): PRIVATE_COVERAGE_REPORT_JAR := $(my_coverage_report_jar)
$(my_coverage_output): PRIVATE_REPORT_DIR := $(my_report_dir)
 
# Generate the coverage report.
$(my_coverage_output): $(my_collect_file) $(my_coverage_report_jar)
   $(hide) rm -rf $(PRIVATE_REPORT_DIR)
   $(hide) mkdir -p $(PRIVATE_REPORT_DIR)
   $(hide) $(JAVA) \
           -cp $(PRIVATE_COVERAGE_REPORT_JAR) \
           $(PRIVATE_COVERAGE_REPORT_CLASS) \
           -classpath $(strip $(call normalize-path-list, $(PRIVATE_COVERAGE_SRCS_JARS))) \
           --exec-file $(PRIVATE_COVERAGE_FILE) \
           --name $(PRIVATE_MODULE) \
           --report-dir $(PRIVATE_REPORT_DIR)/ \
           --srcs $(strip $(call normalize-path-list, $(PRIVATE_INSTRUMENT_SOURCE_DIRS))) \
           >$(PRIVATE_REPORT_DIR)/reporter.txt 2>&1
   @echo "Coverage report: file://"$(realpath $(PRIVATE_REPORT_DIR))"/index.html"
 
 
# Generate a ZIP file of the coverage report.
my_coverage_output_zip := $(my_coverage_dir)/report-html.zip
 
$(my_coverage_output_zip): PRIVATE_REPORT_DIR := $(my_report_dir)
$(my_coverage_output_zip): $(my_coverage_output)
   $(hide) cd $(PRIVATE_REPORT_DIR) && zip --quiet -r $(PWD)/$@ .
 
# Add coverage report zip to dist files.
$(call dist-for-goals, $(my_report_target), \
    $(my_coverage_output_zip):robotests-coverage/$(LOCAL_MODULE)/robolectric-html-coverage.zip \
    $(my_coverage_output):robotests-coverage/$(LOCAL_MODULE)/robolectric-coverage.xml)
 
# Running the coverage will always generate the report.
$(my_target): $(my_coverage_output)
 
# Reset local variables.
my_coverage_output :=
my_coverage_output_zip :=
my_report_dir :=