]> granicus.if.org Git - clang/commitdiff
Driver: Sketch driver support for a CC_LOG_DIAGNOSTICS options, similar to the
authorDaniel Dunbar <daniel@zuster.org>
Thu, 7 Apr 2011 18:01:20 +0000 (18:01 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 7 Apr 2011 18:01:20 +0000 (18:01 +0000)
existing CC_PRINT_OPTIONS and CC_PRINT_HEADERS, which can be used to
transparently capture the compiler diagnostics from a build.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129082 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticFrontendKinds.td
include/clang/Driver/Driver.h
lib/Driver/Driver.cpp
lib/Driver/Tools.cpp
tools/driver/driver.cpp

index 30706769d45e43f696acdb489ded3d6850075763..6ad9529c5f162403543048557b8fce268aeda23b 100644 (file)
@@ -79,6 +79,8 @@ def warn_fe_macro_contains_embedded_newline : Warning<
     "macro '%0' contains embedded newline, text after the newline is ignored.">;
 def warn_fe_cc_print_header_failure : Warning<
     "unable to open CC_PRINT_HEADERS file: %0 (using stderr)">;
+def warn_fe_cc_log_diagnositcs_failure : Warning<
+    "unable to open CC_LOG_DIAGNOSTICS file: %0 (using stderr)">;
 
 def err_verify_missing_start : Error<
     "cannot find start ('{{') of expected %0">;
index 92497ea28d28f39107e7ee1fa2686ec49130efda..56afa02b30db5759b1b223f279603b9134299d7c 100644 (file)
@@ -106,6 +106,9 @@ public:
   /// The file to log CC_PRINT_HEADERS output to, if enabled.
   const char *CCPrintHeadersFilename;
 
+  /// The file to log CC_LOG_DIAGNOSTICS output to, if enabled.
+  const char *CCLogDiagnosticsFilename;
+
   /// Whether the driver should follow g++ like behavior.
   unsigned CCCIsCXX : 1;
 
@@ -126,6 +129,11 @@ public:
   /// information to CCPrintHeadersFilename or to stderr.
   unsigned CCPrintHeaders : 1;
 
+  /// Set CC_LOG_DIAGNOSTICS mode, which causes the frontend to log diagnostics
+  /// to CCLogDiagnosticsFilename or to stderr, in a stable machine readable
+  /// format.
+  unsigned CCLogDiagnostics : 1;
+
 private:
   /// Name to use when calling the generic gcc.
   std::string CCCGenericGCCName;
index 9d02dee540e97249c5b6a7a250870c4b98d6c16d..78720ed0b3cc640ca2c7c110a9530645a009446b 100644 (file)
@@ -63,11 +63,13 @@ Driver::Driver(llvm::StringRef _ClangExecutable,
     DefaultHostTriple(_DefaultHostTriple), DefaultImageName(_DefaultImageName),
     DriverTitle("clang \"gcc-compatible\" driver"),
     Host(0),
-    CCPrintOptionsFilename(0), CCPrintHeadersFilename(0), CCCIsCXX(false),
+    CCPrintOptionsFilename(0), CCPrintHeadersFilename(0),
+    CCLogDiagnosticsFilename(0), CCCIsCXX(false),
     CCCIsCPP(false),CCCEcho(false), CCCPrintBindings(false),
-    CCPrintOptions(false), CCPrintHeaders(false), CCCGenericGCCName("gcc"),
-    CheckInputsExist(true), CCCUseClang(true), CCCUseClangCXX(true),
-    CCCUseClangCPP(true), CCCUsePCH(true), SuppressMissingInputWarning(false) {
+    CCPrintOptions(false), CCPrintHeaders(false), CCLogDiagnostics(false),
+    CCCGenericGCCName("gcc"), CheckInputsExist(true), CCCUseClang(true),
+    CCCUseClangCXX(true), CCCUseClangCPP(true), CCCUsePCH(true),
+    SuppressMissingInputWarning(false) {
   if (IsProduction) {
     // In a "production" build, only use clang on architectures we expect to
     // work, and don't use clang C++.
index e7228229ea2a92ba8200f7627526db305cd5d5fe..77ff2a025f2b2ee468b8918aa7f7b1637027c38e 100644 (file)
@@ -1246,6 +1246,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   Args.AddLastArg(CmdArgs, options::OPT_P);
   Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout);
 
+  if (D.CCLogDiagnostics) {
+    CmdArgs.push_back("-diagnostic-log-file");
+    CmdArgs.push_back(D.CCLogDiagnosticsFilename ?
+                      D.CCLogDiagnosticsFilename : "-");
+  }
+
   // Special case debug options to only pass -g to clang. This is
   // wrong.
   Args.ClaimAllArgs(options::OPT_g_Group);
index 91b48f15484b51e555827a87b7e815d4e2776b10..db72da42ea348527570d4193106a4fda7ec4f630 100644 (file)
@@ -423,6 +423,11 @@ int main(int argc_, const char **argv_) {
   if (TheDriver.CCPrintHeaders)
     TheDriver.CCPrintHeadersFilename = ::getenv("CC_PRINT_HEADERS_FILE");
 
+  // Handle CC_LOG_DIAGNOSTICS and CC_LOG_DIAGNOSTICS_FILE.
+  TheDriver.CCLogDiagnostics = !!::getenv("CC_LOG_DIAGNOSTICS");
+  if (TheDriver.CCLogDiagnostics)
+    TheDriver.CCLogDiagnosticsFilename = ::getenv("CC_LOG_DIAGNOSTICS_FILE");
+
   // Handle QA_OVERRIDE_GCC3_OPTIONS and CCC_ADD_ARGS, used for editing a
   // command line behind the scenes.
   if (const char *OverrideStr = ::getenv("QA_OVERRIDE_GCC3_OPTIONS")) {