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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183398 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Tooling/ArgumentsAdjusters.cpp b/lib/Tooling/ArgumentsAdjusters.cpp
index c44b20d..a69971e 100644
--- a/lib/Tooling/ArgumentsAdjusters.cpp
+++ b/lib/Tooling/ArgumentsAdjusters.cpp
@@ -37,6 +37,23 @@
   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
 
diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp
index cdb9bc7..a121cd0 100644
--- a/lib/Tooling/Tooling.cpp
+++ b/lib/Tooling/Tooling.cpp
@@ -236,8 +236,9 @@
 
 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]));