[PATCH] Make clang tools ignore -fcolor-diagnostics and -fdiagnostics-color retrieved from the compilation database.

Alexander Kornienko alexfh at google.com
Tue Jun 4 12:40:13 PDT 2013


Hi klimek,

Clang tools' diagnostic output could be force colored when a command
line from the compilation database contains -fcolor-diagnostics or
-fdiagnostics-color. This is not what we want e.g. for vim integration.

http://llvm-reviews.chandlerc.com/D917

Files:
  lib/Tooling/ArgumentsAdjusters.cpp

Index: lib/Tooling/ArgumentsAdjusters.cpp
===================================================================
--- lib/Tooling/ArgumentsAdjusters.cpp
+++ lib/Tooling/ArgumentsAdjusters.cpp
@@ -13,6 +13,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Tooling/ArgumentsAdjusters.h"
+#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/StringRef.h"
 
 namespace clang {
 namespace tooling {
@@ -23,8 +25,15 @@
 /// Add -fsyntax-only option to the commnand line arguments.
 CommandLineArguments
 ClangSyntaxOnlyAdjuster::Adjust(const CommandLineArguments &Args) {
-  CommandLineArguments AdjustedArgs = Args;
-  // FIXME: Remove options that generate output.
+  CommandLineArguments AdjustedArgs;
+  AdjustedArgs.reserve(Args.size() + 1);
+  for (size_t i = 0, e = Args.size(); i < e; ++i) {
+    StringRef Arg = Args[i];
+    // FIXME: Remove options that generate output.
+    if (!Arg.startswith("-fcolor-diagnostics") &&
+        !Arg.startswi th("-fdiagnostics-color"))
+      AdjustedArgs.push_back(Args[i]);
+  }
   AdjustedArgs.push_back("-fsyntax-only");
   return AdjustedArgs;
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D917.1.patch
Type: text/x-patch
Size: 1142 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130604/90393e14/attachment.bin>


More information about the cfe-commits mailing list