aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Hertz <shertz@google.com>2016-03-23 09:48:21 +0100
committerSebastien Hertz <shertz@google.com>2016-04-05 12:12:10 +0200
commit831c25634045d80f5cd522f934af6f9dfd253e62 (patch)
tree6dc53ce4f82dd0330c4b1bc777b4049e646a8473
parentf30df9cd8791309e704754def4adf1c94264c21a (diff)
downloadjacoco-nougat-bugfix-release.tar.gz
Excludes source files that depend on non-Android classes and modifies the source code when necessary. Adds a README.android file to describe those changes and the process to build jacoco. Bug: 27719795 (cherry picked from commit 8d9dc829193712ce6859dbd1b894fa2fe6545ff8) Change-Id: I1efb7cb7d6ef1e1ec5324c8d6ac0630a72169b63
-rw-r--r--Android.mk48
-rw-r--r--PREBUILT12
-rw-r--r--README.android15
-rw-r--r--asm-debug-all-5.0.1.jarbin0 -> 380292 bytes
-rw-r--r--config.mk2
-rw-r--r--org.jacoco.agent.rt-0.7.5.201505241946-all.jarbin273599 -> 0 bytes
-rw-r--r--org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java4
7 files changed, 67 insertions, 14 deletions
diff --git a/Android.mk b/Android.mk
index 0fc0f54c..b55fb273 100644
--- a/Android.mk
+++ b/Android.mk
@@ -15,8 +15,50 @@
#
LOCAL_PATH := $(call my-dir)
+# Build jacoco from sources for the platform
+#
+# Note: this is only intended to be used for the platform development. This is *not* intended
+# to be used in the SDK where apps can use the official jacoco release.
include $(CLEAR_VARS)
-LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
- jacocoagent:org.jacoco.agent.rt-0.7.5.201505241946-all$(COMMON_JAVA_PACKAGE_SUFFIX)
+
+jacoco_src_files := $(call all-java-files-under,org.jacoco.core/src)
+jacoco_src_files += $(call all-java-files-under,org.jacoco.agent/src)
+jacoco_src_files += $(call all-java-files-under,org.jacoco.agent.rt/src)
+
+# Some Jacoco source files depend on classes that do not exist in Android. While these classes are
+# not executed at runtime (because we use offline instrumentation), they will cause issues when
+# compiling them with ART during dex pre-opting. Therefore, it would prevent from applying code
+# coverage on classes in the bootclasspath (frameworks, services, ...) or system apps.
+# Note: we still may need to update the source code to cut dependencies in mandatory jacoco classes.
+jacoco_android_exclude_list := \
+ %org.jacoco.core/src/org/jacoco/core/runtime/ModifiedSystemClassRuntime.java \
+ %org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/PreMain.java \
+ %org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java \
+ %org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/JmxRegistration.java
+
+LOCAL_SRC_FILES := $(filter-out $(jacoco_android_exclude_list),$(jacoco_src_files))
+
+# In order to include Jacoco in core libraries, we cannot depend on anything in the
+# bootclasspath (or we would create dependency cycle). Therefore we compile against
+# the SDK android.jar which gives the same APIs Jacoco depends on.
+LOCAL_SDK_VERSION := 9
+
+LOCAL_MODULE := jacocoagent
LOCAL_MODULE_TAGS := optional
-include $(BUILD_MULTI_PREBUILT)
+LOCAL_STATIC_JAVA_LIBRARIES := jacoco-asm
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+#
+# Build asm-5.0.1 as a static library.
+#
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := jacoco-asm
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+LOCAL_SRC_FILES := asm-debug-all-5.0.1$(COMMON_JAVA_PACKAGE_SUFFIX)
+# Workaround for b/27319022
+LOCAL_JACK_FLAGS := -D jack.import.jar.debug-info=false
+LOCAL_UNINSTALLABLE_MODULE := true
+
+include $(BUILD_PREBUILT)
diff --git a/PREBUILT b/PREBUILT
index 9f9684fc..c8d9fd8c 100644
--- a/PREBUILT
+++ b/PREBUILT
@@ -1,13 +1,7 @@
-The jacocoagent.jar is updated in the following way:
+The ASM jar required by jacoco is updated in the following way:
-mvn install
-rm -f jacocoagent.jar
-cp org.jacoco.agent.rt/target/org.jacoco.agent.rt-0.7.5.201505241946-all.jar jacocoagent.jar
+mvn -f org.jacoco.agent.rt/pom.xml dependency:copy-dependencies
+cp org.jacoco.agent.rt/target/dependency/asm-debug-all-5.0.1.jar ./
mvn clean
The Android.mk must be updated to reference the right prebuilt.
-
-Also, the config.mk file must be updated to indicate what is the internal package name
-containing the core classes of Jacoco (org.jacoco.agent.rt.internal_*)
-Note: this information is available in the static field RUNTIMEPACKAGE
-of the org.jacoco.core.JaCoCo class (http://eclemma.org/jacoco/trunk/doc/api/org/jacoco/core/JaCoCo.html#RUNTIMEPACKAGE)
diff --git a/README.android b/README.android
new file mode 100644
index 00000000..6df57d1a
--- /dev/null
+++ b/README.android
@@ -0,0 +1,15 @@
+We build an equivalent of the jacoco-agent.jar which contains classes from org.jacoco.core,
+org.jacoco.agent and org.jacoco.agent.rt packages but also classes from asm 5.0.1.
+
+However, Jacoco depends on classes that do not exist in Android (java.lang.instrument.* or
+javax.management.*) for runtime instrumentation only. The ART compiler would reject those classes
+when they are either in the bootclasspath (core, frameworks, ...) or system apps.
+
+Since we only use offline instrumentation for code coverage (using Jack) and do not execute these
+classes at runtime, we simply not compile them here.
+
+We also need to modify the source code to cut dependencies to the classes that we exclude from the
+compilation. The changes are surrounded by "BEGIN android-change" and "END android-change". Here
+is the list of the changes:
+
+1) Remove the creation of JmxRegistration in org.jacoco.agent.rt.internal.Agent.
diff --git a/asm-debug-all-5.0.1.jar b/asm-debug-all-5.0.1.jar
new file mode 100644
index 00000000..76d4b6a7
--- /dev/null
+++ b/asm-debug-all-5.0.1.jar
Binary files differ
diff --git a/config.mk b/config.mk
index 506caad6..d645621d 100644
--- a/config.mk
+++ b/config.mk
@@ -12,5 +12,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-JACOCO_PACKAGE_NAME := org.jacoco.agent.rt.internal_d695e14
+JACOCO_PACKAGE_NAME := org.jacoco.agent.rt.internal
diff --git a/org.jacoco.agent.rt-0.7.5.201505241946-all.jar b/org.jacoco.agent.rt-0.7.5.201505241946-all.jar
deleted file mode 100644
index a9162556..00000000
--- a/org.jacoco.agent.rt-0.7.5.201505241946-all.jar
+++ /dev/null
Binary files differ
diff --git a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java
index 434fecdb..69ffc015 100644
--- a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java
+++ b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/Agent.java
@@ -121,7 +121,9 @@ public class Agent implements IAgent {
output = createAgentOutput();
output.startup(options, data);
if (options.getJmx()) {
- jmxRegistration = new JmxRegistration(this);
+// BEGIN android-change
+// jmxRegistration = new JmxRegistration(this);
+// END android-change
}
} catch (final Exception e) {
logger.logExeption(e);