From 82c3afcf6f78833e55bc6140799b5809a4527f03 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Wed, 14 Jan 2009 13:01:38 -0500 Subject: [PATCH] ENH: allow ctest_build to return error and warning counts --- Source/CTest/cmCTestBuildCommand.cxx | 28 +++++++++++++++++++++++++++- Source/CTest/cmCTestBuildCommand.h | 15 +++++++++++++-- Source/CTest/cmCTestBuildHandler.cxx | 8 ++++++-- Source/CTest/cmCTestBuildHandler.h | 2 ++ Source/CTest/cmProcess.cxx | 2 +- 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx index 58c3efd91..a98f62153 100644 --- a/Source/CTest/cmCTestBuildCommand.cxx +++ b/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 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; +} diff --git a/Source/CTest/cmCTestBuildCommand.h b/Source/CTest/cmCTestBuildCommand.h index 4853a664f..a961388fd 100644 --- a/Source/CTest/cmCTestBuildCommand.h +++ b/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 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(); }; diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index ca7061b2c..a730981e6 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/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; } //###################################################################### diff --git a/Source/CTest/cmCTestBuildHandler.h b/Source/CTest/cmCTestBuildHandler.h index 73d5a5ac0..cdc1b68a4 100644 --- a/Source/CTest/cmCTestBuildHandler.h +++ b/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. diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx index 75db654ed..37c6a177d 100644 --- a/Source/CTest/cmProcess.cxx +++ b/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; }