Allow default clang-tidy checks

This will avoid suppressing all checks in user defined
.clang-tidy config files.

Bug: 252877310
Test: TIDY_EXTERNAL_VENDOR=1 make tidy-soong_subset
Change-Id: I99032300542e9b83cba60b00f8d328c63b5728e2
This commit is contained in:
Chih-Hung Hsieh
2022-10-11 12:27:17 -07:00
committed by Chih-hung Hsieh
parent 17b8795814
commit d21c46a5f8

View File

@@ -58,17 +58,14 @@ var (
) )
func init() { func init() {
// Many clang-tidy checks like altera-*, llvm-*, modernize-* // The global default tidy checks should include clang-tidy
// are not designed for Android source code or creating too // default checks and tested groups, but exclude known noisy checks.
// many (false-positive) warnings. The global default tidy checks
// should include only tested groups and exclude known noisy checks.
// See https://clang.llvm.org/extra/clang-tidy/checks/list.html // See https://clang.llvm.org/extra/clang-tidy/checks/list.html
pctx.VariableFunc("TidyDefaultGlobalChecks", func(ctx android.PackageVarContext) string { pctx.VariableFunc("TidyDefaultGlobalChecks", func(ctx android.PackageVarContext) string {
if override := ctx.Config().Getenv("DEFAULT_GLOBAL_TIDY_CHECKS"); override != "" { if override := ctx.Config().Getenv("DEFAULT_GLOBAL_TIDY_CHECKS"); override != "" {
return override return override
} }
checks := strings.Join([]string{ checks := strings.Join([]string{
"-*",
"android-*", "android-*",
"bugprone-*", "bugprone-*",
"cert-*", "cert-*",
@@ -95,7 +92,7 @@ func init() {
"-misc-non-private-member-variables-in-classes", "-misc-non-private-member-variables-in-classes",
"-misc-unused-parameters", "-misc-unused-parameters",
"-performance-no-int-to-ptr", "-performance-no-int-to-ptr",
// the following groups are excluded by -* // the following groups are not in clang-tidy default checks.
// -altera-* // -altera-*
// -cppcoreguidelines-* // -cppcoreguidelines-*
// -darwin-* // -darwin-*
@@ -109,28 +106,34 @@ func init() {
// -readability-* // -readability-*
// -zircon-* // -zircon-*
}, ",") }, ",")
// clang-analyzer-* checks are too slow to be in the default for WITH_TIDY=1. // clang-analyzer-* checks are slow for large files, but we have TIDY_TIMEOUT to
// nightly builds add CLANG_ANALYZER_CHECKS=1 to run those checks. // limit clang-tidy runtime. We allow clang-tidy default clang-analyzer-* checks,
// and add it explicitly when CLANG_ANALYZER_CHECKS is set.
// The insecureAPI.DeprecatedOrUnsafeBufferHandling warning does not apply to Android. // The insecureAPI.DeprecatedOrUnsafeBufferHandling warning does not apply to Android.
if ctx.Config().IsEnvTrue("CLANG_ANALYZER_CHECKS") { if ctx.Config().IsEnvTrue("CLANG_ANALYZER_CHECKS") {
checks += ",clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling" checks += ",clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
} else {
checks += ",-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
} }
return checks return checks
}) })
// There are too many clang-tidy warnings in external and vendor projects. // The external and vendor projects do not run clang-tidy unless TIDY_EXTERNAL_VENDOR is set.
// Enable only some google checks for these projects. // We do not add "-*" to the check list to avoid suppressing the check list in .clang-tidy config files.
// There are too many clang-tidy warnings in external and vendor projects, so we only
// enable some google checks for these projects. Users can add more checks locally with the
// "tidy_checks" list in .bp files, or the "Checks" list in .clang-tidy config files.
pctx.VariableFunc("TidyExternalVendorChecks", func(ctx android.PackageVarContext) string { pctx.VariableFunc("TidyExternalVendorChecks", func(ctx android.PackageVarContext) string {
if override := ctx.Config().Getenv("DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS"); override != "" { if override := ctx.Config().Getenv("DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS"); override != "" {
return override return override
} }
return strings.Join([]string{ return strings.Join([]string{
"-*",
"clang-diagnostic-unused-command-line-argument", "clang-diagnostic-unused-command-line-argument",
"google-build-explicit-make-pair", "google-build-explicit-make-pair",
"google-build-namespaces", "google-build-namespaces",
"google-runtime-operator", "google-runtime-operator",
"google-upgrade-*", "google-upgrade-*",
"-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling",
}, ",") }, ",")
}) })