From 0038a8d374dc7f26b8e6d0f055c163405349e7cb Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 3 May 2022 00:28:40 +0000 Subject: Prevent non-app/non-test modules from statically including jacocoagent (cherry picked from commit 3953153c9e24e510237c14fd77ac58f5555c3738) Previously, the .impl library of java_sdk_library modules would end up with the jacocoagent statically included. That is because their Instrument flag was set to true when created by their parent. As that was before the deps were added that meant that they ended up with a static dependency on jacoagent (at least when UnbundledBuild() was true). That was not previously a problem because the .impl files were only used at build time. However, a recent change to make updatable-media statically include framework-media.impl (which statically included the jacocoagent classes) broke the coverage build because the jacocoagent classes are not in the permitted packages for the updatable-media. When instrumenting the bootclasspath the jacocoagent library is added to the art-bootclasspath-fragment. The jacocoagent should only be statically included in apps, or test apps. This change adds an extra flag to specify whether the module type supports statically including the jacocoagent. This is set to true by apps and test apps but not when the java_sdk_library creates the .impl java_library preventing it from statically including jacocoagent. Bug: 230967146 Bug: 229932396 Test: COVERAGE_MODULES=media \ PRODUCT=mainline_modules_x86 \ TARGET_BUILD_APPS=com.google.android.media \ vendor/google/build/build_unbundled_coverage_mainline_module.sh # Fails without this change, passes with it. Merged-In: Ic95cf11a05f59b67e623474ed3dd9be6b4442c42 Change-Id: Ic95cf11a05f59b67e623474ed3dd9be6b4442c42 --- java/app.go | 2 ++ java/base.go | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'java') diff --git a/java/app.go b/java/app.go index 2b52eab15..d0a1db031 100755 --- a/java/app.go +++ b/java/app.go @@ -900,6 +900,7 @@ func AndroidAppFactory() android.Module { module.Module.dexProperties.Optimize.Shrink = proptools.BoolPtr(true) module.Module.properties.Instrument = true + module.Module.properties.Supports_static_instrumentation = true module.Module.properties.Installable = proptools.BoolPtr(true) module.addHostAndDeviceProperties() @@ -1019,6 +1020,7 @@ func AndroidTestFactory() android.Module { module.Module.dexProperties.Optimize.EnabledByDefault = true module.Module.properties.Instrument = true + module.Module.properties.Supports_static_instrumentation = true module.Module.properties.Installable = proptools.BoolPtr(true) module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) module.appProperties.AlwaysPackageNativeLibs = true diff --git a/java/base.go b/java/base.go index 245ffbb3d..ff1ce8516 100644 --- a/java/base.go +++ b/java/base.go @@ -170,6 +170,9 @@ type CommonProperties struct { } Instrument bool `blueprint:"mutated"` + // If true, then the module supports statically including the jacocoagent + // into the library. + Supports_static_instrumentation bool `blueprint:"mutated"` // List of files to include in the META-INF/services folder of the resulting jar. Services []string `android:"path,arch_variant"` @@ -602,7 +605,8 @@ func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool { } func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool { - return j.shouldInstrument(ctx) && + return j.properties.Supports_static_instrumentation && + j.shouldInstrument(ctx) && (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") || ctx.Config().UnbundledBuild()) } -- cgit v1.2.3-59-g8ed1b