clang-tidy: Don't repeat list of all checks in three places.

Instead, put all checks in a cmake variable and reference this.

Also, make clangd use the the ClangTidyForceLinker.h header instead
of duplicating the list of modules -- the duplicate copy was missing
the new "darwin" checker added in r373065.

Differential Revision: https://reviews.llvm.org/D68132

llvm-svn: 373082
This commit is contained in:
Nico Weber 2019-09-27 12:56:14 +00:00
parent 18f805a7ea
commit d69fa737ff
6 changed files with 43 additions and 102 deletions

View File

@ -37,6 +37,8 @@ if(CLANG_ENABLE_STATIC_ANALYZER)
)
endif()
# Checks.
# If you add a check, also add it to ClangTidyForceLinker.h in this directory.
add_subdirectory(android)
add_subdirectory(abseil)
add_subdirectory(boost)
@ -57,9 +59,38 @@ endif()
add_subdirectory(objc)
add_subdirectory(openmp)
add_subdirectory(performance)
add_subdirectory(plugin)
add_subdirectory(portability)
add_subdirectory(readability)
add_subdirectory(zircon)
set(ALL_CLANG_TIDY_CHECKS
clangTidyAndroidModule
clangTidyAbseilModule
clangTidyBoostModule
clangTidyBugproneModule
clangTidyCERTModule
clangTidyCppCoreGuidelinesModule
clangTidyDarwinModule
clangTidyFuchsiaModule
clangTidyGoogleModule
clangTidyHICPPModule
clangTidyLinuxKernelModule
clangTidyLLVMModule
clangTidyMiscModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
clangTidyPerformanceModule
clangTidyPortabilityModule
clangTidyReadabilityModule
clangTidyZirconModule
)
if(CLANG_ENABLE_STATIC_ANALYZER)
list(APPEND ALL_CLANG_TIDY_CHECKS clangTidyMPIModule)
endif()
set(ALL_CLANG_TIDY_CHECKS ${ALL_CLANG_TIDY_CHECKS} PARENT_SCOPE)
# Other subtargets. These may reference ALL_CLANG_TIDY_CHECKS
# and must be below its definition.
add_subdirectory(plugin)
add_subdirectory(tool)
add_subdirectory(utils)
add_subdirectory(zircon)

View File

@ -80,7 +80,8 @@ extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
ModernizeModuleAnchorSource;
#if CLANG_ENABLE_STATIC_ANALYZER
#if CLANG_ENABLE_STATIC_ANALYZER && \
!defined(CLANG_TIDY_DISABLE_STATIC_ANALYZER_CHECKS)
// This anchor is used to force the linker to link the MPIModule.
extern volatile int MPIModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =

View File

@ -8,31 +8,6 @@ add_clang_library(clangTidyPlugin
clangFrontend
clangSema
clangTidy
clangTidyAbseilModule
clangTidyAndroidModule
clangTidyBoostModule
clangTidyBugproneModule
clangTidyCERTModule
clangTidyCppCoreGuidelinesModule
clangTidyDarwinModule
clangTidyFuchsiaModule
clangTidyGoogleModule
clangTidyHICPPModule
clangTidyLinuxKernelModule
clangTidyLLVMModule
clangTidyMiscModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
clangTidyPerformanceModule
clangTidyPortabilityModule
clangTidyReadabilityModule
clangTidyZirconModule
clangTooling
${ALL_CLANG_TIDY_CHECKS}
)
if(CLANG_ENABLE_STATIC_ANALYZER)
target_link_libraries(clangTidyPlugin PRIVATE
clangTidyMPIModule
)
endif()

View File

@ -17,35 +17,11 @@ target_link_libraries(clang-tidy
clangASTMatchers
clangBasic
clangTidy
clangTidyAndroidModule
clangTidyAbseilModule
clangTidyBoostModule
clangTidyBugproneModule
clangTidyCERTModule
clangTidyCppCoreGuidelinesModule
clangTidyDarwinModule
clangTidyFuchsiaModule
clangTidyGoogleModule
clangTidyHICPPModule
clangTidyLinuxKernelModule
clangTidyLLVMModule
clangTidyMiscModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
clangTidyPerformanceModule
clangTidyPortabilityModule
clangTidyReadabilityModule
clangTidyZirconModule
clangTooling
clangToolingCore
${ALL_CLANG_TIDY_CHECKS}
)
if(CLANG_ENABLE_STATIC_ANALYZER)
target_link_libraries(clang-tidy PRIVATE
clangTidyMPIModule
)
endif()
install(PROGRAMS clang-tidy-diff.py
DESTINATION share/clang

View File

@ -117,26 +117,6 @@ add_clang_library(clangDaemon
clangSema
clangSerialization
clangTidy
clangTidyAndroidModule
clangTidyAbseilModule
clangTidyBoostModule
clangTidyBugproneModule
clangTidyCERTModule
clangTidyCppCoreGuidelinesModule
clangTidyDarwinModule
clangTidyFuchsiaModule
clangTidyGoogleModule
clangTidyHICPPModule
clangTidyLinuxKernelModule
clangTidyLLVMModule
clangTidyMiscModule
clangTidyModernizeModule
clangTidyObjCModule
clangTidyOpenMPModule
clangTidyPerformanceModule
clangTidyPortabilityModule
clangTidyReadabilityModule
clangTidyZirconModule
clangTooling
clangToolingCore
clangToolingInclusions
@ -144,6 +124,7 @@ add_clang_library(clangDaemon
clangToolingSyntax
${LLVM_PTHREAD_LIB}
${CLANGD_ATOMIC_LIB}
${ALL_CLANG_TIDY_CHECKS}
)
add_subdirectory(refactor/tweaks)

View File

@ -49,6 +49,11 @@
#include <algorithm>
#include <memory>
// Force the linker to link in Clang-tidy modules.
// clangd doesn't support the static analyzer.
#define CLANG_TIDY_DISABLE_STATIC_ANALYZER_CHECKS
#include "../clang-tidy/ClangTidyForceLinker.h"
namespace clang {
namespace clangd {
namespace {
@ -521,32 +526,4 @@ buildAST(PathRef FileName, std::unique_ptr<CompilerInvocation> Invocation,
}
} // namespace clangd
namespace tidy {
// Force the linker to link in Clang-tidy modules.
#define LINK_TIDY_MODULE(X) \
extern volatile int X##ModuleAnchorSource; \
static int LLVM_ATTRIBUTE_UNUSED X##ModuleAnchorDestination = \
X##ModuleAnchorSource
LINK_TIDY_MODULE(Abseil);
LINK_TIDY_MODULE(Android);
LINK_TIDY_MODULE(Boost);
LINK_TIDY_MODULE(Bugprone);
LINK_TIDY_MODULE(CERT);
LINK_TIDY_MODULE(CppCoreGuidelines);
LINK_TIDY_MODULE(Fuchsia);
LINK_TIDY_MODULE(Google);
LINK_TIDY_MODULE(HICPP);
LINK_TIDY_MODULE(LinuxKernel);
LINK_TIDY_MODULE(LLVM);
LINK_TIDY_MODULE(Misc);
LINK_TIDY_MODULE(Modernize);
// LINK_TIDY_MODULE(MPI); // clangd doesn't support static analyzer.
LINK_TIDY_MODULE(ObjC);
LINK_TIDY_MODULE(OpenMP);
LINK_TIDY_MODULE(Performance);
LINK_TIDY_MODULE(Portability);
LINK_TIDY_MODULE(Readability);
LINK_TIDY_MODULE(Zircon);
#undef LINK_TIDY_MODULE
} // namespace tidy
} // namespace clang