Merge "Generate tidy-* rules unless tidy is disabled"
This commit is contained in:
@@ -427,7 +427,7 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
|
|||||||
linkerDeps = append(linkerDeps, ndkSharedLibDeps(ctx)...)
|
linkerDeps = append(linkerDeps, ndkSharedLibDeps(ctx)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
validations = append(validations, objs.tidyFiles...)
|
validations = append(validations, objs.tidyDepFiles...)
|
||||||
linkerDeps = append(linkerDeps, flags.LdFlagsDeps...)
|
linkerDeps = append(linkerDeps, flags.LdFlagsDeps...)
|
||||||
|
|
||||||
// Register link action.
|
// Register link action.
|
||||||
|
@@ -388,6 +388,7 @@ type builderFlags struct {
|
|||||||
|
|
||||||
// True if these extra features are enabled.
|
// True if these extra features are enabled.
|
||||||
tidy bool
|
tidy bool
|
||||||
|
needTidyFiles bool
|
||||||
gcovCoverage bool
|
gcovCoverage bool
|
||||||
sAbiDump bool
|
sAbiDump bool
|
||||||
emitXrefs bool
|
emitXrefs bool
|
||||||
@@ -420,6 +421,7 @@ type StripFlags struct {
|
|||||||
type Objects struct {
|
type Objects struct {
|
||||||
objFiles android.Paths
|
objFiles android.Paths
|
||||||
tidyFiles android.Paths
|
tidyFiles android.Paths
|
||||||
|
tidyDepFiles android.Paths // link dependent .tidy files
|
||||||
coverageFiles android.Paths
|
coverageFiles android.Paths
|
||||||
sAbiDumpFiles android.Paths
|
sAbiDumpFiles android.Paths
|
||||||
kytheFiles android.Paths
|
kytheFiles android.Paths
|
||||||
@@ -429,6 +431,7 @@ 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...),
|
||||||
|
tidyDepFiles: append(android.Paths{}, a.tidyDepFiles...),
|
||||||
coverageFiles: append(android.Paths{}, a.coverageFiles...),
|
coverageFiles: append(android.Paths{}, a.coverageFiles...),
|
||||||
sAbiDumpFiles: append(android.Paths{}, a.sAbiDumpFiles...),
|
sAbiDumpFiles: append(android.Paths{}, a.sAbiDumpFiles...),
|
||||||
kytheFiles: append(android.Paths{}, a.kytheFiles...),
|
kytheFiles: append(android.Paths{}, a.kytheFiles...),
|
||||||
@@ -439,6 +442,7 @@ 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...),
|
||||||
|
tidyDepFiles: append(a.tidyDepFiles, b.tidyDepFiles...),
|
||||||
coverageFiles: append(a.coverageFiles, b.coverageFiles...),
|
coverageFiles: append(a.coverageFiles, b.coverageFiles...),
|
||||||
sAbiDumpFiles: append(a.sAbiDumpFiles, b.sAbiDumpFiles...),
|
sAbiDumpFiles: append(a.sAbiDumpFiles, b.sAbiDumpFiles...),
|
||||||
kytheFiles: append(a.kytheFiles, b.kytheFiles...),
|
kytheFiles: append(a.kytheFiles, b.kytheFiles...),
|
||||||
@@ -452,9 +456,8 @@ func escapeSingleQuotes(s string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files
|
// Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files
|
||||||
func transformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles, noTidySrcs android.Paths,
|
func transformSourceToObj(ctx ModuleContext, subdir string, srcFiles, noTidySrcs android.Paths,
|
||||||
flags builderFlags, pathDeps android.Paths, cFlagsDeps android.Paths) Objects {
|
flags builderFlags, pathDeps android.Paths, cFlagsDeps android.Paths) Objects {
|
||||||
|
|
||||||
// Source files are one-to-one with tidy, coverage, or kythe files, if enabled.
|
// Source files are one-to-one with tidy, coverage, or kythe files, if enabled.
|
||||||
objFiles := make(android.Paths, len(srcFiles))
|
objFiles := make(android.Paths, len(srcFiles))
|
||||||
var tidyFiles android.Paths
|
var tidyFiles android.Paths
|
||||||
@@ -540,8 +543,7 @@ func transformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles, no
|
|||||||
// Multiple source files have build rules usually share the same cFlags or tidyFlags.
|
// Multiple source files have build rules usually share the same cFlags or tidyFlags.
|
||||||
// Define only one version in this module and share it in multiple build rules.
|
// Define only one version in this module and share it in multiple build rules.
|
||||||
// To simplify the code, the shared variables are all named as $flags<nnn>.
|
// To simplify the code, the shared variables are all named as $flags<nnn>.
|
||||||
numSharedFlags := 0
|
shared := ctx.getSharedFlags()
|
||||||
flagsMap := make(map[string]string)
|
|
||||||
|
|
||||||
// Share flags only when there are multiple files or tidy rules.
|
// Share flags only when there are multiple files or tidy rules.
|
||||||
var hasMultipleRules = len(srcFiles) > 1 || flags.tidy
|
var hasMultipleRules = len(srcFiles) > 1 || flags.tidy
|
||||||
@@ -553,11 +555,11 @@ func transformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles, no
|
|||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
mapKey := kind + flags
|
mapKey := kind + flags
|
||||||
n, ok := flagsMap[mapKey]
|
n, ok := shared.flagsMap[mapKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
numSharedFlags += 1
|
shared.numSharedFlags += 1
|
||||||
n = strconv.Itoa(numSharedFlags)
|
n = strconv.Itoa(shared.numSharedFlags)
|
||||||
flagsMap[mapKey] = n
|
shared.flagsMap[mapKey] = n
|
||||||
ctx.Variable(pctx, kind+n, flags)
|
ctx.Variable(pctx, kind+n, flags)
|
||||||
}
|
}
|
||||||
return "$" + kind + n
|
return "$" + kind + n
|
||||||
@@ -720,9 +722,14 @@ func transformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles, no
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tidyDepFiles android.Paths
|
||||||
|
if flags.needTidyFiles {
|
||||||
|
tidyDepFiles = tidyFiles
|
||||||
|
}
|
||||||
return Objects{
|
return Objects{
|
||||||
objFiles: objFiles,
|
objFiles: objFiles,
|
||||||
tidyFiles: tidyFiles,
|
tidyFiles: tidyFiles,
|
||||||
|
tidyDepFiles: tidyDepFiles,
|
||||||
coverageFiles: coverageFiles,
|
coverageFiles: coverageFiles,
|
||||||
sAbiDumpFiles: sAbiDumpFiles,
|
sAbiDumpFiles: sAbiDumpFiles,
|
||||||
kytheFiles: kytheFiles,
|
kytheFiles: kytheFiles,
|
||||||
|
21
cc/cc.go
21
cc/cc.go
@@ -211,7 +211,8 @@ type Flags struct {
|
|||||||
SystemIncludeFlags []string
|
SystemIncludeFlags []string
|
||||||
|
|
||||||
Toolchain config.Toolchain
|
Toolchain config.Toolchain
|
||||||
Tidy bool // True if clang-tidy is enabled.
|
Tidy bool // True if ninja .tidy rules should be generated.
|
||||||
|
NeedTidyFiles bool // True if module link should depend on .tidy files
|
||||||
GcovCoverage bool // True if coverage files should be generated.
|
GcovCoverage bool // True if coverage files should be generated.
|
||||||
SAbiDump bool // True if header abi dumps should be generated.
|
SAbiDump bool // True if header abi dumps should be generated.
|
||||||
EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
|
EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
|
||||||
@@ -516,6 +517,12 @@ type ModuleContextIntf interface {
|
|||||||
directlyInAnyApex() bool
|
directlyInAnyApex() bool
|
||||||
isPreventInstall() bool
|
isPreventInstall() bool
|
||||||
isCfiAssemblySupportEnabled() bool
|
isCfiAssemblySupportEnabled() bool
|
||||||
|
getSharedFlags() *SharedFlags
|
||||||
|
}
|
||||||
|
|
||||||
|
type SharedFlags struct {
|
||||||
|
numSharedFlags int
|
||||||
|
flagsMap map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ModuleContext interface {
|
type ModuleContext interface {
|
||||||
@@ -827,6 +834,9 @@ type Module struct {
|
|||||||
// Flags used to compile this module
|
// Flags used to compile this module
|
||||||
flags Flags
|
flags Flags
|
||||||
|
|
||||||
|
// Shared flags among build rules of this module
|
||||||
|
sharedFlags SharedFlags
|
||||||
|
|
||||||
// only non-nil when this is a shared library that reuses the objects of a static library
|
// only non-nil when this is a shared library that reuses the objects of a static library
|
||||||
staticAnalogue *StaticLibraryInfo
|
staticAnalogue *StaticLibraryInfo
|
||||||
|
|
||||||
@@ -1605,6 +1615,15 @@ func (ctx *moduleContextImpl) isPreventInstall() bool {
|
|||||||
return ctx.mod.Properties.PreventInstall
|
return ctx.mod.Properties.PreventInstall
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctx *moduleContextImpl) getSharedFlags() *SharedFlags {
|
||||||
|
shared := &ctx.mod.sharedFlags
|
||||||
|
if shared.flagsMap == nil {
|
||||||
|
shared.numSharedFlags = 0
|
||||||
|
shared.flagsMap = make(map[string]string)
|
||||||
|
}
|
||||||
|
return shared
|
||||||
|
}
|
||||||
|
|
||||||
func (ctx *moduleContextImpl) isCfiAssemblySupportEnabled() bool {
|
func (ctx *moduleContextImpl) isCfiAssemblySupportEnabled() bool {
|
||||||
return ctx.mod.isCfiAssemblySupportEnabled()
|
return ctx.mod.isCfiAssemblySupportEnabled()
|
||||||
}
|
}
|
||||||
|
@@ -675,7 +675,7 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compile a list of source files into objects a specified subdirectory
|
// Compile a list of source files into objects a specified subdirectory
|
||||||
func compileObjs(ctx android.ModuleContext, flags builderFlags, subdir string,
|
func compileObjs(ctx ModuleContext, flags builderFlags, subdir string,
|
||||||
srcFiles, noTidySrcs, pathDeps android.Paths, cFlagsDeps android.Paths) Objects {
|
srcFiles, noTidySrcs, pathDeps android.Paths, cFlagsDeps android.Paths) Objects {
|
||||||
|
|
||||||
return transformSourceToObj(ctx, subdir, srcFiles, noTidySrcs, flags, pathDeps, cFlagsDeps)
|
return transformSourceToObj(ctx, subdir, srcFiles, noTidySrcs, flags, pathDeps, cFlagsDeps)
|
||||||
|
@@ -1340,7 +1340,7 @@ func (library *libraryDecorator) linkStatic(ctx ModuleContext,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
transformObjToStaticLib(ctx, library.objects.objFiles, deps.WholeStaticLibsFromPrebuilts, builderFlags, outputFile, nil, objs.tidyFiles)
|
transformObjToStaticLib(ctx, library.objects.objFiles, deps.WholeStaticLibsFromPrebuilts, builderFlags, outputFile, nil, objs.tidyDepFiles)
|
||||||
|
|
||||||
library.coverageOutputFile = transformCoverageFilesToZip(ctx, library.objects, ctx.ModuleName())
|
library.coverageOutputFile = transformCoverageFilesToZip(ctx, library.objects, ctx.ModuleName())
|
||||||
|
|
||||||
@@ -1487,7 +1487,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
|||||||
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
|
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
|
||||||
transformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs,
|
transformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs,
|
||||||
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
|
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
|
||||||
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile, implicitOutputs, objs.tidyFiles)
|
linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile, implicitOutputs, objs.tidyDepFiles)
|
||||||
|
|
||||||
objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...)
|
objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...)
|
||||||
objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...)
|
objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...)
|
||||||
|
14
cc/tidy.go
14
cc/tidy.go
@@ -71,13 +71,17 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not explicitly set, check the global tidy flag
|
// If not explicitly disabled, set flags.Tidy to generate .tidy rules.
|
||||||
if tidy.Properties.Tidy == nil && !ctx.Config().ClangTidy() {
|
// Note that libraries and binaries will depend on .tidy files ONLY if
|
||||||
return flags
|
// the global WITH_TIDY or module 'tidy' property is true.
|
||||||
}
|
|
||||||
|
|
||||||
flags.Tidy = true
|
flags.Tidy = true
|
||||||
|
|
||||||
|
// If explicitly enabled, by global default or local tidy property,
|
||||||
|
// set flags.NeedTidyFiles to make this module depend on .tidy files.
|
||||||
|
if ctx.Config().ClangTidy() || Bool(tidy.Properties.Tidy) {
|
||||||
|
flags.NeedTidyFiles = true
|
||||||
|
}
|
||||||
|
|
||||||
// Add global WITH_TIDY_FLAGS and local tidy_flags.
|
// Add global WITH_TIDY_FLAGS and local tidy_flags.
|
||||||
withTidyFlags := ctx.Config().Getenv("WITH_TIDY_FLAGS")
|
withTidyFlags := ctx.Config().Getenv("WITH_TIDY_FLAGS")
|
||||||
if len(withTidyFlags) > 0 {
|
if len(withTidyFlags) > 0 {
|
||||||
|
@@ -85,6 +85,7 @@ func flagsToBuilderFlags(in Flags) builderFlags {
|
|||||||
toolchain: in.Toolchain,
|
toolchain: in.Toolchain,
|
||||||
gcovCoverage: in.GcovCoverage,
|
gcovCoverage: in.GcovCoverage,
|
||||||
tidy: in.Tidy,
|
tidy: in.Tidy,
|
||||||
|
needTidyFiles: in.NeedTidyFiles,
|
||||||
sAbiDump: in.SAbiDump,
|
sAbiDump: in.SAbiDump,
|
||||||
emitXrefs: in.EmitXrefs,
|
emitXrefs: in.EmitXrefs,
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user