Merge "Add coverage flags for Clang coverage builds."
am: b6aeb14150
Change-Id: If7fc1974a3a930a9f1d610aed1fc1b9864efec32
This commit is contained in:
commit
195ed73e05
4 changed files with 44 additions and 13 deletions
|
@ -1027,6 +1027,10 @@ func (c *deviceConfig) NativeCoverageEnabled() bool {
|
||||||
return Bool(c.config.productVariables.NativeCoverage)
|
return Bool(c.config.productVariables.NativeCoverage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *deviceConfig) ClangCoverageEnabled() bool {
|
||||||
|
return Bool(c.config.productVariables.ClangCoverage)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
|
func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
|
||||||
coverage := false
|
coverage := false
|
||||||
if c.config.productVariables.CoveragePaths != nil {
|
if c.config.productVariables.CoveragePaths != nil {
|
||||||
|
|
|
@ -243,6 +243,7 @@ type productVariables struct {
|
||||||
TidyChecks *string `json:",omitempty"`
|
TidyChecks *string `json:",omitempty"`
|
||||||
|
|
||||||
NativeCoverage *bool `json:",omitempty"`
|
NativeCoverage *bool `json:",omitempty"`
|
||||||
|
ClangCoverage *bool `json:",omitempty"`
|
||||||
CoveragePaths []string `json:",omitempty"`
|
CoveragePaths []string `json:",omitempty"`
|
||||||
CoverageExcludePaths []string `json:",omitempty"`
|
CoverageExcludePaths []string `json:",omitempty"`
|
||||||
|
|
||||||
|
|
|
@ -1084,7 +1084,7 @@ func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
|
func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
|
||||||
return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
|
return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *apexBundle) PreventInstall() {
|
func (a *apexBundle) PreventInstall() {
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (cov *coverage) props() []interface{} {
|
||||||
return []interface{}{&cov.Properties}
|
return []interface{}{&cov.Properties}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getProfileLibraryName(ctx ModuleContextIntf) string {
|
func getGcovProfileLibraryName(ctx ModuleContextIntf) string {
|
||||||
// This function should only ever be called for a cc.Module, so the
|
// This function should only ever be called for a cc.Module, so the
|
||||||
// following statement should always succeed.
|
// following statement should always succeed.
|
||||||
if ctx.useSdk() {
|
if ctx.useSdk() {
|
||||||
|
@ -53,28 +53,47 @@ func getProfileLibraryName(ctx ModuleContextIntf) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getClangProfileLibraryName(ctx ModuleContextIntf) string {
|
||||||
|
if ctx.useSdk() {
|
||||||
|
return "libprofile-clang-extras_ndk"
|
||||||
|
} else {
|
||||||
|
return "libprofile-clang-extras"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps {
|
func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps {
|
||||||
if cov.Properties.NeedCoverageVariant {
|
if cov.Properties.NeedCoverageVariant {
|
||||||
ctx.AddVariationDependencies([]blueprint.Variation{
|
ctx.AddVariationDependencies([]blueprint.Variation{
|
||||||
{Mutator: "link", Variation: "static"},
|
{Mutator: "link", Variation: "static"},
|
||||||
}, coverageDepTag, getProfileLibraryName(ctx))
|
}, coverageDepTag, getGcovProfileLibraryName(ctx))
|
||||||
|
ctx.AddVariationDependencies([]blueprint.Variation{
|
||||||
|
{Mutator: "link", Variation: "static"},
|
||||||
|
}, coverageDepTag, getClangProfileLibraryName(ctx))
|
||||||
}
|
}
|
||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
|
func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
|
||||||
if !ctx.DeviceConfig().NativeCoverageEnabled() {
|
gcovCoverage := ctx.DeviceConfig().NativeCoverageEnabled()
|
||||||
|
clangCoverage := ctx.DeviceConfig().ClangCoverageEnabled()
|
||||||
|
|
||||||
|
if !gcovCoverage && !clangCoverage {
|
||||||
return flags, deps
|
return flags, deps
|
||||||
}
|
}
|
||||||
|
|
||||||
if cov.Properties.CoverageEnabled {
|
if cov.Properties.CoverageEnabled {
|
||||||
flags.Coverage = true
|
flags.Coverage = true
|
||||||
flags.Local.CommonFlags = append(flags.Local.CommonFlags, "--coverage", "-O0")
|
|
||||||
cov.linkCoverage = true
|
cov.linkCoverage = true
|
||||||
|
|
||||||
|
if gcovCoverage {
|
||||||
|
flags.Local.CommonFlags = append(flags.Local.CommonFlags, "--coverage", "-O0")
|
||||||
|
|
||||||
// Override -Wframe-larger-than and non-default optimization
|
// Override -Wframe-larger-than and non-default optimization
|
||||||
// flags that the module may use.
|
// flags that the module may use.
|
||||||
flags.Local.CFlags = append(flags.Local.CFlags, "-Wno-frame-larger-than=", "-O0")
|
flags.Local.CFlags = append(flags.Local.CFlags, "-Wno-frame-larger-than=", "-O0")
|
||||||
|
} else if clangCoverage {
|
||||||
|
flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-fprofile-instr-generate", "-fcoverage-mapping")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Even if we don't have coverage enabled, if any of our object files were compiled
|
// Even if we don't have coverage enabled, if any of our object files were compiled
|
||||||
|
@ -112,12 +131,19 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags
|
||||||
}
|
}
|
||||||
|
|
||||||
if cov.linkCoverage {
|
if cov.linkCoverage {
|
||||||
|
if gcovCoverage {
|
||||||
flags.Local.LdFlags = append(flags.Local.LdFlags, "--coverage")
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "--coverage")
|
||||||
|
|
||||||
coverage := ctx.GetDirectDepWithTag(getProfileLibraryName(ctx), coverageDepTag).(*Module)
|
coverage := ctx.GetDirectDepWithTag(getGcovProfileLibraryName(ctx), coverageDepTag).(*Module)
|
||||||
deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
|
||||||
|
|
||||||
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--wrap,getenv")
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--wrap,getenv")
|
||||||
|
} else if clangCoverage {
|
||||||
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "-fprofile-instr-generate")
|
||||||
|
|
||||||
|
coverage := ctx.GetDirectDepWithTag(getClangProfileLibraryName(ctx), coverageDepTag).(*Module)
|
||||||
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return flags, deps
|
return flags, deps
|
||||||
|
@ -125,7 +151,7 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags
|
||||||
|
|
||||||
func (cov *coverage) begin(ctx BaseModuleContext) {
|
func (cov *coverage) begin(ctx BaseModuleContext) {
|
||||||
// Coverage is disabled globally
|
// Coverage is disabled globally
|
||||||
if !ctx.DeviceConfig().NativeCoverageEnabled() {
|
if !ctx.DeviceConfig().NativeCoverageEnabled() && !ctx.DeviceConfig().ClangCoverageEnabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue