Skip to content

Commit 3f8b100

Browse files
committed
[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
1 parent be8e38c commit 3f8b100

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

clang-tools-extra/clang-tidy/tool/CMakeLists.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,24 @@ set(LLVM_LINK_COMPONENTS
55
support
66
)
77

8-
add_clang_tool(clang-tidy
8+
# Needed by LLVM's CMake checks because this file defines multiple targets.
9+
set(LLVM_OPTIONAL_SOURCES ClangTidyMain.cpp ClangTidyToolMain.cpp)
10+
11+
add_clang_library(clangTidyMain
912
ClangTidyMain.cpp
13+
14+
LINK_LIBS
15+
clangAST
16+
clangASTMatchers
17+
clangBasic
18+
clangTidy
19+
${ALL_CLANG_TIDY_CHECKS}
20+
clangTooling
21+
clangToolingCore
22+
)
23+
24+
add_clang_tool(clang-tidy
25+
ClangTidyToolMain.cpp
1026
)
1127
add_dependencies(clang-tidy
1228
clang-resource-headers
@@ -22,6 +38,7 @@ clang_target_link_libraries(clang-tidy
2238
target_link_libraries(clang-tidy
2339
PRIVATE
2440
clangTidy
41+
clangTidyMain
2542
${ALL_CLANG_TIDY_CHECKS}
2643
)
2744

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
///
1515
//===----------------------------------------------------------------------===//
1616

17+
#include "ClangTidyMain.h"
1718
#include "../ClangTidy.h"
1819
#include "../ClangTidyForceLinker.h"
1920
#include "../GlobList.h"
@@ -327,7 +328,7 @@ getVfsFromFile(const std::string &OverlayFile,
327328
return FS;
328329
}
329330

330-
static int clangTidyMain(int argc, const char **argv) {
331+
int clangTidyMain(int argc, const char **argv) {
331332
llvm::InitLLVM X(argc, argv);
332333
CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
333334
cl::ZeroOrMore);
@@ -488,7 +489,3 @@ static int clangTidyMain(int argc, const char **argv) {
488489

489490
} // namespace tidy
490491
} // namespace clang
491-
492-
int main(int argc, const char **argv) {
493-
return clang::tidy::clangTidyMain(argc, argv);
494-
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===--- tools/extra/clang-tidy/ClangTidyMain.h - Clang tidy tool -------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file This file declares the main function for the clang-tidy tool.
10+
///
11+
/// This tool uses the Clang Tooling infrastructure, see
12+
/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
13+
/// for details on setting it up with LLVM source tree.
14+
///
15+
//===----------------------------------------------------------------------===//
16+
17+
namespace clang {
18+
namespace tidy {
19+
20+
int clangTidyMain(int argc, const char **argv);
21+
22+
} // namespace tidy
23+
} // namespace clang
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===--- tools/extra/clang-tidy/ClangTidyToolMain.cpp - Clang tidy tool ---===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file This file contains clang-tidy tool entry point main function.
10+
///
11+
/// This tool uses the Clang Tooling infrastructure, see
12+
/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
13+
/// for details on setting it up with LLVM source tree.
14+
///
15+
//===----------------------------------------------------------------------===//
16+
17+
#include "ClangTidyMain.h"
18+
19+
int main(int argc, const char **argv) {
20+
return clang::tidy::clangTidyMain(argc, argv);
21+
}

0 commit comments

Comments
 (0)