Shorten the -checks flag in clang-tidy rules

* If a module defines tidy_checks with "-*",
  pass only "-*" and checks after it to clang-tidy.

Test: make tidy-soong_subset
Change-Id: I2a4a6111f67b934bc29e4e4fe8596a8dce4e7031
This commit is contained in:
Chih-Hung Hsieh
2022-06-02 19:55:15 -07:00
parent b12ae4f2bd
commit 80e3e03aa9
2 changed files with 89 additions and 2 deletions

View File

@@ -144,8 +144,23 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags {
tidyChecks += config.TidyChecksForDir(ctx.ModuleDir())
}
if len(tidy.Properties.Tidy_checks) > 0 {
tidyChecks = tidyChecks + "," + strings.Join(esc(ctx, "tidy_checks",
config.ClangRewriteTidyChecks(tidy.Properties.Tidy_checks)), ",")
// If Tidy_checks contains "-*", ignore all checks before "-*".
localChecks := tidy.Properties.Tidy_checks
ignoreGlobalChecks := false
for n, check := range tidy.Properties.Tidy_checks {
if check == "-*" {
ignoreGlobalChecks = true
localChecks = tidy.Properties.Tidy_checks[n:]
}
}
if ignoreGlobalChecks {
tidyChecks = "-checks=" + strings.Join(esc(ctx, "tidy_checks",
config.ClangRewriteTidyChecks(localChecks)), ",")
} else {
tidyChecks = tidyChecks + "," + strings.Join(esc(ctx, "tidy_checks",
config.ClangRewriteTidyChecks(localChecks)), ",")
}
}
if ctx.Windows() {
// https://b.corp.google.com/issues/120614316