Populate android_binary coverage metadata information with --experimental_java_coverage
@@ -607,7 +607,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
new ApkInfo(
zipAlignedApk,
unsignedApk,
- androidCommon.getInstrumentedJar(),
+ getCoverageInstrumentationJarForApk(ruleContext, androidCommon),
resourceApk.getManifest(),
AndroidCommon.getApkDebugSigningKey(ruleContext)))
.addNativeDeclaredProvider(new AndroidPreDexJarProvider(jarToDex))
@@ -617,6 +617,24 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
.addOutputGroup("android_deploy_info", deployInfo);
}
+ /**
+ * For coverage builds, this returns a Jar containing <b>un</b>instrumented bytecode for the
+ * coverage reporter's consumption. This Jar is often confusingly called <i>instrumented</i>.
+ * This method simply returns the deploy Jar when "new" coverage is used, otherwise the
+ * traditional "instrumented" Jar. Note the deploy Jar is built anyway for Android binaries.
+ *
+ * @return A Jar containing uninstrumented bytecode or {@code null} for non-coverage builds
+ */
+ @Nullable
+ private static Artifact getCoverageInstrumentationJarForApk(
+ RuleContext ruleContext, AndroidCommon androidCommon) throws InterruptedException {
+ if (ruleContext.getConfiguration().isCodeCoverageEnabled()
+ && ruleContext.getConfiguration().isExperimentalJavaCoverage()) {
+ return ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_BINARY_DEPLOY_JAR);
+ }
+ return androidCommon.getInstrumentedJar();
+ }
+
private static NestedSet<Artifact> getLibraryResourceJars(RuleContext ruleContext) {
Iterable<AndroidLibraryResourceClassJarProvider> libraryResourceJarProviders =
AndroidCommon.getTransitivePrerequisites(
