[PATCH] clang-check: Enable specification of additional compiler arguments
Pavel Labath
labath at google.com
Wed Jun 5 02:20:56 PDT 2013
Hi klimek,
This adds two command-line parameters: -extra-arg and -extra-arg-before, which
enable the user to pass additional parameters to the compiler command.
http://llvm-reviews.chandlerc.com/D919
Files:
tools/clang-check/ClangCheck.cpp
Index: tools/clang-check/ClangCheck.cpp
===================================================================
--- tools/clang-check/ClangCheck.cpp
+++ tools/clang-check/ClangCheck.cpp
@@ -70,6 +70,11 @@
"fix-what-you-can",
cl::desc(Options->getOptionHelpText(options::OPT_fix_what_you_can)));
+static cl::list<std::string> ArgsAfter("extra-arg",
+ cl::desc("Additional argument to append to the compiler command line"));
+static cl::list<std::string> ArgsBefore("extra-arg-before",
+ cl::desc("Additional argument to prepend to the compiler command line"));
+
namespace {
// FIXME: Move FixItRewriteInPlace from lib/Rewrite/Frontend/FrontendActions.cpp
@@ -123,6 +128,35 @@
}
};
+class InsertAdjuster: public clang::tooling::ArgumentsAdjuster {
+public:
+ enum Position { BEGIN, END };
+
+ InsertAdjuster(const CommandLineArguments &Extra, Position Pos)
+ : Extra(Extra), Pos(Pos) {
+ }
+
+ virtual CommandLineArguments
+ Adjust(const CommandLineArguments &Args) LLVM_OVERRIDE {
+ CommandLineArguments Return(Args);
+
+ CommandLineArguments::iterator I;
+ if (Pos == END)
+ I = Return.end();
+ else {
+ I = Return.begin();
+ ++I;
+ }
+
+ Return.insert(I, Extra.begin(), Extra.end());
+ return Return;
+ }
+
+private:
+ const CommandLineArguments Extra;
+ const Position Pos;
+};
+
} // namespace
// Anonymous namespace here causes problems with gcc <= 4.4 on MacOS 10.6.
@@ -147,6 +181,12 @@
CommonOptionsParser OptionsParser(argc, argv);
ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
+
+ if (ArgsAfter.size() > 0)
+ Tool.appendArgumentsAdjuster(new InsertAdjuster(ArgsAfter, InsertAdjuster::END));
+ if (ArgsBefore.size() > 0)
+ Tool.appendArgumentsAdjuster(new InsertAdjuster(ArgsBefore, InsertAdjuster::BEGIN));
+
if (Fixit)
return Tool.run(newFrontendActionFactory<FixItAction>());
clang_check::ClangCheckActionFactory Factory;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D919.1.patch
Type: text/x-patch
Size: 1990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130605/a796d90a/attachment.bin>
More information about the cfe-commits
mailing list