Author: Dmitry Polukhin Date: 2020-01-24T13:00:45-08:00 New Revision: 3f8b100e94b5c848843fa91c9782d9d4df4bb026
URL: https://github.com/llvm/llvm-project/commit/3f8b100e94b5c848843fa91c9782d9d4df4bb026 DIFF: https://github.com/llvm/llvm-project/commit/3f8b100e94b5c848843fa91c9782d9d4df4bb026.diff LOG: [clang-tidy] Add library for clang-tidy main function Summary: This library allows to create clang-tidy tools with custom checks outside of llvm repo using prebuilt clang release tarball. Test Plan: Checked that clang-tidy works as before. New library exists in istall dir. Reviewers: smeenai, gribozavr, stephanemoore Subscribers: mgorny, xazax.hun, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D73300 Added: clang-tools-extra/clang-tidy/tool/ClangTidyMain.h clang-tools-extra/clang-tidy/tool/ClangTidyToolMain.cpp Modified: clang-tools-extra/clang-tidy/tool/CMakeLists.txt clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/tool/CMakeLists.txt b/clang-tools-extra/clang-tidy/tool/CMakeLists.txt index 073749a7d836..0cd15ddb4653 100644 --- a/clang-tools-extra/clang-tidy/tool/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/tool/CMakeLists.txt @@ -5,8 +5,24 @@ set(LLVM_LINK_COMPONENTS support ) -add_clang_tool(clang-tidy +# Needed by LLVM's CMake checks because this file defines multiple targets. +set(LLVM_OPTIONAL_SOURCES ClangTidyMain.cpp ClangTidyToolMain.cpp) + +add_clang_library(clangTidyMain ClangTidyMain.cpp + + LINK_LIBS + clangAST + clangASTMatchers + clangBasic + clangTidy + ${ALL_CLANG_TIDY_CHECKS} + clangTooling + clangToolingCore + ) + +add_clang_tool(clang-tidy + ClangTidyToolMain.cpp ) add_dependencies(clang-tidy clang-resource-headers @@ -22,6 +38,7 @@ clang_target_link_libraries(clang-tidy target_link_libraries(clang-tidy PRIVATE clangTidy + clangTidyMain ${ALL_CLANG_TIDY_CHECKS} ) diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp index ad6182def20d..c6927cc6bd98 100644 --- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -14,6 +14,7 @@ /// //===----------------------------------------------------------------------===// +#include "ClangTidyMain.h" #include "../ClangTidy.h" #include "../ClangTidyForceLinker.h" #include "../GlobList.h" @@ -327,7 +328,7 @@ getVfsFromFile(const std::string &OverlayFile, return FS; } -static int clangTidyMain(int argc, const char **argv) { +int clangTidyMain(int argc, const char **argv) { llvm::InitLLVM X(argc, argv); CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory, cl::ZeroOrMore); @@ -488,7 +489,3 @@ static int clangTidyMain(int argc, const char **argv) { } // namespace tidy } // namespace clang - -int main(int argc, const char **argv) { - return clang::tidy::clangTidyMain(argc, argv); -} diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.h b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.h new file mode 100644 index 000000000000..f87f84b66aca --- /dev/null +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.h @@ -0,0 +1,23 @@ +//===--- tools/extra/clang-tidy/ClangTidyMain.h - Clang tidy tool -------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file This file declares the main function for the clang-tidy tool. +/// +/// This tool uses the Clang Tooling infrastructure, see +/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html +/// for details on setting it up with LLVM source tree. +/// +//===----------------------------------------------------------------------===// + +namespace clang { +namespace tidy { + +int clangTidyMain(int argc, const char **argv); + +} // namespace tidy +} // namespace clang diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyToolMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyToolMain.cpp new file mode 100644 index 000000000000..eb7fde7b8e07 --- /dev/null +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyToolMain.cpp @@ -0,0 +1,21 @@ +//===--- tools/extra/clang-tidy/ClangTidyToolMain.cpp - Clang tidy tool ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file This file contains clang-tidy tool entry point main function. +/// +/// This tool uses the Clang Tooling infrastructure, see +/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html +/// for details on setting it up with LLVM source tree. +/// +//===----------------------------------------------------------------------===// + +#include "ClangTidyMain.h" + +int main(int argc, const char **argv) { + return clang::tidy::clangTidyMain(argc, argv); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits