Allow globally disabling some clang-tidy checks.
Test: used for the upcoming compiler update Bug: None Change-Id: Id17db2c48fa3e165da81a1d084827bde142406dd
This commit is contained in:
parent
046cbd1590
commit
d12afec49c
2 changed files with 31 additions and 14 deletions
|
@ -15,6 +15,7 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
@ -88,6 +89,12 @@ var ClangUnknownLldflags = 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() {
|
||||
pctx.StaticVariable("ClangExtraCflags", strings.Join([]string{
|
||||
"-D__compiler_offsetof=__builtin_offsetof",
|
||||
|
@ -202,25 +209,34 @@ func init() {
|
|||
}
|
||||
|
||||
func ClangFilterUnknownCflags(cflags []string) []string {
|
||||
ret := make([]string, 0, len(cflags))
|
||||
for _, f := range cflags {
|
||||
if !inListSorted(f, ClangUnknownCflags) {
|
||||
ret = append(ret, f)
|
||||
result, _ := android.FilterList(cflags, ClangUnknownCflags)
|
||||
return result
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func ClangFilterUnknownLldflags(lldflags []string) []string {
|
||||
ret := make([]string, 0, len(lldflags))
|
||||
for _, f := range lldflags {
|
||||
if !inListSorted(f, ClangUnknownLldflags) {
|
||||
ret = append(ret, f)
|
||||
}
|
||||
}
|
||||
func ClangRewriteTidyChecks(checks []string) []string {
|
||||
checks = append(checks, clangTidyNegateChecks(ClangTidyDisableChecks)...)
|
||||
// clang-tidy does not allow later arguments to override earlier arguments,
|
||||
// so if we just disabled an argument that was explicitly enabled we must
|
||||
// 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 {
|
||||
|
|
|
@ -109,7 +109,8 @@ 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(tidy.Properties.Tidy_checks), ",")
|
||||
tidyChecks = tidyChecks + "," + strings.Join(esc(
|
||||
config.ClangRewriteTidyChecks(tidy.Properties.Tidy_checks)), ",")
|
||||
}
|
||||
if ctx.Windows() {
|
||||
// https://b.corp.google.com/issues/120614316
|
||||
|
|
Loading…
Reference in a new issue