Use a default exclude filter for JaCoCo in Soong.

Instrumented builds should exclude certain classes from instrumenation
by default. (e.g. JaCoCo itself) Leverage the existing
DefaultJacocoExclusionFilter to do this.

Note: Two different default filters exist now (one for Make and one for
Soong), as they have different wildcard rules.

Test: EMMA_INSTRUMENT=true EMMA_INSTRUMENT_STATIC=true m -j32
TeleService and inspected the resulting temporary jar that was
instrumented to confirm that anything from org/jacoco was excluded.
Bug: 159748844

Change-Id: I5466b0a03957edfbe53971d5d1a7729fdb8337db
Merged-In: I5466b0a03957edfbe53971d5d1a7729fdb8337db
This commit is contained in:
Chris Gross 2020-07-01 13:21:14 +00:00 committed by Allen Hair
parent 63d687989d
commit 03f3a9c146
4 changed files with 7 additions and 4 deletions

View File

@ -1053,7 +1053,7 @@ func (c *deviceConfig) SamplingPGO() bool {
// represents any path. // represents any path.
func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool { func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool {
coverage := false coverage := false
if c.config.productVariables.JavaCoveragePaths == nil || if len(c.config.productVariables.JavaCoveragePaths) == 0 ||
InList("*", c.config.productVariables.JavaCoveragePaths) || InList("*", c.config.productVariables.JavaCoveragePaths) ||
HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) { HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) {
coverage = true coverage = true

View File

@ -34,7 +34,8 @@ var (
DefaultLambdaStubsLibrary = "core-lambda-stubs" DefaultLambdaStubsLibrary = "core-lambda-stubs"
SdkLambdaStubsPath = "prebuilts/sdk/tools/core-lambda-stubs.jar" SdkLambdaStubsPath = "prebuilts/sdk/tools/core-lambda-stubs.jar"
DefaultJacocoExcludeFilter = []string{"org.junit.*", "org.jacoco.*", "org.mockito.*"} DefaultMakeJacocoExcludeFilter = []string{"org.junit.*", "org.jacoco.*", "org.mockito.*"}
DefaultJacocoExcludeFilter = []string{"org.junit.**", "org.jacoco.**", "org.mockito.**"}
InstrumentFrameworkModules = []string{ InstrumentFrameworkModules = []string{
"framework", "framework",

View File

@ -64,7 +64,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("ZIPSYNC", "${ZipSyncCmd}") ctx.Strict("ZIPSYNC", "${ZipSyncCmd}")
ctx.Strict("JACOCO_CLI_JAR", "${JacocoCLIJar}") ctx.Strict("JACOCO_CLI_JAR", "${JacocoCLIJar}")
ctx.Strict("DEFAULT_JACOCO_EXCLUDE_FILTER", strings.Join(DefaultJacocoExcludeFilter, ",")) ctx.Strict("DEFAULT_JACOCO_EXCLUDE_FILTER", strings.Join(DefaultMakeJacocoExcludeFilter, ","))
ctx.Strict("EXTRACT_JAR_PACKAGES", "${ExtractJarPackagesCmd}") ctx.Strict("EXTRACT_JAR_PACKAGES", "${ExtractJarPackagesCmd}")

View File

@ -25,6 +25,7 @@ import (
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
"android/soong/android" "android/soong/android"
"android/soong/java/config"
) )
var ( var (
@ -76,7 +77,8 @@ func (j *Module) jacocoModuleToZipCommand(ctx android.ModuleContext) string {
if err != nil { if err != nil {
ctx.PropertyErrorf("jacoco.include_filter", "%s", err.Error()) ctx.PropertyErrorf("jacoco.include_filter", "%s", err.Error())
} }
excludes, err := jacocoFiltersToSpecs(j.properties.Jacoco.Exclude_filter) // Also include the default list of classes to exclude from instrumentation.
excludes, err := jacocoFiltersToSpecs(append(j.properties.Jacoco.Exclude_filter, config.DefaultJacocoExcludeFilter...))
if err != nil { if err != nil {
ctx.PropertyErrorf("jacoco.exclude_filter", "%s", err.Error()) ctx.PropertyErrorf("jacoco.exclude_filter", "%s", err.Error())
} }