diff --git a/core/definitions.mk b/core/definitions.mk index 99b2ed152..6b1d8fc3c 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -1979,6 +1979,7 @@ else \ fi; \ $(call call-jack) \ $(strip $(PRIVATE_JACK_FLAGS)) \ + $(strip $(PRIVATE_JACK_COVERAGE_OPTIONS)) \ $(if $(NO_OPTIMIZE_DX), \ -D jack.dex.optimize="false") \ $(if $(PRIVATE_RMTYPEDEFS), \ diff --git a/core/java.mk b/core/java.mk index 9e7821506..9b8ee1250 100644 --- a/core/java.mk +++ b/core/java.mk @@ -496,7 +496,11 @@ common_proguard_flags := \ ifeq ($(filter nosystem,$(LOCAL_PROGUARD_ENABLED)),) common_proguard_flags += -include $(BUILD_SYSTEM)/proguard.flags ifeq ($(LOCAL_EMMA_INSTRUMENT),true) +ifdef LOCAL_JACK_ENABLED +common_proguard_flags += -include $(BUILD_SYSTEM)/proguard.jacoco.flags +else common_proguard_flags += -include $(BUILD_SYSTEM)/proguard.emma.flags +endif # LOCAL_JACK_ENABLED endif # If this is a test package, add proguard keep flags for tests. ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),) @@ -667,6 +671,15 @@ $(built_dex).toc: $(full_classes_jack) else #LOCAL_IS_STATIC_JAVA_LIBRARY $(built_dex_intermediate): PRIVATE_CLASSES_JACK := $(full_classes_jack) +ifeq ($(LOCAL_EMMA_INSTRUMENT),true) +$(built_dex_intermediate): PRIVATE_JACK_COVERAGE_OPTIONS := \ + -D jack.coverage="true" \ + -D jack.coverage.metadata.file=$(intermediates.COMMON)/coverage.em \ + -D jack.coverage.jacoco.package=$(JACOCO_PACKAGE_NAME) +else +$(built_dex_intermediate): PRIVATE_JACK_COVERAGE_OPTIONS := +endif + $(built_dex_intermediate): $(jack_all_deps) | setup-jack-server @echo Building with Jack: $@ $(jack-java-to-dex) diff --git a/core/java_library.mk b/core/java_library.mk index dc6186f3f..81a4a6a30 100644 --- a/core/java_library.mk +++ b/core/java_library.mk @@ -47,7 +47,12 @@ endif ifeq (true,$(EMMA_INSTRUMENT)) ifeq (true,$(LOCAL_EMMA_INSTRUMENT)) ifeq (true,$(EMMA_INSTRUMENT_STATIC)) +ifdef LOCAL_JACK_ENABLED +# Jack supports coverage with Jacoco +LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent +else LOCAL_STATIC_JAVA_LIBRARIES += emma +endif # LOCAL_JACK_ENABLED endif # LOCAL_EMMA_INSTRUMENT endif # EMMA_INSTRUMENT_STATIC else diff --git a/core/main.mk b/core/main.mk index 549c82589..923e677f2 100644 --- a/core/main.mk +++ b/core/main.mk @@ -334,6 +334,11 @@ include build/core/pdk_config.mk # Install and start Jack server -include $(TOPDIR)prebuilts/sdk/tools/jack_server_setup.mk +# +# ----------------------------------------------------------------- +# Jacoco package name for Jack +-include $(TOPDIR)external/jacoco/config.mk + # ----------------------------------------------------------------- ### ### In this section we set up the things that are different diff --git a/core/package_internal.mk b/core/package_internal.mk index f5a00e5e7..097d801cb 100644 --- a/core/package_internal.mk +++ b/core/package_internal.mk @@ -186,12 +186,22 @@ endif # EMMA_INSTRUMENT is true ifeq (true,$(LOCAL_EMMA_INSTRUMENT)) ifeq (true,$(EMMA_INSTRUMENT_STATIC)) +ifdef LOCAL_JACK_ENABLED +# Jack supports coverage with Jacoco +LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent +else LOCAL_STATIC_JAVA_LIBRARIES += emma +endif # LOCAL_JACK_ENABLED else ifdef LOCAL_SDK_VERSION ifdef TARGET_BUILD_APPS # In unbundled build merge the emma library into the apk. +ifdef LOCAL_JACK_ENABLED +# Jack supports coverage with Jacoco +LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent +else LOCAL_STATIC_JAVA_LIBRARIES += emma +endif # LOCAL_JACK_ENABLED else # If build against the SDK in full build, core.jar is not used, # we have to use prebiult emma.jar to make Proguard happy; diff --git a/core/proguard.jacoco.flags b/core/proguard.jacoco.flags new file mode 100644 index 000000000..c3bed9435 --- /dev/null +++ b/core/proguard.jacoco.flags @@ -0,0 +1,8 @@ +# Keep everything for the emma classes +-keep class com.vladium.** { + *; +} +# Keep everything for the jacoco classes +-keep class org.jacoco.** { + *; +}