r183398 - ClangTool: strip -o from the command line
Pavel Labath
labath at google.com
Thu Jun 6 04:52:19 PDT 2013
Author: labath
Date: Thu Jun 6 06:52:19 2013
New Revision: 183398
URL: http://llvm.org/viewvc/llvm-project?rev=183398&view=rev
Log:
ClangTool: strip -o from the command line
Summary:
This patch creates a new ArgumentsAdjuster, which removes all -o parameters from
the command line. This adjuster is inserted by default into the ClangTool pipeline.
Reviewers: klimek
CC: cfe-commits, revane
Differential Revision: http://llvm-reviews.chandlerc.com/D925
Added:
cfe/trunk/test/Tooling/clang-check-strip-o.cpp
Modified:
cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h
cfe/trunk/include/clang/Tooling/Tooling.h
cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
cfe/trunk/lib/Tooling/Tooling.cpp
Modified: cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h?rev=183398&r1=183397&r2=183398&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h (original)
+++ cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h Thu Jun 6 06:52:19 2013
@@ -52,6 +52,12 @@ class ClangSyntaxOnlyAdjuster : public A
virtual CommandLineArguments Adjust(const CommandLineArguments &Args);
};
+/// \brief An argument adjuster which removes output-related command line
+/// arguments.
+class ClangStripOutputAdjuster : public ArgumentsAdjuster {
+ virtual CommandLineArguments Adjust(const CommandLineArguments &Args);
+};
+
} // end namespace tooling
} // end namespace clang
Modified: cfe/trunk/include/clang/Tooling/Tooling.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=183398&r1=183397&r2=183398&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/Tooling.h (original)
+++ cfe/trunk/include/clang/Tooling/Tooling.h Thu Jun 6 06:52:19 2013
@@ -233,7 +233,7 @@ class ClangTool {
// Contains a list of pairs (<file name>, <file content>).
std::vector< std::pair<StringRef, StringRef> > MappedFileContents;
- SmallVector<ArgumentsAdjuster *, 1> ArgsAdjusters;
+ SmallVector<ArgumentsAdjuster *, 2> ArgsAdjusters;
};
template <typename T>
Modified: cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp?rev=183398&r1=183397&r2=183398&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp (original)
+++ cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp Thu Jun 6 06:52:19 2013
@@ -37,6 +37,23 @@ ClangSyntaxOnlyAdjuster::Adjust(const Co
return AdjustedArgs;
}
+CommandLineArguments
+ClangStripOutputAdjuster::Adjust(const CommandLineArguments &Args) {
+ CommandLineArguments AdjustedArgs;
+ for (size_t i = 0, e = Args.size(); i < e; ++i) {
+ StringRef Arg = Args[i];
+ if(!Arg.startswith("-o"))
+ AdjustedArgs.push_back(Args[i]);
+
+ if(Arg == "-o") {
+ // Output is specified as -o foo. Skip the next argument also.
+ ++i;
+ }
+ // Else, the output is specified as -ofoo. Just do nothing.
+ }
+ return AdjustedArgs;
+}
+
} // end namespace tooling
} // end namespace clang
Modified: cfe/trunk/lib/Tooling/Tooling.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=183398&r1=183397&r2=183398&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)
+++ cfe/trunk/lib/Tooling/Tooling.cpp Thu Jun 6 06:52:19 2013
@@ -236,8 +236,9 @@ void ToolInvocation::addFileMappingsTo(S
ClangTool::ClangTool(const CompilationDatabase &Compilations,
ArrayRef<std::string> SourcePaths)
- : Files((FileSystemOptions())),
- ArgsAdjusters(1, new ClangSyntaxOnlyAdjuster()) {
+ : Files((FileSystemOptions())) {
+ ArgsAdjusters.push_back(new ClangStripOutputAdjuster());
+ ArgsAdjusters.push_back(new ClangSyntaxOnlyAdjuster());
for (unsigned I = 0, E = SourcePaths.size(); I != E; ++I) {
SmallString<1024> File(getAbsolutePath(SourcePaths[I]));
Added: cfe/trunk/test/Tooling/clang-check-strip-o.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/clang-check-strip-o.cpp?rev=183398&view=auto
==============================================================================
--- cfe/trunk/test/Tooling/clang-check-strip-o.cpp (added)
+++ cfe/trunk/test/Tooling/clang-check-strip-o.cpp Thu Jun 6 06:52:19 2013
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo '[{"directory":".","command":"clang++ -c %t/test.cpp -o foo -ofoo","file":"%t/test.cpp"}]' | sed -e 's/\\/\//g' > %t/compile_commands.json
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-check -p "%t" "%t/test.cpp" -extra-arg=-v 2>&1|FileCheck %s
+// FIXME: Make the above easier.
+
+// CHECK: Invocation
+// CHECK-NOT: {{ -v}}
+// CHECK: C++ requires
+invalid;
More information about the cfe-commits
mailing list