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
This commit is contained in:
@@ -118,6 +118,7 @@ bootstrap_go_package {
|
|||||||
"cc/builder.go",
|
"cc/builder.go",
|
||||||
"cc/cc.go",
|
"cc/cc.go",
|
||||||
"cc/check.go",
|
"cc/check.go",
|
||||||
|
"cc/coverage.go",
|
||||||
"cc/gen.go",
|
"cc/gen.go",
|
||||||
"cc/makevars.go",
|
"cc/makevars.go",
|
||||||
"cc/prebuilt.go",
|
"cc/prebuilt.go",
|
||||||
|
@@ -471,3 +471,18 @@ func (c *deviceConfig) VndkVersion() string {
|
|||||||
func (c *deviceConfig) BtConfigIncludeDir() string {
|
func (c *deviceConfig) BtConfigIncludeDir() string {
|
||||||
return String(c.config.ProductVariables.BtConfigIncludeDir)
|
return String(c.config.ProductVariables.BtConfigIncludeDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *deviceConfig) NativeCoverageEnabled() bool {
|
||||||
|
return Bool(c.config.ProductVariables.NativeCoverage)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
|
||||||
|
if c.config.ProductVariables.CoveragePaths != nil {
|
||||||
|
for _, prefix := range *c.config.ProductVariables.CoveragePaths {
|
||||||
|
if strings.HasPrefix(path, prefix) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
@@ -131,6 +131,9 @@ type productVariables struct {
|
|||||||
ClangTidy *bool `json:",omitempty"`
|
ClangTidy *bool `json:",omitempty"`
|
||||||
TidyChecks *string `json:",omitempty"`
|
TidyChecks *string `json:",omitempty"`
|
||||||
|
|
||||||
|
NativeCoverage *bool `json:",omitempty"`
|
||||||
|
CoveragePaths *[]string `json:",omitempty"`
|
||||||
|
|
||||||
DevicePrefer32BitExecutables *bool `json:",omitempty"`
|
DevicePrefer32BitExecutables *bool `json:",omitempty"`
|
||||||
HostPrefer32BitExecutables *bool `json:",omitempty"`
|
HostPrefer32BitExecutables *bool `json:",omitempty"`
|
||||||
|
|
||||||
|
@@ -111,6 +111,10 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
|
|||||||
|
|
||||||
fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
|
fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
|
||||||
|
|
||||||
|
if library.coverageOutputFile.Valid() {
|
||||||
|
fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", library.coverageOutputFile.String())
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -145,6 +149,9 @@ func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.Andr
|
|||||||
fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS := "+strings.Join(binary.symlinks, " "))
|
fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS := "+strings.Join(binary.symlinks, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if binary.coverageOutputFile.Valid() {
|
||||||
|
fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", binary.coverageOutputFile.String())
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -79,6 +79,9 @@ type binaryDecorator struct {
|
|||||||
|
|
||||||
// Names of symlinks to be installed for use in LOCAL_MODULE_SYMLINKS
|
// Names of symlinks to be installed for use in LOCAL_MODULE_SYMLINKS
|
||||||
symlinks []string
|
symlinks []string
|
||||||
|
|
||||||
|
// Output archive of gcno coverage information
|
||||||
|
coverageOutputFile android.OptionalPath
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ linker = (*binaryDecorator)(nil)
|
var _ linker = (*binaryDecorator)(nil)
|
||||||
@@ -299,6 +302,10 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
|
|||||||
deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
|
deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
|
||||||
builderFlags, outputFile)
|
builderFlags, outputFile)
|
||||||
|
|
||||||
|
objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...)
|
||||||
|
objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...)
|
||||||
|
binary.coverageOutputFile = TransformCoverageFilesToLib(ctx, objs, builderFlags, binary.getStem(ctx))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -198,6 +198,7 @@ type builderFlags struct {
|
|||||||
toolchain config.Toolchain
|
toolchain config.Toolchain
|
||||||
clang bool
|
clang bool
|
||||||
tidy bool
|
tidy bool
|
||||||
|
coverage bool
|
||||||
|
|
||||||
groupStaticLibs bool
|
groupStaticLibs bool
|
||||||
|
|
||||||
@@ -207,21 +208,24 @@ type builderFlags struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Objects struct {
|
type Objects struct {
|
||||||
objFiles android.Paths
|
objFiles android.Paths
|
||||||
tidyFiles android.Paths
|
tidyFiles android.Paths
|
||||||
|
coverageFiles android.Paths
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Objects) Copy() Objects {
|
func (a Objects) Copy() Objects {
|
||||||
return Objects{
|
return Objects{
|
||||||
objFiles: append(android.Paths{}, a.objFiles...),
|
objFiles: append(android.Paths{}, a.objFiles...),
|
||||||
tidyFiles: append(android.Paths{}, a.tidyFiles...),
|
tidyFiles: append(android.Paths{}, a.tidyFiles...),
|
||||||
|
coverageFiles: append(android.Paths{}, a.coverageFiles...),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Objects) Append(b Objects) Objects {
|
func (a Objects) Append(b Objects) Objects {
|
||||||
return Objects{
|
return Objects{
|
||||||
objFiles: append(a.objFiles, b.objFiles...),
|
objFiles: append(a.objFiles, b.objFiles...),
|
||||||
tidyFiles: append(a.tidyFiles, b.tidyFiles...),
|
tidyFiles: append(a.tidyFiles, b.tidyFiles...),
|
||||||
|
coverageFiles: append(a.coverageFiles, b.coverageFiles...),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,6 +238,10 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
|
|||||||
if flags.tidy && flags.clang {
|
if flags.tidy && flags.clang {
|
||||||
tidyFiles = make(android.Paths, 0, len(srcFiles))
|
tidyFiles = make(android.Paths, 0, len(srcFiles))
|
||||||
}
|
}
|
||||||
|
var coverageFiles android.Paths
|
||||||
|
if flags.coverage {
|
||||||
|
coverageFiles = make(android.Paths, 0, len(srcFiles))
|
||||||
|
}
|
||||||
|
|
||||||
cflags := flags.globalFlags + " " + flags.cFlags + " " + flags.conlyFlags
|
cflags := flags.globalFlags + " " + flags.cFlags + " " + flags.conlyFlags
|
||||||
cppflags := flags.globalFlags + " " + flags.cFlags + " " + flags.cppFlags
|
cppflags := flags.globalFlags + " " + flags.cFlags + " " + flags.cppFlags
|
||||||
@@ -268,12 +276,14 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
|
|||||||
var moduleCflags string
|
var moduleCflags string
|
||||||
var ccCmd string
|
var ccCmd string
|
||||||
tidy := flags.tidy && flags.clang
|
tidy := flags.tidy && flags.clang
|
||||||
|
coverage := flags.coverage
|
||||||
|
|
||||||
switch srcFile.Ext() {
|
switch srcFile.Ext() {
|
||||||
case ".S", ".s":
|
case ".S", ".s":
|
||||||
ccCmd = "gcc"
|
ccCmd = "gcc"
|
||||||
moduleCflags = asflags
|
moduleCflags = asflags
|
||||||
tidy = false
|
tidy = false
|
||||||
|
coverage = false
|
||||||
case ".c":
|
case ".c":
|
||||||
ccCmd = "gcc"
|
ccCmd = "gcc"
|
||||||
moduleCflags = cflags
|
moduleCflags = cflags
|
||||||
@@ -300,11 +310,19 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
|
|||||||
ccCmd = gccCmd(flags.toolchain, ccCmd)
|
ccCmd = gccCmd(flags.toolchain, ccCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var implicitOutputs android.WritablePaths
|
||||||
|
if coverage {
|
||||||
|
gcnoFile := android.ObjPathWithExt(ctx, subdir, srcFile, "gcno")
|
||||||
|
implicitOutputs = append(implicitOutputs, gcnoFile)
|
||||||
|
coverageFiles = append(coverageFiles, gcnoFile)
|
||||||
|
}
|
||||||
|
|
||||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||||
Rule: cc,
|
Rule: cc,
|
||||||
Output: objFile,
|
Output: objFile,
|
||||||
Input: srcFile,
|
ImplicitOutputs: implicitOutputs,
|
||||||
OrderOnly: deps,
|
Input: srcFile,
|
||||||
|
OrderOnly: deps,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"cFlags": moduleCflags,
|
"cFlags": moduleCflags,
|
||||||
"ccCmd": ccCmd,
|
"ccCmd": ccCmd,
|
||||||
@@ -332,8 +350,9 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Objects{
|
return Objects{
|
||||||
objFiles: objFiles,
|
objFiles: objFiles,
|
||||||
tidyFiles: tidyFiles,
|
tidyFiles: tidyFiles,
|
||||||
|
coverageFiles: coverageFiles,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,6 +360,11 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
|
|||||||
func TransformObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
|
func TransformObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
|
||||||
flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths) {
|
flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths) {
|
||||||
|
|
||||||
|
if ctx.Darwin() {
|
||||||
|
transformDarwinObjToStaticLib(ctx, objFiles, flags, outputFile, deps)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
arCmd := gccCmd(flags.toolchain, "ar")
|
arCmd := gccCmd(flags.toolchain, "ar")
|
||||||
arFlags := "crsPD"
|
arFlags := "crsPD"
|
||||||
|
|
||||||
@@ -360,7 +384,7 @@ func TransformObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
|
|||||||
// darwin. The darwin ar tool doesn't support @file for list files, and has a
|
// darwin. The darwin ar tool doesn't support @file for list files, and has a
|
||||||
// very small command line length limit, so we have to split the ar into multiple
|
// very small command line length limit, so we have to split the ar into multiple
|
||||||
// steps, each appending to the previous one.
|
// steps, each appending to the previous one.
|
||||||
func TransformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
|
func transformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
|
||||||
flags builderFlags, outputPath android.ModuleOutPath, deps android.Paths) {
|
flags builderFlags, outputPath android.ModuleOutPath, deps android.Paths) {
|
||||||
|
|
||||||
arFlags := "cqs"
|
arFlags := "cqs"
|
||||||
@@ -599,6 +623,20 @@ func TransformDarwinStrip(ctx android.ModuleContext, inputFile android.Path,
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TransformCoverageFilesToLib(ctx android.ModuleContext,
|
||||||
|
inputs Objects, flags builderFlags, baseName string) android.OptionalPath {
|
||||||
|
|
||||||
|
if len(inputs.coverageFiles) > 0 {
|
||||||
|
outputFile := android.PathForModuleOut(ctx, baseName+".gcnodir")
|
||||||
|
|
||||||
|
TransformObjToStaticLib(ctx, inputs.coverageFiles, flags, outputFile, nil)
|
||||||
|
|
||||||
|
return android.OptionalPathForPath(outputFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
return android.OptionalPath{}
|
||||||
|
}
|
||||||
|
|
||||||
func CopyGccLib(ctx android.ModuleContext, libName string,
|
func CopyGccLib(ctx android.ModuleContext, libName string,
|
||||||
flags builderFlags, outputFile android.WritablePath) {
|
flags builderFlags, outputFile android.WritablePath) {
|
||||||
|
|
||||||
|
36
cc/cc.go
36
cc/cc.go
@@ -46,6 +46,8 @@ func init() {
|
|||||||
|
|
||||||
ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
|
ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
|
||||||
ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
|
ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
|
||||||
|
|
||||||
|
ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
|
||||||
})
|
})
|
||||||
|
|
||||||
pctx.Import("android/soong/cc/config")
|
pctx.Import("android/soong/cc/config")
|
||||||
@@ -78,6 +80,7 @@ type PathDeps struct {
|
|||||||
|
|
||||||
// Paths to .o files
|
// Paths to .o files
|
||||||
Objs Objects
|
Objs Objects
|
||||||
|
StaticLibObjs Objects
|
||||||
WholeStaticLibObjs Objects
|
WholeStaticLibObjs Objects
|
||||||
|
|
||||||
// Paths to generated source files
|
// Paths to generated source files
|
||||||
@@ -108,6 +111,7 @@ type Flags struct {
|
|||||||
Toolchain config.Toolchain
|
Toolchain config.Toolchain
|
||||||
Clang bool
|
Clang bool
|
||||||
Tidy bool
|
Tidy bool
|
||||||
|
Coverage bool
|
||||||
|
|
||||||
RequiredInstructionSet string
|
RequiredInstructionSet string
|
||||||
DynamicLinker string
|
DynamicLinker string
|
||||||
@@ -144,8 +148,7 @@ type BaseProperties struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UnusedProperties struct {
|
type UnusedProperties struct {
|
||||||
Native_coverage *bool
|
Tags []string
|
||||||
Tags []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ModuleContextIntf interface {
|
type ModuleContextIntf interface {
|
||||||
@@ -261,6 +264,7 @@ type Module struct {
|
|||||||
installer installer
|
installer installer
|
||||||
stl *stl
|
stl *stl
|
||||||
sanitize *sanitize
|
sanitize *sanitize
|
||||||
|
coverage *coverage
|
||||||
|
|
||||||
androidMkSharedLibDeps []string
|
androidMkSharedLibDeps []string
|
||||||
|
|
||||||
@@ -291,6 +295,9 @@ func (c *Module) Init() (blueprint.Module, []interface{}) {
|
|||||||
if c.sanitize != nil {
|
if c.sanitize != nil {
|
||||||
props = append(props, c.sanitize.props()...)
|
props = append(props, c.sanitize.props()...)
|
||||||
}
|
}
|
||||||
|
if c.coverage != nil {
|
||||||
|
props = append(props, c.coverage.props()...)
|
||||||
|
}
|
||||||
for _, feature := range c.features {
|
for _, feature := range c.features {
|
||||||
props = append(props, feature.props()...)
|
props = append(props, feature.props()...)
|
||||||
}
|
}
|
||||||
@@ -411,6 +418,7 @@ func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Mo
|
|||||||
}
|
}
|
||||||
module.stl = &stl{}
|
module.stl = &stl{}
|
||||||
module.sanitize = &sanitize{}
|
module.sanitize = &sanitize{}
|
||||||
|
module.coverage = &coverage{}
|
||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,6 +462,9 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
|||||||
if c.sanitize != nil {
|
if c.sanitize != nil {
|
||||||
flags = c.sanitize.flags(ctx, flags)
|
flags = c.sanitize.flags(ctx, flags)
|
||||||
}
|
}
|
||||||
|
if c.coverage != nil {
|
||||||
|
flags = c.coverage.flags(ctx, flags)
|
||||||
|
}
|
||||||
for _, feature := range c.features {
|
for _, feature := range c.features {
|
||||||
flags = feature.flags(ctx, flags)
|
flags = feature.flags(ctx, flags)
|
||||||
}
|
}
|
||||||
@@ -525,6 +536,9 @@ func (c *Module) begin(ctx BaseModuleContext) {
|
|||||||
if c.sanitize != nil {
|
if c.sanitize != nil {
|
||||||
c.sanitize.begin(ctx)
|
c.sanitize.begin(ctx)
|
||||||
}
|
}
|
||||||
|
if c.coverage != nil {
|
||||||
|
c.coverage.begin(ctx)
|
||||||
|
}
|
||||||
for _, feature := range c.features {
|
for _, feature := range c.features {
|
||||||
feature.begin(ctx)
|
feature.begin(ctx)
|
||||||
}
|
}
|
||||||
@@ -563,6 +577,9 @@ func (c *Module) deps(ctx DepsContext) Deps {
|
|||||||
if c.sanitize != nil {
|
if c.sanitize != nil {
|
||||||
deps = c.sanitize.deps(ctx, deps)
|
deps = c.sanitize.deps(ctx, deps)
|
||||||
}
|
}
|
||||||
|
if c.coverage != nil {
|
||||||
|
deps = c.coverage.deps(ctx, deps)
|
||||||
|
}
|
||||||
for _, feature := range c.features {
|
for _, feature := range c.features {
|
||||||
deps = feature.deps(ctx, deps)
|
deps = feature.deps(ctx, deps)
|
||||||
}
|
}
|
||||||
@@ -951,6 +968,20 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
depPaths.CrtEnd = linkFile
|
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 ptr != nil {
|
||||||
if !linkFile.Valid() {
|
if !linkFile.Valid() {
|
||||||
ctx.ModuleErrorf("module %q missing output file", name)
|
ctx.ModuleErrorf("module %q missing output file", name)
|
||||||
@@ -1024,6 +1055,7 @@ func DefaultsFactory(props ...interface{}) (blueprint.Module, []interface{}) {
|
|||||||
&StripProperties{},
|
&StripProperties{},
|
||||||
&InstallerProperties{},
|
&InstallerProperties{},
|
||||||
&TidyProperties{},
|
&TidyProperties{},
|
||||||
|
&CoverageProperties{},
|
||||||
)
|
)
|
||||||
|
|
||||||
return android.InitDefaultsModule(module, module, props...)
|
return android.InitDefaultsModule(module, module, props...)
|
||||||
|
124
cc/coverage.go
Normal file
124
cc/coverage.go
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
// Copyright 2017 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package cc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"android/soong/android"
|
||||||
|
"github.com/google/blueprint"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CoverageProperties struct {
|
||||||
|
Native_coverage *bool
|
||||||
|
|
||||||
|
CoverageEnabled bool `blueprint:"mutated"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type coverage struct {
|
||||||
|
Properties CoverageProperties
|
||||||
|
|
||||||
|
// Whether binaries containing this module need --coverage added to their ldflags
|
||||||
|
linkCoverage bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cov *coverage) props() []interface{} {
|
||||||
|
return []interface{}{&cov.Properties}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cov *coverage) begin(ctx BaseModuleContext) {}
|
||||||
|
|
||||||
|
func (cov *coverage) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||||
|
return deps
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cov *coverage) flags(ctx ModuleContext, flags Flags) Flags {
|
||||||
|
if !ctx.DeviceConfig().NativeCoverageEnabled() {
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
if cov.Properties.CoverageEnabled {
|
||||||
|
flags.Coverage = true
|
||||||
|
flags.GlobalFlags = append(flags.GlobalFlags, "--coverage", "-O0")
|
||||||
|
cov.linkCoverage = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Even if we don't have coverage enabled, if any of our object files were compiled
|
||||||
|
// with coverage, then we need to add --coverage to our ldflags.
|
||||||
|
if !cov.linkCoverage {
|
||||||
|
if ctx.static() && !ctx.staticBinary() {
|
||||||
|
// For static libraries, the only thing that changes our object files
|
||||||
|
// are included whole static libraries, so check to see if any of
|
||||||
|
// those have coverage enabled.
|
||||||
|
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
||||||
|
if ctx.OtherModuleDependencyTag(m) != wholeStaticDepTag {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if cc, ok := m.(*Module); ok && cc.coverage != nil {
|
||||||
|
if cc.coverage.linkCoverage {
|
||||||
|
cov.linkCoverage = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// For executables and shared libraries, we need to check all of
|
||||||
|
// our static dependencies.
|
||||||
|
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
||||||
|
cc, ok := m.(*Module)
|
||||||
|
if !ok || cc.coverage == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if static, ok := cc.linker.(libraryInterface); !ok || !static.static() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if cc.coverage.linkCoverage {
|
||||||
|
cov.linkCoverage = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cov.linkCoverage {
|
||||||
|
flags.LdFlags = append(flags.LdFlags, "--coverage")
|
||||||
|
}
|
||||||
|
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
func coverageLinkingMutator(mctx android.BottomUpMutatorContext) {
|
||||||
|
if c, ok := mctx.Module().(*Module); ok && c.coverage != nil {
|
||||||
|
var enabled bool
|
||||||
|
|
||||||
|
if !mctx.DeviceConfig().NativeCoverageEnabled() {
|
||||||
|
// Coverage is disabled globally
|
||||||
|
} else if mctx.Host() {
|
||||||
|
// TODO(dwillemsen): because of -nodefaultlibs, we must depend on libclang_rt.profile-*.a
|
||||||
|
// Just turn off for now.
|
||||||
|
} else if c.coverage.Properties.Native_coverage != nil {
|
||||||
|
enabled = *c.coverage.Properties.Native_coverage
|
||||||
|
} else {
|
||||||
|
enabled = mctx.DeviceConfig().CoverageEnabledForPath(mctx.ModuleDir())
|
||||||
|
}
|
||||||
|
|
||||||
|
if enabled {
|
||||||
|
// Create a variation so that we don't need to recompile objects
|
||||||
|
// when turning on or off coverage. We'll still relink the necessary
|
||||||
|
// binaries, since we don't know which ones those are until later.
|
||||||
|
m := mctx.CreateLocalVariations("cov")
|
||||||
|
m[0].(*Module).coverage.Properties.CoverageEnabled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -199,6 +199,9 @@ type libraryDecorator struct {
|
|||||||
|
|
||||||
sanitize *sanitize
|
sanitize *sanitize
|
||||||
|
|
||||||
|
// Output archive of gcno coverage information files
|
||||||
|
coverageOutputFile android.OptionalPath
|
||||||
|
|
||||||
// Decorated interafaces
|
// Decorated interafaces
|
||||||
*baseCompiler
|
*baseCompiler
|
||||||
*baseLinker
|
*baseLinker
|
||||||
@@ -393,12 +396,12 @@ func (library *libraryDecorator) linkStatic(ctx ModuleContext,
|
|||||||
|
|
||||||
outputFile := android.PathForModuleOut(ctx,
|
outputFile := android.PathForModuleOut(ctx,
|
||||||
ctx.ModuleName()+library.Properties.VariantName+staticLibraryExtension)
|
ctx.ModuleName()+library.Properties.VariantName+staticLibraryExtension)
|
||||||
|
builderFlags := flagsToBuilderFlags(flags)
|
||||||
|
|
||||||
if ctx.Darwin() {
|
TransformObjToStaticLib(ctx, library.objects.objFiles, builderFlags, outputFile, objs.tidyFiles)
|
||||||
TransformDarwinObjToStaticLib(ctx, library.objects.objFiles, flagsToBuilderFlags(flags), outputFile, objs.tidyFiles)
|
|
||||||
} else {
|
library.coverageOutputFile = TransformCoverageFilesToLib(ctx, library.objects, builderFlags,
|
||||||
TransformObjToStaticLib(ctx, library.objects.objFiles, flagsToBuilderFlags(flags), outputFile, objs.tidyFiles)
|
ctx.ModuleName()+library.Properties.VariantName)
|
||||||
}
|
|
||||||
|
|
||||||
library.wholeStaticMissingDeps = ctx.GetMissingDependencies()
|
library.wholeStaticMissingDeps = ctx.GetMissingDependencies()
|
||||||
|
|
||||||
@@ -506,6 +509,10 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
|||||||
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
|
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
|
||||||
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile)
|
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile)
|
||||||
|
|
||||||
|
objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...)
|
||||||
|
objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...)
|
||||||
|
library.coverageOutputFile = TransformCoverageFilesToLib(ctx, objs, builderFlags, library.getLibName(ctx))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -101,6 +101,7 @@ func flagsToBuilderFlags(in Flags) builderFlags {
|
|||||||
yasmFlags: strings.Join(in.YasmFlags, " "),
|
yasmFlags: strings.Join(in.YasmFlags, " "),
|
||||||
toolchain: in.Toolchain,
|
toolchain: in.Toolchain,
|
||||||
clang: in.Clang,
|
clang: in.Clang,
|
||||||
|
coverage: in.Coverage,
|
||||||
tidy: in.Tidy,
|
tidy: in.Tidy,
|
||||||
|
|
||||||
groupStaticLibs: in.GroupStaticLibs,
|
groupStaticLibs: in.GroupStaticLibs,
|
||||||
|
Reference in New Issue
Block a user