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
diff --git a/core/definitions.mk b/core/definitions.mk
index 13bd47c..1c14f22 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -3281,6 +3281,30 @@
# 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