Refactor coverage support
Bug: http://b/128524141 The goal is to add a static library (libprofile-extras) to modules that require coverage. Since the coverageMutator is a post-deps mutator, the results of the coverageMutator are not available when the dependencies get constructed in deps(). This change moves the detection from the coverageMutator to begin(). Test: m NATIVE_COVERAGE=true COVERAGE_PATHS=* Test: blueline_coverage target in internal branch (using forrest) Change-Id: I4e7c8b31ed5060642c6218ea33c532a0f6619967
This commit is contained in:
@@ -23,6 +23,9 @@ import (
|
|||||||
type CoverageProperties struct {
|
type CoverageProperties struct {
|
||||||
Native_coverage *bool
|
Native_coverage *bool
|
||||||
|
|
||||||
|
NeedCoverageVariant bool `blueprint:"mutated"`
|
||||||
|
NeedCoverageBuild bool `blueprint:"mutated"`
|
||||||
|
|
||||||
CoverageEnabled bool `blueprint:"mutated"`
|
CoverageEnabled bool `blueprint:"mutated"`
|
||||||
IsCoverageVariant bool `blueprint:"mutated"`
|
IsCoverageVariant bool `blueprint:"mutated"`
|
||||||
}
|
}
|
||||||
@@ -38,8 +41,6 @@ func (cov *coverage) props() []interface{} {
|
|||||||
return []interface{}{&cov.Properties}
|
return []interface{}{&cov.Properties}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cov *coverage) begin(ctx BaseModuleContext) {}
|
|
||||||
|
|
||||||
func (cov *coverage) deps(ctx BaseModuleContext, deps Deps) Deps {
|
func (cov *coverage) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
@@ -100,40 +101,47 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
func coverageMutator(mctx android.BottomUpMutatorContext) {
|
func (cov *coverage) begin(ctx BaseModuleContext) {
|
||||||
// Coverage is disabled globally
|
// Coverage is disabled globally
|
||||||
if !mctx.DeviceConfig().NativeCoverageEnabled() {
|
if !ctx.DeviceConfig().NativeCoverageEnabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if c, ok := mctx.Module().(*Module); ok {
|
var needCoverageVariant bool
|
||||||
var needCoverageVariant bool
|
var needCoverageBuild bool
|
||||||
var needCoverageBuild bool
|
|
||||||
|
|
||||||
if mctx.Host() {
|
if ctx.Host() {
|
||||||
// TODO(dwillemsen): because of -nodefaultlibs, we must depend on libclang_rt.profile-*.a
|
// TODO(dwillemsen): because of -nodefaultlibs, we must depend on libclang_rt.profile-*.a
|
||||||
// Just turn off for now.
|
// Just turn off for now.
|
||||||
} else if c.IsStubs() {
|
} else if ctx.isStubs() {
|
||||||
// Do not enable coverage for platform stub libraries
|
// Do not enable coverage for platform stub libraries
|
||||||
} else if c.isNDKStubLibrary() {
|
} else if ctx.isNDKStubLibrary() {
|
||||||
// Do not enable coverage for NDK stub libraries
|
// Do not enable coverage for NDK stub libraries
|
||||||
} else if c.coverage != nil {
|
} else {
|
||||||
// Check if Native_coverage is set to false. This property defaults to true.
|
// Check if Native_coverage is set to false. This property defaults to true.
|
||||||
needCoverageVariant = BoolDefault(c.coverage.Properties.Native_coverage, true)
|
needCoverageVariant = BoolDefault(cov.Properties.Native_coverage, true)
|
||||||
|
|
||||||
if sdk_version := String(c.Properties.Sdk_version); sdk_version != "current" {
|
if sdk_version := ctx.sdkVersion(); ctx.useSdk() && sdk_version != "current" {
|
||||||
// Native coverage is not supported for SDK versions < 23
|
// Native coverage is not supported for SDK versions < 23
|
||||||
if fromApi, err := strconv.Atoi(sdk_version); err == nil && fromApi < 23 {
|
if fromApi, err := strconv.Atoi(sdk_version); err == nil && fromApi < 23 {
|
||||||
needCoverageVariant = false
|
needCoverageVariant = false
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if needCoverageVariant {
|
|
||||||
// Coverage variant is actually built with coverage if enabled for its module path
|
|
||||||
needCoverageBuild = mctx.DeviceConfig().CoverageEnabledForPath(mctx.ModuleDir())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if needCoverageVariant {
|
||||||
|
// Coverage variant is actually built with coverage if enabled for its module path
|
||||||
|
needCoverageBuild = ctx.DeviceConfig().CoverageEnabledForPath(ctx.ModuleDir())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cov.Properties.NeedCoverageBuild = needCoverageBuild
|
||||||
|
cov.Properties.NeedCoverageVariant = needCoverageVariant
|
||||||
|
}
|
||||||
|
|
||||||
|
func coverageMutator(mctx android.BottomUpMutatorContext) {
|
||||||
|
if c, ok := mctx.Module().(*Module); ok && c.coverage != nil {
|
||||||
|
needCoverageVariant := c.coverage.Properties.NeedCoverageVariant
|
||||||
|
needCoverageBuild := c.coverage.Properties.NeedCoverageBuild
|
||||||
if needCoverageVariant {
|
if needCoverageVariant {
|
||||||
m := mctx.CreateVariations("", "cov")
|
m := mctx.CreateVariations("", "cov")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user