Add gcov coverage support to Rust modules.
This adds gcov coverage support for Rust device library and binary
modules (including test modules). Support is provided to pass Rust
static library gcno files to CC modules and visa versa.
Additional changes:
* Begin mutator added for Rust modules.
* SuffixInList added to android package.
* CoverageEnabled added to Coverage interface.
* CoverageFiles added to LinkableLibrary interface.
* Fix in coverage mutator for non-CC modules which marked the wrong
variant as the coverage variant.
* Added coverage libraries to the cc.GatherRequiredDepsForTest.
Bug: 146448203
Test: NATIVE_COVERAGE=true COVERAGE_PATHS='*' m -j <rust_module>
Change-Id: If20728bdde42a1dd544a35a40f0d981b80a5835f
diff --git a/cc/coverage.go b/cc/coverage.go
index bde07fd..cc9a1ad 100644
--- a/cc/coverage.go
+++ b/cc/coverage.go
@@ -65,10 +65,10 @@
if cov.Properties.NeedCoverageVariant {
ctx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
- }, coverageDepTag, getGcovProfileLibraryName(ctx))
+ }, CoverageDepTag, getGcovProfileLibraryName(ctx))
ctx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
- }, coverageDepTag, getClangProfileLibraryName(ctx))
+ }, CoverageDepTag, getClangProfileLibraryName(ctx))
}
return deps
}
@@ -134,14 +134,14 @@
if gcovCoverage {
flags.Local.LdFlags = append(flags.Local.LdFlags, "--coverage")
- coverage := ctx.GetDirectDepWithTag(getGcovProfileLibraryName(ctx), coverageDepTag).(*Module)
+ coverage := ctx.GetDirectDepWithTag(getGcovProfileLibraryName(ctx), CoverageDepTag).(*Module)
deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
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)
+ coverage := ctx.GetDirectDepWithTag(getClangProfileLibraryName(ctx), CoverageDepTag).(*Module)
deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
}
}
@@ -150,25 +150,30 @@
}
func (cov *coverage) begin(ctx BaseModuleContext) {
+ if ctx.Host() {
+ // TODO(dwillemsen): because of -nodefaultlibs, we must depend on libclang_rt.profile-*.a
+ // Just turn off for now.
+ } else {
+ cov.Properties = SetCoverageProperties(ctx, cov.Properties, ctx.nativeCoverage(), ctx.useSdk(), ctx.sdkVersion())
+ }
+}
+
+func SetCoverageProperties(ctx android.BaseModuleContext, properties CoverageProperties, moduleTypeHasCoverage bool,
+ useSdk bool, sdkVersion string) CoverageProperties {
// Coverage is disabled globally
if !ctx.DeviceConfig().NativeCoverageEnabled() && !ctx.DeviceConfig().ClangCoverageEnabled() {
- return
+ return properties
}
var needCoverageVariant bool
var needCoverageBuild bool
- if ctx.Host() {
- // TODO(dwillemsen): because of -nodefaultlibs, we must depend on libclang_rt.profile-*.a
- // Just turn off for now.
- } else if !ctx.nativeCoverage() {
- // Native coverage is not supported for this module type.
- } else {
+ if moduleTypeHasCoverage {
// Check if Native_coverage is set to false. This property defaults to true.
- needCoverageVariant = BoolDefault(cov.Properties.Native_coverage, true)
- if sdk_version := ctx.sdkVersion(); ctx.useSdk() && sdk_version != "current" {
+ needCoverageVariant = BoolDefault(properties.Native_coverage, true)
+ if useSdk && sdkVersion != "current" {
// 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(sdkVersion); err == nil && fromApi < 23 {
needCoverageVariant = false
}
}
@@ -179,8 +184,10 @@
}
}
- cov.Properties.NeedCoverageBuild = needCoverageBuild
- cov.Properties.NeedCoverageVariant = needCoverageVariant
+ properties.NeedCoverageBuild = needCoverageBuild
+ properties.NeedCoverageVariant = needCoverageVariant
+
+ return properties
}
// Coverage is an interface for non-CC modules to implement to be mutated for coverage
@@ -190,6 +197,7 @@
PreventInstall()
HideFromMake()
MarkAsCoverageVariant(bool)
+ EnableCoverageIfNeeded()
}
func coverageMutator(mctx android.BottomUpMutatorContext) {
@@ -212,14 +220,17 @@
m[1].(*Module).coverage.Properties.IsCoverageVariant = true
}
} else if cov, ok := mctx.Module().(Coverage); ok && cov.IsNativeCoverageNeeded(mctx) {
- // APEX modules fall here
+ // APEX and Rust modules fall here
// Note: variant "" is also created because an APEX can be depended on by another
// module which are split into "" and "cov" variants. e.g. when cc_test refers
// to an APEX via 'data' property.
m := mctx.CreateVariations("", "cov")
- m[0].(Coverage).MarkAsCoverageVariant(true)
+ m[0].(Coverage).MarkAsCoverageVariant(false)
m[0].(Coverage).PreventInstall()
m[0].(Coverage).HideFromMake()
+
+ m[1].(Coverage).MarkAsCoverageVariant(true)
+ m[1].(Coverage).EnableCoverageIfNeeded()
}
}