OSDN Git Service

Squashed commit of the following (DO NOT MERGE):
authorGuang Zhu <guangzhu@google.com>
Thu, 13 May 2010 23:46:21 +0000 (16:46 -0700)
committerGuang Zhu <guangzhu@google.com>
Tue, 18 May 2010 22:26:22 +0000 (15:26 -0700)
commit 7401608f3b9b52b3348e32ec9fefe7583d6c2fa4
Author: Guang Zhu <guangzhu@google.com>
Date:   Fri Apr 23 11:54:37 2010 -0700

    collect emm meta files for emma instrumented build

    when doing 'make dist', with EMMA_INSTRUMENT on the coverage.em files
    generated for each module will be collected into one emma_meta.zip file

    Change-Id: I382c39a97005e6cae5c79ad7eaef1c8857f658af

commit 8376d70938f6507d54b66fe5832a637aa883974e
Author: Guang Zhu <guangzhu@google.com>
Date:   Wed Mar 10 15:48:03 2010 -0800

    enhancement for building app with emma code coverage

    * global filter to avoid applying instrumentation on emma classes
    * remove local variable information at dex step instead of compile time

    Change-Id: If04c27bc717f34816077a98ead9ceb0dbcbb0d2f

Change-Id: I971bd0f291bede2568b21347247d37a7d035c661

core/Makefile
core/clear_vars.mk
core/definitions.mk
core/java.mk
core/main.mk

index 9cb8c82..bd46b36 100644 (file)
@@ -1072,6 +1072,17 @@ $(APPS_ZIP): $(INSTALLED_SYSTEMIMAGE)
        $(hide) mkdir -p $(dir $@)
        $(hide) zip -qj $@ $(TARGET_OUT_APPS)/*
 
+
+#------------------------------------------------------------------
+# A zip of emma code coverage meta files. Generated for fully emma
+# instrumented build.
+#
+EMMA_META_ZIP := $(PRODUCT_OUT)/emma_meta.zip
+$(EMMA_META_ZIP): $(INSTALLED_SYSTEMIMAGE)
+       @echo "Collecting Emma coverage meta files."
+       $(hide) find $(TARGET_COMMON_OUT_ROOT) -name "coverage.em" | \
+               zip -@ -q $@
+
 endif  # TARGET_SIMULATOR != true
 
 # -----------------------------------------------------------------
index 35b1224..c37b43e 100644 (file)
@@ -93,6 +93,7 @@ LOCAL_NO_EMMA_INSTRUMENT:=
 LOCAL_NO_EMMA_COMPILE:=
 LOCAL_PROGUARD_ENABLED:= # '',optonly,full,custom
 LOCAL_PROGUARD_FLAGS:=
+LOCAL_EMMA_COVERAGE_FILTER:=
 
 # Trim MAKEFILE_LIST so that $(call my-dir) doesn't need to
 # iterate over thousands of entries every time.
index fd2be64..b911eef 100644 (file)
@@ -1326,7 +1326,8 @@ endef
 
 define transform-classes.jar-to-emma
 $(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \
-    $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR)
+    $(PRIVATE_EMMA_COVERAGE_FILE) -ip $< -d $(PRIVATE_EMMA_INTERMEDIATES_DIR) \
+    -ix $(PRIVATE_EMMA_COVERAGE_FILTER)
 endef
 
 #TODO: use a smaller -Xmx value for most libraries;
index 4955a33..6c8d3d5 100644 (file)
@@ -63,10 +63,13 @@ endif
 # Choose leaf name for the compiled jar file.
 ifneq ($(LOCAL_NO_EMMA_COMPILE),true)
 full_classes_compiled_jar_leaf := classes-no-debug-var.jar
+built_dex_leaf := classes-no-local.dex
 else
 full_classes_compiled_jar_leaf := classes-full-debug.jar
+built_dex_leaf := classes-with-local.dex
 endif
 full_classes_compiled_jar := $(intermediates.COMMON)/$(full_classes_compiled_jar_leaf)
+built_dex_intermediate := $(intermediates.COMMON)/$(built_dex_leaf)
 
 emma_intermediates_dir := $(intermediates.COMMON)/emma_out
 # the 'lib/$(full_classes_compiled_jar_leaf)' portion of this path is fixed in
@@ -85,7 +88,8 @@ LOCAL_INTERMEDIATE_TARGETS += \
     $(full_classes_full_names_jar) \
     $(full_classes_stubs_jar) \
     $(full_classes_jarjar_jar) \
-    $(built_dex)
+    $(built_dex) \
+    $(built_dex_intermediate)
 
 LOCAL_INTERMEDIATE_SOURCE_DIR := $(intermediates.COMMON)/src
 
@@ -155,18 +159,7 @@ $(full_classes_compiled_jar): $(java_sources) $(full_java_lib_deps)
 # be done after the inclusion of base_rules.mk.
 ALL_MODULES.$(LOCAL_MODULE).CHECKED := $(full_classes_compiled_jar)
 
-ifneq ($(LOCAL_NO_EMMA_COMPILE),true)
-# If you instrument class files that have local variable debug information in
-# them emma does not correctly maintain the local variable table.
-# This will cause an error when you try to convert the class files for Android.
-# The workaround for this to compile the java classes with only
-# line and source debug information, not local information.
-$(full_classes_compiled_jar): PRIVATE_JAVAC_DEBUG_FLAGS := -g:{lines,source}
-else
-# when emma is off, compile with the default flags, which contain full debug
-# info
 $(full_classes_compiled_jar): PRIVATE_JAVAC_DEBUG_FLAGS := -g
-endif
 
 ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
 # Skip adding emma instrumentation to class files if this is a static library,
@@ -177,6 +170,15 @@ endif
 ifneq ($(LOCAL_NO_EMMA_INSTRUMENT),true)
 $(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILE := $(intermediates.COMMON)/coverage.em
 $(full_classes_emma_jar): PRIVATE_EMMA_INTERMEDIATES_DIR := $(emma_intermediates_dir)
+# module level coverage filter can be defined using LOCAL_EMMA_COVERAGE_FILTER
+# in Android.mk
+ifdef LOCAL_EMMA_COVERAGE_FILTER
+$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := $(LOCAL_EMMA_COVERAGE_FILTER)
+else
+# by default, avoid applying emma instrumentation onto emma classes itself,
+# otherwise there will be exceptions thrown
+$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := *,-emma,-emmarun,-com.vladium.*
+endif
 # this rule will generate both $(PRIVATE_EMMA_COVERAGE_FILE) and
 # $(full_classes_emma_jar)
 $(full_classes_emma_jar): $(full_classes_compiled_jar) | $(EMMA_JAR)
@@ -253,12 +255,25 @@ $(full_classes_proguard_jar): $(full_classes_full_names_jar) | $(ACP) $(PROGUARD
 
 ALL_MODULES.$(LOCAL_MODULE).PROGUARD_ENABLED:=$(LOCAL_PROGUARD_ENABLED)
 
+# If you instrument class files that have local variable debug information in
+# them emma does not correctly maintain the local variable table.
+# This will cause an error when you try to convert the class files for Android.
+# The workaround here is to build different dex file here based on emma switch
+# then later copy into classes.dex. When emma is on, dx is run with --no-locals
+# option to remove local variable information
+
 # Override PRIVATE_INTERMEDIATES_DIR so that install-dex-debug
 # will work even when intermediates != intermediates.COMMON.
-$(built_dex): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON)
-$(built_dex): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
-$(built_dex): $(full_classes_jar) $(DX)
+$(built_dex_intermediate): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON)
+$(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
+ifneq ($(LOCAL_NO_EMMA_COMPILE),true)
+$(built_dex_intermediate): PRIVATE_DX_FLAGS += --no-locals
+endif
+$(built_dex_intermediate): $(full_classes_jar) $(DX)
        $(transform-classes.jar-to-dex)
+$(built_dex): $(built_dex_intermediate) | $(ACP)
+       @echo Copying: $@
+       $(hide) $(ACP) $< $@
 ifneq ($(GENERATE_DEX_DEBUG),)
        $(install-dex-debug)
 endif
index f52b473..6eb2662 100644 (file)
@@ -707,6 +707,12 @@ $(call dist-for-goals, droid, \
        $(INSTALLED_RAMDISK_TARGET) \
  )
 
+ifeq ($(EMMA_INSTRUMENT),true)
+$(call dist-for-goals, droid, \
+       $(EMMA_META_ZIP) \
+ )
+endif
+
 # Tests are installed in userdata.img.  If we're building the tests
 # variant, copy it for "make tests dist".  Also copy a zip of the
 # contents of userdata.img, so that people can easily extract a