Home | History | Annotate | Download | only in 3.5.1
      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)
     10 $(my_coverage_output): PRIVATE_INSTRUMENT_SOURCE_DIRS := $(my_instrument_source_dirs)
     11 $(my_coverage_output): PRIVATE_COVERAGE_REPORT_CLASS := $(my_coverage_report_class)
     12 $(my_coverage_output): PRIVATE_COVERAGE_REPORT_JAR := $(my_coverage_report_jar)
     13 $(my_coverage_output): PRIVATE_REPORT_DIR := $(my_report_dir)
     14 
     15 # Generate the coverage report.
     16 $(my_coverage_output): $(my_collect_target) $(my_coverage_report_jar)
     17 	$(hide) rm -rf $(PRIVATE_REPORT_DIR)
     18 	$(hide) mkdir -p $(PRIVATE_REPORT_DIR)
     19 	$(hide) $(JAVA) \
     20 			-cp $(PRIVATE_COVERAGE_REPORT_JAR) \
     21 			$(PRIVATE_COVERAGE_REPORT_CLASS) \
     22 			-classpath $(strip $(call normalize-path-list, $(PRIVATE_COVERAGE_SRCS_JARS))) \
     23 			--exec-file $(PRIVATE_COVERAGE_FILE) \
     24 			--name $(PRIVATE_MODULE) \
     25 			--report-dir $(PRIVATE_REPORT_DIR)/ \
     26 			--srcs $(strip $(call normalize-path-list, $(PRIVATE_INSTRUMENT_SOURCE_DIRS))) \
     27 			>$(PRIVATE_REPORT_DIR)/reporter.txt 2>&1
     28 	@echo "Coverage report: file://"$(realpath $(PRIVATE_REPORT_DIR))"/index.html"
     29 
     30 
     31 # Generate a ZIP file of the coverage report.
     32 my_coverage_output_zip := $(my_coverage_dir)/report-html.zip
     33 
     34 $(my_coverage_output_zip): PRIVATE_REPORT_DIR := $(my_report_dir)
     35 $(my_coverage_output_zip): $(my_coverage_output)
     36 	$(hide) cd $(PRIVATE_REPORT_DIR) && zip --quiet -r $(PWD)/$@ .
     37 
     38 # Add coverage report zip to dist files.
     39 $(call dist-for-goals, $(my_target), \
     40     $(my_coverage_output_zip):robotests-coverage/$(LOCAL_MODULE)/robolectric-html-coverage.zip \
     41     $(my_coverage_output):robotests-coverage/$(LOCAL_MODULE)/robolectric-coverage.xml)
     42 
     43 # Running the coverage will always generate the report.
     44 $(my_target): $(my_coverage_output)
     45 
     46 # Reset local variables.
     47 my_coverage_output :=
     48 my_coverage_output_zip :=
     49 my_report_dir :=
     50