Tighten restrictions on LOCAL_JACK_COVERAGE_(INCLUDE|EXCLUDE)_FILTER

Jack supported '?' and '*' wildcards anywhere in a filter. Tighten
the restrictions to only support '*' at the end of a filter, and
to disallow '?'.  This will allow jacoco support to be built on
top of the existing zip2zip tools.

Add checks that all filters meet the new requirements, and run
the checks outside the LOCAL_EMMA_INSTRUMENT==true check so that
mistakes can be caught without having to run a build with
coverage enabled.

Bug: 69629238
Test: m EMMA_INSTRUMENT=true EMMA_INSTRUMENT_STATIC=true
Test: m in internal master
Test: https://android-build.googleplex.com/builds/view-workplan?viewType=Table&workplanId=L67200000122054710&nodeType=Trybot
Change-Id: Ib78bd3c8685fbc6bdcdb517df874186efd1cff33
This commit is contained in:
Colin Cross 2017-11-21 15:01:26 -08:00
parent cbf6fd55bf
commit 3c8d30ce60
2 changed files with 37 additions and 31 deletions

View File

@ -3281,6 +3281,30 @@ endef
# run test
$(strip $(call test-validate-paths-are-subdirs))
###########################################################
## Validate jacoco class filters and convert them to
## file arguments
## Jacoco class filters are comma-separated lists of class
## files (android.app.Application), and may have '*' as the
## last character to match all classes in a package
## including subpackages.
define jacoco-class-filter-to-file-args
$(strip $(call jacoco-validate-file-args,\
$(subst $(comma),$(space),\
$(subst .,/,\
$(strip $(1))))))
endef
define jacoco-validate-file-args
$(strip $(1)\
$(call validate-paths-are-subdirs,$(1))
$(foreach arg,$(1),\
$(if $(findstring ?,$(arg)),$(call pretty-error,\
'?' filters are not supported in LOCAL_JACK_COVERAGE_INCLUDE_FILTER or LOCAL_JACK_COVERAGE_EXCLUDE_FILTER))\
$(if $(findstring *,$(patsubst %*,%,$(arg))),$(call pretty-error,\
'*' is only supported at the end of a filter in LOCAL_JACK_COVERAGE_INCLUDE_FILTER or LOCAL_JACK_COVERAGE_EXCLUDE_FILTER))\
))
endef
###########################################################
## Other includes

View File

@ -19,41 +19,23 @@
# (at the time of authorship, it is included by java.mk and
# java_host_library.mk)
my_include_filter :=
my_exclude_filter :=
# determine Jacoco include/exclude filters even when coverage is not enabled
# to get syntax checking on LOCAL_JACK_COVERAGE_(INCLUDE|EXCLUDE)_FILTER
DEFAULT_JACOCO_EXCLUDE_FILTER := org/junit/*,org/jacoco/*,org/mockito/*
# copy filters from Jack but also skip some known java packages
my_include_filter := $(strip $(LOCAL_JACK_COVERAGE_INCLUDE_FILTER))
my_exclude_filter := $(strip $(DEFAULT_JACOCO_EXCLUDE_FILTER),$(LOCAL_JACK_COVERAGE_EXCLUDE_FILTER))
my_include_args := $(call jacoco-class-filter-to-file-args, $(my_include_filter))
my_exclude_args := $(call jacoco-class-filter-to-file-args, $(my_exclude_filter))
# single-quote each arg of the include args so the '*' gets evaluated by zip
# don't quote the exclude args they need to be evaluated by bash for rm -rf
my_include_args := $(foreach arg,$(my_include_args),'$(arg)')
ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
# determine Jacoco include/exclude filters
DEFAULT_JACOCO_EXCLUDE_FILTER := org/junit/*,org/jacoco/*,org/mockito/*
# copy filters from Jack but also skip some known java packages
my_include_filter := $(strip $(LOCAL_JACK_COVERAGE_INCLUDE_FILTER))
my_exclude_filter := $(strip $(DEFAULT_JACOCO_EXCLUDE_FILTER),$(LOCAL_JACK_COVERAGE_EXCLUDE_FILTER))
# replace '.' with '/' and ',' with ' ', and quote each arg
ifneq ($(strip $(my_include_filter)),)
my_include_args := $(strip $(my_include_filter))
my_include_args := $(subst .,/,$(my_include_args))
my_include_args := '$(subst $(comma),' ',$(my_include_args))'
else
my_include_args :=
endif
# replace '.' with '/' and ',' with ' '
ifneq ($(strip $(my_exclude_filter)),)
my_exclude_args := $(my_exclude_filter)
my_exclude_args := $(subst .,/,$(my_exclude_args))
my_exclude_args := $(subst $(comma)$(comma),$(comma),$(my_exclude_args))
my_exclude_args := $(subst $(comma), ,$(my_exclude_args))
else
my_exclude_args :=
endif
my_files := $(intermediates.COMMON)/jacoco
$(call validate-paths-are-subdirs,$(my_exclude_args))
# make a task that unzips the classes that we want to instrument from the
# input jar
my_unzipped_path := $(my_files)/work/classes-to-instrument/classes