[clang-tools-extra] r265542 - [clang-tidy] filter plugins and plugin arguments of the command-line
Etienne Bergeron via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 6 07:07:51 PDT 2016
Author: etienneb
Date: Wed Apr 6 09:07:51 2016
New Revision: 265542
URL: http://llvm.org/viewvc/llvm-project?rev=265542&view=rev
Log:
[clang-tidy] filter plugins and plugin arguments of the command-line
Summary:
This patch remove the plugin argument from the command-line.
Loading plugins was making clang-tidy to fail when running over chromium (linux).
Example of a command-line executed when running clang-tidy over chromium (from the compilation database).
```
../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/third_party/WebKit/Source/core/fetch/webcore_shared.Resource.o.d -DV8_DEPRECATION_WARNINGS -DCLD_VERSION=2 -D_FILE_OFFSET_BITS=64 -DCHROMIUM_BUILD -DCR_CLANG_REVISION=264915-1 -DCOMPONENT_BUILD -DUI_COMPOSITOR_IMAGE_TRANSPORT -DUSE_AURA=1 -DUSE_PANGO=1 -DUSE_CAIRO=1 -DUSE_DEFAULT_RENDER_THEME=1 -DUSE_LIBJPEG_TURBO=1 -DUSE_X11=1 -DUSE_CLIPBOARD_AURAX11=1 -DENABLE_WEBRTC=1 -DENABLE_MEDIA_ROUTER=1 -DENABLE_PEPPER_CDMS -DENABLE_NOTIFICATIONS -DENABLE_TOPCHROME_MD=1 -DUSE_UDEV -DFIELDTRIAL_TESTING_ENABLED -DENABLE_TASK_MANAGER=1 -DENABLE_EXTENSIONS=1 -DENABLE_PDF=1 -DENABLE_PLUGINS=1 -DENABLE_SESSION_SERVICE=1 -DENABLE_THEMES=1 -DENABLE_AUTOFILL_DIALOG=1 -DENABLE_PRINTING=1 -DENABLE_BASIC_PRINTING=1 -DENABLE_PRINT_PREVIEW=1 -DENABLE_SPELLCHECK=1 -DENABLE_CAPTIVE_PORTAL_DETECTION=1 -DENABLE_APP_LIST=1 -DENABLE_SETTINGS_APP=1 -DENABLE_SUPERVISED_USERS=1 -DENABLE_MDNS=1 -DENABLE_SERVICE_DISCOVERY=1 -DV8_USE_EXTERNAL_STARTU
P_DATA -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DBLINK_CORE_IMPLEMENTATION=1 -DBLINK_IMPLEMENTATION=1 -DINSIDE_BLINK -DGL_GLEXT_PROTOTYPES -DMOJO_USE_SYSTEM_IMPL -DCHROME_PNG_WRITE_SUPPORT -DPNG_USER_CONFIG -DENABLE_LAYOUT_UNIT_IN_INLINE_BOXES=0 -DENABLE_OILPAN=1 -DWTF_USE_CONCATENATED_IMPULSE_RESPONSES=1 -DENABLE_INPUT_MULTIPLE_FIELDS_UI=1 -DWTF_USE_ICCJPEG=1 -DWTF_USE_QCMSLIB=1 -DWTF_USE_WEBAUDIO_FFMPEG=1 -DWTF_USE_DEFAULT_RENDER_THEME=1 -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 -DU_NOEXCEPT= -DSKIA_DLL -DGR_GL_IGNORE_ES3_MSAA=0 -DSK_SUPPORT_GPU=1 -DSK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS -DLIBXML_STATIC -DLIBXSLT_STATIC -DV8_SHARED -DUSING_V8_SHARED -DUSE_LIBPCI=1 -DUSE_OPENSSL=1 -DUSE_GLIB=1 -DUSE_NSS_CERTS=1 -DUSE_NSS_VERIFIER=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -D_DEBUG -D_GLIBCXX_DEBUG=1 -Igen -I../../third_party/WebKit/Source -Igen/blink -I../../third_party/WebKit -I../
../third_party/WebKit/Source/core/testing -I../../third_party/WebKit/Source/core/testing/v8 -I../.. -I../../skia/config -I../../third_party/khronos -I../../gpu -Igen/angle -I../../third_party/angle/include -I../../third_party/ffmpeg -Igen/third_party/WebKit -I../../third_party/iccjpeg -I../../third_party/libpng -I../../third_party/libwebp -I../../third_party/ots/include -I../../third_party/zlib -I../../third_party/libjpeg_turbo -I../../third_party/icu/source/i18n -I../../third_party/icu/source/common -I../../skia/ext -I../../third_party/skia/include/core -I../../third_party/skia/include/effects -I../../third_party/skia/include/pdf -I../../third_party/skia/include/gpu -I../../third_party/skia/include/lazy -I../../third_party/skia/include/pathops -I../../third_party/skia/include/pipe -I../../third_party/skia/include/ports -I../../third_party/skia/include/utils -I../../third_party/libxml/linux/include -I../../third_party/libxml/src/include -I../../third_party/libxslt -I../../third_part
y/npapi -I../../third_party/npapi/bindings -I../../third_party/qcms/src -I../../third_party/snappy/linux -I../../third_party/snappy/src -I../../v8/include -fstack-protector --param=ssp-buffer-size=4 -Werror -pthread -fno-strict-aliasing -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -fvisibility=hidden -pipe -fPIC -Xclang -load -Xclang /home/etienneb/chromium/src/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-templates -Xclang -plugin-arg-find-bad-constructs -Xclang follow-macro-expansion -fcolor-diagnostics -B/home/etienneb/chromium/src/third_party/binutils/Linux_x64/Release/bin -Wheader-hygiene -Wno-char-subscripts -Wno-unneeded-internal-declaration -Wno-covered-switch-default -Wstring-conversion -Wno-c++11-narrowing -Wno-deprecated-register -Wno-inconsistent-missing-override -Wno-shift-negative-value -Wglobal-constructors -Wexit-time-destr
uctors -fno-strict-aliasing -Xclang -load -Xclang /home/etienneb/chromium/src/third_party/llvm-build/Release+Asserts/lib/libBlinkGCPlugin.so -Xclang -add-plugin -Xclang blink-gc-plugin -Xclang -plugin-arg-blink-gc-plugin -Xclang enable-oilpan -Xclang -plugin-arg-blink-gc-plugin -Xclang warn-raw-ptr -pthread -I/home/etienneb/chromium/src/build/linux/debian_wheezy_amd64-sysroot/usr/include/glib-2.0 -I/home/etienneb/chromium/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu/glib-2.0/include -m64 -march=x86-64 --sysroot=/home/etienneb/chromium/src/build/linux/debian_wheezy_amd64-sysroot -O0 -g -funwind-tables -gsplit-dwarf -g0 -fno-exceptions -fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -std=gnu++11 -c ../../third_party/WebKit/Source/core/fetch/Resource.cpp -o obj/third_party/WebKit/Source/core/fetch/webcore_shared.Resource.o
```
The plugins are added with the following arguments:
```
-Xclang -load -Xclang /home/etienneb/chromium/src/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-templates -Xclang -plugin-arg-find-bad-constructs -Xclang follow-macro-expansion
```
Reviewers: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D18806
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=265542&r1=265541&r2=265542&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Wed Apr 6 09:07:51 2016
@@ -107,9 +107,7 @@ public:
DiagPrinter->BeginSourceFile(LangOpts);
}
- SourceManager& getSourceManager() {
- return SourceMgr;
- }
+ SourceManager &getSourceManager() { return SourceMgr; }
void reportDiagnostic(const ClangTidyError &Error) {
const ClangTidyMessage &Message = Error.Message;
@@ -141,7 +139,7 @@ public:
Range = SourceRange(FixLoc, FixEndLoc);
Diag << FixItHint::CreateReplacement(Range, Fix.getReplacementText());
}
-
+
++TotalFixes;
if (ApplyFixes) {
bool Success = Fix.isApplicable() && Fix.apply(Rewrite);
@@ -417,19 +415,39 @@ runClangTidy(std::unique_ptr<ClangTidyOp
std::vector<ClangTidyError> *Errors, ProfileData *Profile) {
ClangTool Tool(Compilations, InputFiles);
clang::tidy::ClangTidyContext Context(std::move(OptionsProvider));
- ArgumentsAdjuster PerFileExtraArgumentsInserter = [&Context](
- const CommandLineArguments &Args, StringRef Filename) {
- ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
- CommandLineArguments AdjustedArgs;
- if (Opts.ExtraArgsBefore)
- AdjustedArgs = *Opts.ExtraArgsBefore;
- AdjustedArgs.insert(AdjustedArgs.begin(), Args.begin(), Args.end());
- if (Opts.ExtraArgs)
- AdjustedArgs.insert(AdjustedArgs.end(), Opts.ExtraArgs->begin(),
- Opts.ExtraArgs->end());
- return AdjustedArgs;
- };
+
+ // Add extra arguments passed by the clang-tidy command-line.
+ ArgumentsAdjuster PerFileExtraArgumentsInserter =
+ [&Context](const CommandLineArguments &Args, StringRef Filename) {
+ ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
+ CommandLineArguments AdjustedArgs;
+ if (Opts.ExtraArgsBefore)
+ AdjustedArgs = *Opts.ExtraArgsBefore;
+ AdjustedArgs.insert(AdjustedArgs.begin(), Args.begin(), Args.end());
+ if (Opts.ExtraArgs)
+ AdjustedArgs.insert(AdjustedArgs.end(), Opts.ExtraArgs->begin(),
+ Opts.ExtraArgs->end());
+ return AdjustedArgs;
+ };
+
+ // Remove plugins arguments.
+ ArgumentsAdjuster PluginArgumentsRemover =
+ [&Context](const CommandLineArguments &Args, StringRef Filename) {
+ CommandLineArguments AdjustedArgs;
+ for (size_t I = 0, E = Args.size(); I < E; ++I) {
+ if (I + 4 < Args.size() && Args[I] == "-Xclang" &&
+ (Args[I + 1] == "-load" || Args[I + 1] == "-add-plugin" ||
+ StringRef(Args[I + 1]).startswith("-plugin-arg-")) &&
+ Args[I + 2] == "-Xclang") {
+ I += 3;
+ } else
+ AdjustedArgs.push_back(Args[I]);
+ }
+ return AdjustedArgs;
+ };
+
Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter);
+ Tool.appendArgumentsAdjuster(PluginArgumentsRemover);
if (Profile)
Context.setCheckProfileData(Profile);
More information about the cfe-commits
mailing list