Merge "Allow globally disabling some clang-tidy checks."

This commit is contained in:
Treehugger Robot
2020-08-20 19:51:31 +00:00
committed by Gerrit Code Review
2 changed files with 31 additions and 14 deletions

View File

@@ -15,6 +15,7 @@
package config package config
import ( import (
"android/soong/android"
"sort" "sort"
"strings" "strings"
) )
@@ -88,6 +89,12 @@ var ClangUnknownLldflags = sorted([]string{
var ClangLibToolingUnknownCflags = sorted([]string{}) var ClangLibToolingUnknownCflags = sorted([]string{})
// List of tidy checks that should be disabled globally. When the compiler is
// updated, some checks enabled by this module may be disabled if they have
// become more strict, or if they are a new match for a wildcard group like
// `modernize-*`.
var ClangTidyDisableChecks = []string{}
func init() { func init() {
pctx.StaticVariable("ClangExtraCflags", strings.Join([]string{ pctx.StaticVariable("ClangExtraCflags", strings.Join([]string{
"-D__compiler_offsetof=__builtin_offsetof", "-D__compiler_offsetof=__builtin_offsetof",
@@ -202,25 +209,34 @@ func init() {
} }
func ClangFilterUnknownCflags(cflags []string) []string { func ClangFilterUnknownCflags(cflags []string) []string {
ret := make([]string, 0, len(cflags)) result, _ := android.FilterList(cflags, ClangUnknownCflags)
for _, f := range cflags { return result
if !inListSorted(f, ClangUnknownCflags) { }
ret = append(ret, f)
}
}
func clangTidyNegateChecks(checks []string) []string {
ret := make([]string, 0, len(checks))
for _, c := range checks {
if strings.HasPrefix(c, "-") {
ret = append(ret, c)
} else {
ret = append(ret, "-"+c)
}
}
return ret return ret
} }
func ClangFilterUnknownLldflags(lldflags []string) []string { func ClangRewriteTidyChecks(checks []string) []string {
ret := make([]string, 0, len(lldflags)) checks = append(checks, clangTidyNegateChecks(ClangTidyDisableChecks)...)
for _, f := range lldflags { // clang-tidy does not allow later arguments to override earlier arguments,
if !inListSorted(f, ClangUnknownLldflags) { // so if we just disabled an argument that was explicitly enabled we must
ret = append(ret, f) // remove the enabling argument from the list.
} result, _ := android.FilterList(checks, ClangTidyDisableChecks)
} return result
}
return ret func ClangFilterUnknownLldflags(lldflags []string) []string {
result, _ := android.FilterList(lldflags, ClangUnknownLldflags)
return result
} }
func inListSorted(s string, list []string) bool { func inListSorted(s string, list []string) bool {

View File

@@ -109,7 +109,8 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags {
tidyChecks += config.TidyChecksForDir(ctx.ModuleDir()) tidyChecks += config.TidyChecksForDir(ctx.ModuleDir())
} }
if len(tidy.Properties.Tidy_checks) > 0 { if len(tidy.Properties.Tidy_checks) > 0 {
tidyChecks = tidyChecks + "," + strings.Join(esc(tidy.Properties.Tidy_checks), ",") tidyChecks = tidyChecks + "," + strings.Join(esc(
config.ClangRewriteTidyChecks(tidy.Properties.Tidy_checks)), ",")
} }
if ctx.Windows() { if ctx.Windows() {
// https://b.corp.google.com/issues/120614316 // https://b.corp.google.com/issues/120614316