diff options
author | Dan Willemsen <dwillemsen@google.com> | 2017-02-09 16:16:31 -0800 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2017-02-14 13:05:48 -0800 |
commit | 581341d4f2752a1f2823173167d30ddb30db5932 (patch) | |
tree | c8a4413cdc0a81ca2d934442d71b55a6e5abfec9 /cc/cc.go | |
parent | e13374d3c1e33176ac229317505c5e2b4d8d5240 (diff) | |
download | build_soong-581341d4f2752a1f2823173167d30ddb30db5932.tar.gz build_soong-581341d4f2752a1f2823173167d30ddb30db5932.tar.bz2 build_soong-581341d4f2752a1f2823173167d30ddb30db5932.zip |
Native Coverage support in Soong (gcov)
This is configured the same as make -- a global NATIVE_COVERAGE=true
flag to allow native coverage, then COVERAGE_PATHS=path1,path2,... to
turn it on for certain paths.
There are .gcnodir files exported to Make and saved in $OUT/coverage/...
files which are `ar` archives containing all of the compiler-produced
.gcno files for a particular executable / shared library.
Unlike the Make implementation, this only passes links the helper
library (automatically through --coverage) when one of the object files
or static libraries being used actually has coverage enabled.
Host support is currently disabled, since we set -nodefaultlibs, which
prevents libclang_rt.profile-*.a from being picked up automatically.
Bug: 32749731
Test: NATIVE_COVERAGE=true COVERAGE_PATHS=system/core/libcutils m -j libbacktrace libutils tombstoned
$OUT/coverage/system/lib*/libcutils.gcnodir looks correct (self)
$OUT/coverage/system/lib*/libbacktrace.gcnodir looks correct (static)
$OUT/coverage/system/lib*/libutils.gcnodir doesn't exist (shared)
$OUT/coverage/system/bin/tombstoned.gcnodir looks correct (executable)
Test: NATIVE_COVERAGE=true COVERAGE_PATHS=external/libcxxabi m -j libc++
Confirm that $OUT/coverage/system/lib*/libc++.gcnodir looks correct (whole_static_libs)
Change-Id: I48aaa0ba8d76e50e9c2d1151421c0c6dc8ed79a9
Diffstat (limited to 'cc/cc.go')
-rw-r--r-- | cc/cc.go | 36 |
1 files changed, 34 insertions, 2 deletions
@@ -46,6 +46,8 @@ func init() { ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan)) ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel() + + ctx.BottomUp("coverage", coverageLinkingMutator).Parallel() }) pctx.Import("android/soong/cc/config") @@ -78,6 +80,7 @@ type PathDeps struct { // Paths to .o files Objs Objects + StaticLibObjs Objects WholeStaticLibObjs Objects // Paths to generated source files @@ -108,6 +111,7 @@ type Flags struct { Toolchain config.Toolchain Clang bool Tidy bool + Coverage bool RequiredInstructionSet string DynamicLinker string @@ -144,8 +148,7 @@ type BaseProperties struct { } type UnusedProperties struct { - Native_coverage *bool - Tags []string + Tags []string } type ModuleContextIntf interface { @@ -261,6 +264,7 @@ type Module struct { installer installer stl *stl sanitize *sanitize + coverage *coverage androidMkSharedLibDeps []string @@ -291,6 +295,9 @@ func (c *Module) Init() (blueprint.Module, []interface{}) { if c.sanitize != nil { props = append(props, c.sanitize.props()...) } + if c.coverage != nil { + props = append(props, c.coverage.props()...) + } for _, feature := range c.features { props = append(props, feature.props()...) } @@ -411,6 +418,7 @@ func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Mo } module.stl = &stl{} module.sanitize = &sanitize{} + module.coverage = &coverage{} return module } @@ -454,6 +462,9 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { if c.sanitize != nil { flags = c.sanitize.flags(ctx, flags) } + if c.coverage != nil { + flags = c.coverage.flags(ctx, flags) + } for _, feature := range c.features { flags = feature.flags(ctx, flags) } @@ -525,6 +536,9 @@ func (c *Module) begin(ctx BaseModuleContext) { if c.sanitize != nil { c.sanitize.begin(ctx) } + if c.coverage != nil { + c.coverage.begin(ctx) + } for _, feature := range c.features { feature.begin(ctx) } @@ -563,6 +577,9 @@ func (c *Module) deps(ctx DepsContext) Deps { if c.sanitize != nil { deps = c.sanitize.deps(ctx, deps) } + if c.coverage != nil { + deps = c.coverage.deps(ctx, deps) + } for _, feature := range c.features { deps = feature.deps(ctx, deps) } @@ -951,6 +968,20 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { depPaths.CrtEnd = linkFile } + switch tag { + case staticDepTag, staticExportDepTag, lateStaticDepTag: + staticLib, ok := cc.linker.(libraryInterface) + if !ok || !staticLib.static() { + ctx.ModuleErrorf("module %q not a static library", name) + return + } + + // When combining coverage files for shared libraries and executables, coverage files + // in static libraries act as if they were whole static libraries. + depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles, + staticLib.objs().coverageFiles...) + } + if ptr != nil { if !linkFile.Valid() { ctx.ModuleErrorf("module %q missing output file", name) @@ -1024,6 +1055,7 @@ func DefaultsFactory(props ...interface{}) (blueprint.Module, []interface{}) { &StripProperties{}, &InstallerProperties{}, &TidyProperties{}, + &CoverageProperties{}, ) return android.InitDefaultsModule(module, module, props...) |