aboutsummaryrefslogtreecommitdiffstats
path: root/cc/check.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/check.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/check.go')
-rw-r--r--cc/check.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/cc/check.go b/cc/check.go
index 4e403a58..340464e4 100644
--- a/cc/check.go
+++ b/cc/check.go
@@ -105,3 +105,31 @@ func CheckBadHostLdlibs(ctx ModuleContext, prop string, flags []string) {
}
}
}
+
+// Check for bad clang tidy flags
+func CheckBadTidyFlags(ctx ModuleContext, prop string, flags []string) {
+ for _, flag := range flags {
+ flag = strings.TrimSpace(flag)
+
+ if !strings.HasPrefix(flag, "-") {
+ ctx.PropertyErrorf(prop, "Flag `%s` must start with `-`", flag)
+ } else if strings.HasPrefix(flag, "-fix") {
+ ctx.PropertyErrorf(prop, "Flag `%s` is not allowed, since it could cause multiple writes to the same source file", flag)
+ } else if strings.HasPrefix(flag, "-checks=") {
+ ctx.PropertyErrorf(prop, "Flag `%s` is not allowed, use `tidy_checks` property instead", flag)
+ } else if strings.Contains(flag, " ") {
+ ctx.PropertyErrorf(prop, "Bad flag: `%s` is not an allowed multi-word flag. Should it be split into multiple flags?", flag)
+ }
+ }
+}
+
+// Check for bad clang tidy checks
+func CheckBadTidyChecks(ctx ModuleContext, prop string, checks []string) {
+ for _, check := range checks {
+ if strings.Contains(check, " ") {
+ ctx.PropertyErrorf("tidy_checks", "Check `%s` invalid, cannot contain spaces", check)
+ } else if strings.Contains(check, ",") {
+ ctx.PropertyErrorf("tidy_checks", "Check `%s` invalid, cannot contain commas. Split each entry into it's own string instead", check)
+ }
+ }
+}