Merge "Allow globally disabling some clang-tidy checks."
This commit is contained in:
@@ -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 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
|
||||||
|
}
|
||||||
|
|
||||||
func ClangFilterUnknownLldflags(lldflags []string) []string {
|
func ClangFilterUnknownLldflags(lldflags []string) []string {
|
||||||
ret := make([]string, 0, len(lldflags))
|
result, _ := android.FilterList(lldflags, ClangUnknownLldflags)
|
||||||
for _, f := range lldflags {
|
return result
|
||||||
if !inListSorted(f, ClangUnknownLldflags) {
|
|
||||||
ret = append(ret, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func inListSorted(s string, list []string) bool {
|
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())
|
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
|
||||||
|
Reference in New Issue
Block a user