aboutsummaryrefslogtreecommitdiffstats
path: root/cc/builder.go
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2016-09-26 15:45:04 -0700
committerDan Willemsen <dwillemsen@google.com>2016-10-31 16:21:01 -0700
commita03cf6d3221142a7d38fefb187728a084f0b0367 (patch)
treeb048c310fd53cdc60f1452d97671377167da409d /cc/builder.go
parent5cb580f407d2b1b639d7aeea8e1310740e55fe1c (diff)
downloadbuild_soong-a03cf6d3221142a7d38fefb187728a084f0b0367.tar.gz
build_soong-a03cf6d3221142a7d38fefb187728a084f0b0367.tar.bz2
build_soong-a03cf6d3221142a7d38fefb187728a084f0b0367.zip
Add clang-tidy support
For every file which we can run clang-tidy (C/C++ clang-built), we add a new build node that depends on the object file (since clang-tidy does not export a depfile), and is depended on by the link step. This is better than how we're doing it in make, since calling tidy can be turned on or off without needing to rebuild the object files. This does not attempt to port WITH_TIDY_ONLY from Make, since the way that it works is broken (due to the lack of a depfile). Bug: 32244182 Test: WITH_TIDY=true mmma -j bionic/libc Test: ./soong (Setting ClangTidy: true) Change-Id: I40bbb5bb00d292d72bf1c293b93080b5f9f6d8ea
Diffstat (limited to 'cc/builder.go')
-rw-r--r--cc/builder.go70
1 files changed, 56 insertions, 14 deletions
diff --git a/cc/builder.go b/cc/builder.go
index 0006ed36..faa39d15 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -150,6 +150,14 @@ var (
Restat: true,
},
"crossCompile")
+
+ clangTidy = pctx.AndroidStaticRule("clangTidy",
+ blueprint.RuleParams{
+ Command: "rm -f $out && ${config.ClangBin}/clang-tidy $tidyFlags $in -- $cFlags && touch $out",
+ CommandDeps: []string{"${config.ClangBin}/clang-tidy"},
+ Description: "tidy $out",
+ },
+ "cFlags", "tidyFlags")
)
func init() {
@@ -174,8 +182,10 @@ type builderFlags struct {
libFlags string
yaccFlags string
protoFlags string
+ tidyFlags string
toolchain config.Toolchain
clang bool
+ tidy bool
stripKeepSymbols bool
stripKeepMiniDebugInfo bool
@@ -183,18 +193,21 @@ type builderFlags struct {
}
type Objects struct {
- objFiles android.Paths
+ objFiles android.Paths
+ tidyFiles android.Paths
}
func (a Objects) Copy() Objects {
return Objects{
- objFiles: append(android.Paths{}, a.objFiles...),
+ objFiles: append(android.Paths{}, a.objFiles...),
+ tidyFiles: append(android.Paths{}, a.tidyFiles...),
}
}
func (a Objects) Append(b Objects) Objects {
return Objects{
- objFiles: append(a.objFiles, b.objFiles...),
+ objFiles: append(a.objFiles, b.objFiles...),
+ tidyFiles: append(a.tidyFiles, b.tidyFiles...),
}
}
@@ -203,6 +216,10 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
flags builderFlags, deps android.Paths) Objects {
objFiles := make(android.Paths, len(srcFiles))
+ var tidyFiles android.Paths
+ if flags.tidy && flags.clang {
+ tidyFiles = make(android.Paths, 0, len(srcFiles))
+ }
cflags := flags.globalFlags + " " + flags.cFlags + " " + flags.conlyFlags
cppflags := flags.globalFlags + " " + flags.cFlags + " " + flags.cppFlags
@@ -223,11 +240,13 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
var moduleCflags string
var ccCmd string
+ tidy := flags.tidy && flags.clang
switch srcFile.Ext() {
case ".S", ".s":
ccCmd = "gcc"
moduleCflags = asflags
+ tidy = false
case ".c":
ccCmd = "gcc"
moduleCflags = cflags
@@ -264,24 +283,45 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
"ccCmd": ccCmd,
},
})
+
+ if tidy {
+ tidyFile := android.ObjPathWithExt(ctx, srcFile, subdir, "tidy")
+ tidyFiles = append(tidyFiles, tidyFile)
+
+ ctx.ModuleBuild(pctx, android.ModuleBuildParams{
+ Rule: clangTidy,
+ Output: tidyFile,
+ Input: srcFile,
+ // We must depend on objFile, since clang-tidy doesn't
+ // support exporting dependencies.
+ Implicit: objFile,
+ Args: map[string]string{
+ "cFlags": moduleCflags,
+ "tidyFlags": flags.tidyFlags,
+ },
+ })
+ }
+
}
return Objects{
- objFiles: objFiles,
+ objFiles: objFiles,
+ tidyFiles: tidyFiles,
}
}
// Generate a rule for compiling multiple .o files to a static library (.a)
func TransformObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
- flags builderFlags, outputFile android.ModuleOutPath) {
+ flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths) {
arCmd := gccCmd(flags.toolchain, "ar")
arFlags := "crsPD"
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
- Rule: ar,
- Output: outputFile,
- Inputs: objFiles,
+ Rule: ar,
+ Output: outputFile,
+ Inputs: objFiles,
+ Implicits: deps,
Args: map[string]string{
"arFlags": arFlags,
"arCmd": arCmd,
@@ -294,7 +334,7 @@ func TransformObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
// very small command line length limit, so we have to split the ar into multiple
// steps, each appending to the previous one.
func TransformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
- flags builderFlags, outputPath android.ModuleOutPath) {
+ flags builderFlags, outputPath android.ModuleOutPath, deps android.Paths) {
arFlags := "cqs"
@@ -303,8 +343,9 @@ func TransformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.P
dummyAr := android.PathForModuleOut(ctx, "dummy"+staticLibraryExtension)
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
- Rule: emptyFile,
- Output: dummy,
+ Rule: emptyFile,
+ Output: dummy,
+ Implicits: deps,
})
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
@@ -347,9 +388,10 @@ func TransformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.P
if in == "" {
ctx.Build(pctx, blueprint.BuildParams{
- Rule: darwinAr,
- Outputs: []string{out},
- Inputs: l,
+ Rule: darwinAr,
+ Outputs: []string{out},
+ Inputs: l,
+ Implicits: deps.Strings(),
Args: map[string]string{
"arFlags": arFlags,
},