Browse Source

ENH: allow ctest_build to return error and warning counts

Bill Hoffman 17 years ago
parent
commit
82c3afcf6f

+ 27 - 1
Source/CTest/cmCTestBuildCommand.cxx

@@ -18,6 +18,7 @@
 
 #include "cmCTest.h"
 #include "cmCTestGenericHandler.h"
+#include "cmCTestBuildHandler.h"
 #include "cmake.h"
 #include "cmGlobalGenerator.h"
 
@@ -26,6 +27,10 @@
 cmCTestBuildCommand::cmCTestBuildCommand()
 {
   this->GlobalGenerator = 0;
+  this->Arguments[ctb_NUMBER_ERRORS] = "NUMBER_ERRORS";
+  this->Arguments[ctb_NUMBER_WARNINGS] = "NUMBER_WARNINGS"; 
+  this->Arguments[ctb_LAST] = 0;
+  this->Last = ctb_LAST;
 }
 
 //----------------------------------------------------------------------------
@@ -48,7 +53,7 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
     this->SetError("internal CTest error. Cannot instantiate build handler");
     return 0;
     }
-
+  this->Handler =  (cmCTestBuildHandler*)handler;
   const char* ctestBuildCommand
     = this->Makefile->GetDefinition("CTEST_BUILD_COMMAND");
   if ( ctestBuildCommand && *ctestBuildCommand )
@@ -132,3 +137,24 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
 }
 
 
+bool cmCTestBuildCommand::InitialPass(std::vector<std::string> const& args,
+                                      cmExecutionStatus &status)
+{
+  bool ret =  cmCTestHandlerCommand::InitialPass(args, status);
+  if ( this->Values[ctb_NUMBER_ERRORS] && *this->Values[ctb_NUMBER_ERRORS])
+    {  
+    cmOStringStream str;
+    str << this->Handler->GetTotalErrors();
+    this->Makefile->AddDefinition(
+      this->Values[ctb_NUMBER_ERRORS], str.str().c_str());
+    }
+  if ( this->Values[ctb_NUMBER_WARNINGS]
+       && *this->Values[ctb_NUMBER_WARNINGS])
+    {
+    cmOStringStream str;
+    str << this->Handler->GetTotalWarnings();
+    this->Makefile->AddDefinition(
+      this->Values[ctb_NUMBER_WARNINGS], str.str().c_str());
+    }
+  return ret;
+}

+ 13 - 2
Source/CTest/cmCTestBuildCommand.h

@@ -20,6 +20,7 @@
 #include "cmCTestHandlerCommand.h"
 
 class cmGlobalGenerator;
+class cmCTestBuildHandler;
 
 /** \class cmCTestBuild
  * \brief Run a ctest script
@@ -56,14 +57,16 @@ public:
     {
     return "Builds the repository.";
     }
-
+  virtual bool InitialPass(std::vector<std::string> const& args,
+                           cmExecutionStatus &status);
   /**
    * More documentation.
    */
   virtual const char* GetFullDocumentation()
     {
     return
-      "  ctest_build([BUILD build_dir] [RETURN_VALUE res])\n"
+      "  ctest_build([BUILD build_dir] [RETURN_VALUE res] "
+      " [NUMBER_ERRORS val] [NUMBER_WARNINGS val])\n"
       "Builds the given build directory and stores results in Build.xml.";
     }
 
@@ -72,6 +75,14 @@ public:
   cmGlobalGenerator* GlobalGenerator;
 
 protected:
+  cmCTestBuildHandler* Handler;
+  enum {
+    ctb_BUILD = ct_LAST,
+    ctb_NUMBER_ERRORS,
+    ctb_NUMBER_WARNINGS,
+    ctb_LAST
+  };
+
   cmCTestGenericHandler* InitializeHandler();
 };
 

+ 6 - 2
Source/CTest/cmCTestBuildHandler.cxx

@@ -475,7 +475,7 @@ int cmCTestBuildHandler::ProcessHandler()
     }
   this->GenerateDartBuildOutput(
     xofs, this->ErrorsAndWarnings, elapsed_build_time);
-  return 0;
+  return res;
 }
 
 //----------------------------------------------------------------------
@@ -724,6 +724,7 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command,
         errorwarning.Error       = false;
         this->ErrorsAndWarnings.push_back(errorwarning);
         this->TotalWarnings ++;
+        return *retVal;  // return the program return value
         }
       }
     }
@@ -734,11 +735,13 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command,
       *retVal = cmsysProcess_GetExitException(cp);
       cmCTestLog(this->CTest, WARNING, "There was an exception: " << *retVal
                  << std::endl);
+      return *retVal;
       }
     }
   else if(result == cmsysProcess_State_Expired)
     {
     cmCTestLog(this->CTest, WARNING, "There was a timeout" << std::endl);
+    return -1;
     }
   else if(result == cmsysProcess_State_Error)
     {
@@ -754,11 +757,12 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command,
     this->TotalErrors ++;
     cmCTestLog(this->CTest, ERROR_MESSAGE, "There was an error: "
       << cmsysProcess_GetErrorString(cp) << std::endl);
+    return -1;
     }
 
   cmsysProcess_Delete(cp);
 
-  return result;
+  return 0;
 }
 
 //######################################################################

+ 2 - 0
Source/CTest/cmCTestBuildHandler.h

@@ -49,6 +49,8 @@ public:
    */
   virtual void Initialize();
 
+  int GetTotalErrors() { return this->TotalErrors;}
+  int GetTotalWarnings() { return this->TotalWarnings;}
 private:
   //! Run command specialized for make and configure. Returns process status
   // and retVal is return value or exception.

+ 1 - 1
Source/CTest/cmProcess.cxx

@@ -213,7 +213,7 @@ bool cmProcess::IsRunning()
   cmsysProcess_WaitForExit(this->Process, 0);
   this->ExitValue = cmsysProcess_GetExitValue(this->Process);
   this->TotalTime = cmSystemTools::GetTime() - this->StartTime;
-//  std::cerr << "Time to run: " << this->TotalTime << "\n";
+  std::cerr << "Time to run: " << this->TotalTime << "\n";
   return false;
 }