From 583691a0603940c114b882543089bd56790d25a3 Mon Sep 17 00:00:00 2001 From: Roland Levillain Date: Tue, 9 Jun 2020 13:07:36 +0100 Subject: Introduce product variables to select Java code coverage paths in Soong. Introduce product variables `JavaCoveragePaths` and `JavaCoverageExcludePaths` (resp. populated from environment variables `JAVA_COVERAGE_PATHS` and `JAVA_COVERAGE_EXCLUDE_PATHS`). Use them to control which Java modules are candidate for instrumentation based on their source path. By default (when `JavaCoveragePaths` is empty), have all Java module be candidate for instrumentation, to preserve the existing behavior. Test: export EMMA_INSTRUMENT=true \ && export EMMA_INSTRUMENT_FRAMEWORK=true \ && export JAVA_COVERAGE_PATHS=art \ && m Bug: 158212027 Bug: 156284897 Merged-In: Ibe9c1f41ed6110867411952689c5a7ad6536f277 Change-Id: Ibe9c1f41ed6110867411952689c5a7ad6536f277 --- android/config.go | 21 +++++++++++++++++++++ android/variable.go | 3 +++ java/java.go | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/android/config.go b/android/config.go index 92227cd2..40347e76 100644 --- a/android/config.go +++ b/android/config.go @@ -1037,6 +1037,27 @@ func (c *deviceConfig) SamplingPGO() bool { return Bool(c.config.productVariables.SamplingPGO) } +// JavaCoverageEnabledForPath returns whether Java code coverage is enabled for +// path. Coverage is enabled by default when the product variable +// JavaCoveragePaths is empty. If JavaCoveragePaths is not empty, coverage is +// enabled for any path which is part of this variable (and not part of the +// JavaCoverageExcludePaths product variable). Value "*" in JavaCoveragePaths +// represents any path. +func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool { + coverage := false + if c.config.productVariables.JavaCoveragePaths == nil || + InList("*", c.config.productVariables.JavaCoveragePaths) || + HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) { + coverage = true + } + if coverage && c.config.productVariables.JavaCoverageExcludePaths != nil { + if HasAnyPrefix(path, c.config.productVariables.JavaCoverageExcludePaths) { + coverage = false + } + } + return coverage +} + func (c *config) NativeLineCoverage() bool { return Bool(c.productVariables.NativeLineCoverage) } diff --git a/android/variable.go b/android/variable.go index 277304f7..fadfebcb 100644 --- a/android/variable.go +++ b/android/variable.go @@ -253,6 +253,9 @@ type productVariables struct { SamplingPGO *bool `json:",omitempty"` + JavaCoveragePaths []string `json:",omitempty"` + JavaCoverageExcludePaths []string `json:",omitempty"` + NativeLineCoverage *bool `json:",omitempty"` Native_coverage *bool `json:",omitempty"` ClangCoverage *bool `json:",omitempty"` diff --git a/java/java.go b/java/java.go index 90e9b1f6..1560e186 100644 --- a/java/java.go +++ b/java/java.go @@ -627,7 +627,9 @@ type jniLib struct { } func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool { - return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") + return j.properties.Instrument && + ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") && + ctx.DeviceConfig().JavaCoverageEnabledForPath(ctx.ModuleDir()) } func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool { -- cgit v1.2.3