jacoco libs dependency for instrumented libraries
On coverage builds, R8 will fail to properly optimize and fail the build
if ignore_warnings: false, because jacoco injects dependencies on
jacocoagent classes, but the jacocoagent library is not part of the
classpath libraries passed in to R8 in its arguments.
Instead we can add jacocoagent as a libs dependency for these modules so
that it will get pulled into the r8 flags.
Bug: 243903417
Test: add optimize.ignore_warnings: false to NetworkStackAppDefaults &&
make SKIP_ABI_CHECKS=true PRODUCT=cf_x86_phone-userdebug \
EMMA_INSTRUMENT=true EMMA_INSTRUMENT_FRAMEWORK=true \
CLANG_COVERAGE=true COVERAGE_PATHS="" \
TARGET_USERDATAIMAGE_PARTITION_SIZE=17179869184 \
SKIP_BOOT_JARS_CHECK=true \
NetworkStack
Change-Id: I71313b1fd35437ec52890f5c30b3fd1381c7c3d2
diff --git a/java/base.go b/java/base.go
index cf3b3d5..53f0f52 100644
--- a/java/base.go
+++ b/java/base.go
@@ -169,6 +169,8 @@
Output_params []string
}
+ // If true, then jacocoagent is automatically added as a libs dependency so that
+ // r8 will not strip instrumentation classes out of dexed libraries.
Instrument bool `blueprint:"mutated"`
// If true, then the module supports statically including the jacocoagent
// into the library.
@@ -787,6 +789,9 @@
} else if j.shouldInstrumentStatic(ctx) {
ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
}
+ if j.shouldInstrument(ctx) {
+ ctx.AddVariationDependencies(nil, libTag, "jacocoagent")
+ }
if j.useCompose() {
ctx.AddVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), kotlinPluginTag,