Instrument impl library belonging to apexes
https://r.android.com/3094444 has removed instrumentation from the
implementation library of the java sdk library. However, given that the
top level java sdk library was not being instrumented before removing
the compilation action, there is no way to get the coverage data for the
java sdk library included in the mainline modules with the
aforementioned change.
As seen in b/340174053, instrumenting all impl libraries by default
may lead to double instrumentation execution time error in some edge
cases (especially with make to soong dependency).
Given the above two conditions, this change allows instrumentation for
the implementation library of the java sdk library that belongs to
apex(es).
Test: lunch husky-trunk_staging-userdebug && EMMA_INSTRUMENT=true EMMA_INSTRUMENT_FRAMEWORK=true m droid dist
Test: DIST_DIR=dist_dir TARGET_BUILD_VARIANT=userdebug PRODUCT=mainline_modules_x86_64 COVERAGE_MODULES="uwb" ./vendor/google/build/build_unbundled_coverage_mainline_module.sh
Bug: 341170242
Change-Id: I175e02f61e139296f5a177e6fc1c3ded760ac028
diff --git a/java/base.go b/java/base.go
index 0c28671..48a02b8 100644
--- a/java/base.go
+++ b/java/base.go
@@ -715,7 +715,12 @@
// doesn't make sense) or framework libraries (e.g. libraries found in the InstrumentFrameworkModules list) unless EMMA_INSTRUMENT_FRAMEWORK is true.
apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
isJacocoAgent := ctx.ModuleName() == "jacocoagent"
- if j.DirectlyInAnyApex() && !isJacocoAgent && !apexInfo.IsForPlatform() {
+
+ isApexVariantSdkLibImplLib := j.SdkLibraryName() != nil &&
+ strings.HasSuffix(j.Name(), ".impl") &&
+ len(apexInfo.InApexVariants) > 0
+
+ if (j.DirectlyInAnyApex() || isApexVariantSdkLibImplLib) && !isJacocoAgent && !apexInfo.IsForPlatform() {
if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
return true
} else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {