-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugin-support.patch
95 lines (91 loc) · 4.4 KB
/
plugin-support.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index be068aa8da4a..73f91530d773 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -88,6 +88,7 @@ template <> struct MappingTraits<ClangTidyOptions> {
bool Ignored = false;
IO.mapOptional("Checks", Options.Checks);
IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
+ IO.mapOptional("Plugins", Options.Plugins);
IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
IO.mapOptional("AnalyzeTemporaryDtors", Ignored); // legacy compatibility
IO.mapOptional("FormatStyle", Options.FormatStyle);
@@ -110,6 +111,7 @@ ClangTidyOptions ClangTidyOptions::getDefaults() {
ClangTidyOptions Options;
Options.Checks = "";
Options.WarningsAsErrors = "";
+ Options.Plugins = "";
Options.HeaderFilterRegex = "";
Options.SystemHeaders = false;
Options.FormatStyle = "none";
@@ -146,6 +148,7 @@ ClangTidyOptions &ClangTidyOptions::mergeWith(const ClangTidyOptions &Other,
unsigned Order) {
mergeCommaSeparatedLists(Checks, Other.Checks);
mergeCommaSeparatedLists(WarningsAsErrors, Other.WarningsAsErrors);
+ mergeCommaSeparatedLists(Plugins, Other.Plugins);
overrideValue(HeaderFilterRegex, Other.HeaderFilterRegex);
overrideValue(SystemHeaders, Other.SystemHeaders);
overrideValue(FormatStyle, Other.FormatStyle);
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index d8a4a14f5b52..29c2ff9c62d4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -72,6 +72,9 @@ struct ClangTidyOptions {
/// WarningsAsErrors filter.
llvm::Optional<std::string> WarningsAsErrors;
+ /// List of plugins.
+ llvm::Optional<std::string> Plugins;
+
/// Output warnings from headers matching this filter. Warnings from
/// main files will always be displayed.
llvm::Optional<std::string> HeaderFilterRegex;
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 2466b647c68c..aad9c5a140c5 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -19,6 +19,7 @@
#include "../ClangTidyForceLinker.h"
#include "../GlobList.h"
#include "clang/Tooling/CommonOptionsParser.h"
+#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
@@ -190,6 +191,12 @@ configuration of all checks.
)"),
cl::init(false), cl::cat(ClangTidyCategory));
+static cl::opt<std::string> Plugins("plugins", cl::desc(R"(
+Comma-separated list of plugins:
+ -plugins="my-check.so,..."
+)"),
+ cl::init(""), cl::cat(ClangTidyCategory));
+
static cl::opt<bool> EnableCheckProfile("enable-check-profile", cl::desc(R"(
Enable per-check timing profiles, and print a
report to stderr.
@@ -303,6 +310,8 @@ static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider(
OverrideOptions.Checks = Checks;
if (WarningsAsErrors.getNumOccurrences() > 0)
OverrideOptions.WarningsAsErrors = WarningsAsErrors;
+ if (Plugins.getNumOccurrences() > 0)
+ OverrideOptions.Plugins = Plugins;
if (HeaderFilter.getNumOccurrences() > 0)
OverrideOptions.HeaderFilterRegex = HeaderFilter;
if (SystemHeaders.getNumOccurrences() > 0)
@@ -423,6 +432,18 @@ int clangTidyMain(int argc, const char **argv) {
SmallString<256> FilePath = MakeAbsolute(std::string(FileName));
ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
+ if (EffectiveOptions.Plugins) {
+ SmallVector<StringRef, 10> PluginNames;
+ StringRef(*EffectiveOptions.Plugins).split(PluginNames, ",", -1, false);
+ for (StringRef PluginNameRef : PluginNames) {
+ std::string PluginName = PluginNameRef.str();
+ std::string errMsg;
+ if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(PluginName.c_str(), &errMsg)) {
+ llvm::errs() << "Failed to load plugin " << PluginName << ": " << errMsg << "\n";
+ return 1;
+ }
+ }
+ }
std::vector<std::string> EnabledChecks =
getCheckNames(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers);