diff options
author | Kitware Robot <kwrobot@kitware.com> | 2016-05-16 14:34:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-05-16 20:05:19 (GMT) |
commit | d9fd2f5402eeaa345691313658e02b51038f570b (patch) | |
tree | dca71b9a7e267f4c6300da3eb770415381726785 /Source/CTest/cmCTestScriptHandler.cxx | |
parent | 82df6deaafb36cbbfd450202bb20b320f637751a (diff) | |
download | CMake-d9fd2f5402eeaa345691313658e02b51038f570b.zip CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.gz CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.bz2 |
Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update
all our C++ code to a new style defined by `.clang-format`.
Use `clang-format` version 3.8.
* If you reached this commit for a line in `git blame`, re-run the blame
operation starting at the parent of this commit to see older history
for the content.
* See the parent commit for instructions to rebase a change across this
style transition commit.
Diffstat (limited to 'Source/CTest/cmCTestScriptHandler.cxx')
-rw-r--r-- | Source/CTest/cmCTestScriptHandler.cxx | 691 |
1 files changed, 280 insertions, 411 deletions
diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index bde7a6d..0c09cc7 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -35,7 +35,7 @@ // needed for sleep #if !defined(_WIN32) -# include <unistd.h> +#include <unistd.h> #endif #include "cmCTestBuildCommand.h" @@ -60,19 +60,18 @@ class cmCTestScriptFunctionBlocker : public cmFunctionBlocker public: cmCTestScriptFunctionBlocker() {} virtual ~cmCTestScriptFunctionBlocker() {} - virtual bool IsFunctionBlocked(const cmListFileFunction& lff, - cmMakefile &mf, - cmExecutionStatus &); - //virtual bool ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf); - //virtual void ScopeEnded(cmMakefile &mf); + virtual bool IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile& mf, + cmExecutionStatus&); + // virtual bool ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf); + // virtual void ScopeEnded(cmMakefile &mf); cmCTestScriptHandler* CTestScriptHandler; }; // simply update the time and don't block anything -bool cmCTestScriptFunctionBlocker:: -IsFunctionBlocked(const cmListFileFunction& , cmMakefile &, - cmExecutionStatus &) +bool cmCTestScriptFunctionBlocker::IsFunctionBlocked(const cmListFileFunction&, + cmMakefile&, + cmExecutionStatus&) { this->CTestScriptHandler->UpdateElapsedTime(); return false; @@ -90,7 +89,7 @@ cmCTestScriptHandler::cmCTestScriptHandler() this->ScriptStartTime = 0; // the *60 is becuase the settings are in minutes but GetTime is seconds - this->MinimumInterval = 30*60; + this->MinimumInterval = 30 * 60; this->ContinuousDuration = -1; } @@ -115,7 +114,7 @@ void cmCTestScriptHandler::Initialize() this->CMOutFile = ""; this->ExtraUpdates.clear(); - this->MinimumInterval = 20*60; + this->MinimumInterval = 20 * 60; this->ContinuousDuration = -1; // what time in seconds did this script start running @@ -137,46 +136,41 @@ cmCTestScriptHandler::~cmCTestScriptHandler() delete this->CMake; } - // just adds an argument to the vector -void cmCTestScriptHandler::AddConfigurationScript(const char *script, +void cmCTestScriptHandler::AddConfigurationScript(const char* script, bool pscope) { this->ConfigurationScripts.push_back(script); this->ScriptProcessScope.push_back(pscope); } - // the generic entry point for handling scripts, this routine will run all // the scripts provides a -S arguments int cmCTestScriptHandler::ProcessHandler() { int res = 0; - for (size_t i=0; i < this->ConfigurationScripts.size(); ++i) - { + for (size_t i = 0; i < this->ConfigurationScripts.size(); ++i) { // for each script run it - res |= this->RunConfigurationScript - (cmSystemTools::CollapseFullPath(this->ConfigurationScripts[i]), - this->ScriptProcessScope[i]); - } - if ( res ) - { + res |= this->RunConfigurationScript( + cmSystemTools::CollapseFullPath(this->ConfigurationScripts[i]), + this->ScriptProcessScope[i]); + } + if (res) { return -1; - } + } return 0; } void cmCTestScriptHandler::UpdateElapsedTime() { - if (this->Makefile) - { + if (this->Makefile) { // set the current elapsed time char timeString[20]; - int itime = static_cast<unsigned int>(cmSystemTools::GetTime() - - this->ScriptStartTime); - sprintf(timeString,"%i",itime); + int itime = static_cast<unsigned int>(cmSystemTools::GetTime() - + this->ScriptStartTime); + sprintf(timeString, "%i", itime); this->Makefile->AddDefinition("CTEST_ELAPSED_TIME", timeString); - } + } } void cmCTestScriptHandler::AddCTestCommand(cmCTestCommand* command) @@ -196,115 +190,97 @@ int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg) argv.push_back("-SR"); argv.push_back(total_script_arg.c_str()); - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Executable for CTest is: " << - cmSystemTools::GetCTestCommand() << "\n"); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Executable for CTest is: " + << cmSystemTools::GetCTestCommand() << "\n"); // now pass through all the other arguments - std::vector<std::string> &initArgs = + std::vector<std::string>& initArgs = this->CTest->GetInitialCommandLineArguments(); //*** need to make sure this does not have the current script *** - for(size_t i=1; i < initArgs.size(); ++i) - { + for (size_t i = 1; i < initArgs.size(); ++i) { argv.push_back(initArgs[i].c_str()); - } + } argv.push_back(0); // Now create process object cmsysProcess* cp = cmsysProcess_New(); cmsysProcess_SetCommand(cp, &*argv.begin()); - //cmsysProcess_SetWorkingDirectory(cp, dir); + // cmsysProcess_SetWorkingDirectory(cp, dir); cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); - //cmsysProcess_SetTimeout(cp, timeout); + // cmsysProcess_SetTimeout(cp, timeout); cmsysProcess_Execute(cp); std::vector<char> out; std::vector<char> err; std::string line; int pipe = cmSystemTools::WaitForLine(cp, line, 100.0, out, err); - while(pipe != cmsysProcess_Pipe_None) - { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Output: " - << line << "\n"); - if(pipe == cmsysProcess_Pipe_STDERR) - { + while (pipe != cmsysProcess_Pipe_None) { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Output: " << line + << "\n"); + if (pipe == cmsysProcess_Pipe_STDERR) { cmCTestLog(this->CTest, ERROR_MESSAGE, line << "\n"); - } - else if(pipe == cmsysProcess_Pipe_STDOUT) - { + } else if (pipe == cmsysProcess_Pipe_STDOUT) { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, line << "\n"); - } - pipe = cmSystemTools::WaitForLine(cp, line, 100, out, err); } + pipe = cmSystemTools::WaitForLine(cp, line, 100, out, err); + } // Properly handle output of the build command cmsysProcess_WaitForExit(cp, 0); int result = cmsysProcess_GetState(cp); int retVal = 0; bool failed = false; - if(result == cmsysProcess_State_Exited) - { + if (result == cmsysProcess_State_Exited) { retVal = cmsysProcess_GetExitValue(cp); - } - else if(result == cmsysProcess_State_Exception) - { + } else if (result == cmsysProcess_State_Exception) { retVal = cmsysProcess_GetExitException(cp); cmCTestLog(this->CTest, ERROR_MESSAGE, "\tThere was an exception: " - << cmsysProcess_GetExceptionString(cp) << " " << - retVal << std::endl); + << cmsysProcess_GetExceptionString(cp) << " " << retVal + << std::endl); failed = true; - } - else if(result == cmsysProcess_State_Expired) - { + } else if (result == cmsysProcess_State_Expired) { cmCTestLog(this->CTest, ERROR_MESSAGE, "\tThere was a timeout" - << std::endl); + << std::endl); failed = true; - } - else if(result == cmsysProcess_State_Error) - { + } else if (result == cmsysProcess_State_Error) { cmCTestLog(this->CTest, ERROR_MESSAGE, "\tError executing ctest: " - << cmsysProcess_GetErrorString(cp) << std::endl); + << cmsysProcess_GetErrorString(cp) << std::endl); failed = true; - } + } cmsysProcess_Delete(cp); - if(failed) - { + if (failed) { std::ostringstream message; message << "Error running command: ["; message << result << "] "; - for(std::vector<const char*>::iterator i = argv.begin(); - i != argv.end(); ++i) - { - if(*i) - { - message << *i << " "; - } + for (std::vector<const char*>::iterator i = argv.begin(); i != argv.end(); + ++i) { + if (*i) { + message << *i << " "; } - cmCTestLog(this->CTest, ERROR_MESSAGE, - message.str() << argv[0] << std::endl); - return -1; } + cmCTestLog(this->CTest, ERROR_MESSAGE, message.str() << argv[0] + << std::endl); + return -1; + } return retVal; } -static void ctestScriptProgressCallback(const char *m, float, void* cd) +static void ctestScriptProgressCallback(const char* m, float, void* cd) { cmCTest* ctest = static_cast<cmCTest*>(cd); - if(m && *m) - { + if (m && *m) { cmCTestLog(ctest, HANDLER_OUTPUT, "-- " << m << std::endl); - } + } } void cmCTestScriptHandler::CreateCMake() { // create a cmake instance to read the configuration script - if (this->CMake) - { + if (this->CMake) { delete this->CMake; delete this->GlobalGenerator; delete this->Makefile; - } + } this->CMake = new cmake; this->CMake->SetHomeDirectory(""); this->CMake->SetHomeOutputDirectory(""); @@ -354,27 +330,25 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) // passed into the scripts as S_ARG std::string script = total_script_arg; std::string script_arg; - if (total_script_arg.find(",") != std::string::npos) - { - script = total_script_arg.substr(0,total_script_arg.find(",")); - script_arg = total_script_arg.substr(total_script_arg.find(",")+1); - } + if (total_script_arg.find(",") != std::string::npos) { + script = total_script_arg.substr(0, total_script_arg.find(",")); + script_arg = total_script_arg.substr(total_script_arg.find(",") + 1); + } // make sure the file exists - if (!cmSystemTools::FileExists(script.c_str())) - { + if (!cmSystemTools::FileExists(script.c_str())) { cmSystemTools::Error("Cannot find file: ", script.c_str()); return 1; - } + } // read in the list file to fill the cache // create a cmake instance to read the configuration script this->CreateCMake(); // set a variable with the path to the current script - this->Makefile->AddDefinition("CTEST_SCRIPT_DIRECTORY", - cmSystemTools::GetFilenamePath(script).c_str()); - this->Makefile->AddDefinition("CTEST_SCRIPT_NAME", - cmSystemTools::GetFilenameName(script).c_str()); + this->Makefile->AddDefinition( + "CTEST_SCRIPT_DIRECTORY", cmSystemTools::GetFilenamePath(script).c_str()); + this->Makefile->AddDefinition( + "CTEST_SCRIPT_NAME", cmSystemTools::GetFilenameName(script).c_str()); this->Makefile->AddDefinition("CTEST_EXECUTABLE_NAME", cmSystemTools::GetCTestCommand().c_str()); this->Makefile->AddDefinition("CMAKE_EXECUTABLE_NAME", @@ -383,59 +357,53 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) this->UpdateElapsedTime(); // add the script arg if defined - if (!script_arg.empty()) - { + if (!script_arg.empty()) { this->Makefile->AddDefinition("CTEST_SCRIPT_ARG", script_arg.c_str()); - } + } #if defined(__CYGWIN__) this->Makefile->AddDefinition("CMAKE_LEGACY_CYGWIN_WIN32", "0"); #endif // always add a function blocker to update the elapsed time - cmCTestScriptFunctionBlocker *f = new cmCTestScriptFunctionBlocker(); + cmCTestScriptFunctionBlocker* f = new cmCTestScriptFunctionBlocker(); f->CTestScriptHandler = this; this->Makefile->AddFunctionBlocker(f); - /* Execute CTestScriptMode.cmake, which loads CMakeDetermineSystem and CMakeSystemSpecificInformation, so that variables like CMAKE_SYSTEM and also the search paths for libraries, header and executables are set correctly and can be used. Makes new-style ctest scripting easier. */ std::string systemFile = - this->Makefile->GetModulesFile("CTestScriptMode.cmake"); + this->Makefile->GetModulesFile("CTestScriptMode.cmake"); if (!this->Makefile->ReadListFile(systemFile.c_str()) || - cmSystemTools::GetErrorOccuredFlag()) - { - cmCTestLog(this->CTest, ERROR_MESSAGE, "Error in read:" - << systemFile << "\n"); + cmSystemTools::GetErrorOccuredFlag()) { + cmCTestLog(this->CTest, ERROR_MESSAGE, "Error in read:" << systemFile + << "\n"); return 2; - } + } // Add definitions of variables passed in on the command line: - const std::map<std::string, std::string> &defs = + const std::map<std::string, std::string>& defs = this->CTest->GetDefinitions(); for (std::map<std::string, std::string>::const_iterator it = defs.begin(); - it != defs.end(); ++it) - { + it != defs.end(); ++it) { this->Makefile->AddDefinition(it->first, it->second.c_str()); - } + } // finally read in the script if (!this->Makefile->ReadListFile(script.c_str()) || - cmSystemTools::GetErrorOccuredFlag()) - { + cmSystemTools::GetErrorOccuredFlag()) { // Reset the error flag so that it can run more than // one script with an error when you use ctest_run_script. cmSystemTools::ResetErrorOccuredFlag(); return 2; - } + } return 0; } - // extract variabels from the script to set ivars int cmCTestScriptHandler::ExtractVariables() { @@ -443,80 +411,64 @@ int cmCTestScriptHandler::ExtractVariables() const char* minInterval; const char* contDuration; - this->SourceDir - = this->Makefile->GetSafeDefinition("CTEST_SOURCE_DIRECTORY"); - this->BinaryDir - = this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY"); + this->SourceDir = + this->Makefile->GetSafeDefinition("CTEST_SOURCE_DIRECTORY"); + this->BinaryDir = + this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY"); // add in translations for src and bin cmSystemTools::AddKeepPath(this->SourceDir); cmSystemTools::AddKeepPath(this->BinaryDir); - this->CTestCmd - = this->Makefile->GetSafeDefinition("CTEST_COMMAND"); - this->CVSCheckOut - = this->Makefile->GetSafeDefinition("CTEST_CVS_CHECKOUT"); - this->CTestRoot - = this->Makefile->GetSafeDefinition("CTEST_DASHBOARD_ROOT"); - this->UpdateCmd - = this->Makefile->GetSafeDefinition("CTEST_UPDATE_COMMAND"); - if ( this->UpdateCmd.empty() ) - { - this->UpdateCmd - = this->Makefile->GetSafeDefinition("CTEST_CVS_COMMAND"); - } - this->CTestEnv - = this->Makefile->GetSafeDefinition("CTEST_ENVIRONMENT"); - this->InitialCache - = this->Makefile->GetSafeDefinition("CTEST_INITIAL_CACHE"); - this->CMakeCmd - = this->Makefile->GetSafeDefinition("CTEST_CMAKE_COMMAND"); - this->CMOutFile - = this->Makefile->GetSafeDefinition("CTEST_CMAKE_OUTPUT_FILE_NAME"); - - this->Backup - = this->Makefile->IsOn("CTEST_BACKUP_AND_RESTORE"); - this->EmptyBinDir - = this->Makefile->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY"); - this->EmptyBinDirOnce - = this->Makefile->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY_ONCE"); - - minInterval - = this->Makefile->GetDefinition("CTEST_CONTINUOUS_MINIMUM_INTERVAL"); - contDuration - = this->Makefile->GetDefinition("CTEST_CONTINUOUS_DURATION"); + this->CTestCmd = this->Makefile->GetSafeDefinition("CTEST_COMMAND"); + this->CVSCheckOut = this->Makefile->GetSafeDefinition("CTEST_CVS_CHECKOUT"); + this->CTestRoot = this->Makefile->GetSafeDefinition("CTEST_DASHBOARD_ROOT"); + this->UpdateCmd = this->Makefile->GetSafeDefinition("CTEST_UPDATE_COMMAND"); + if (this->UpdateCmd.empty()) { + this->UpdateCmd = this->Makefile->GetSafeDefinition("CTEST_CVS_COMMAND"); + } + this->CTestEnv = this->Makefile->GetSafeDefinition("CTEST_ENVIRONMENT"); + this->InitialCache = + this->Makefile->GetSafeDefinition("CTEST_INITIAL_CACHE"); + this->CMakeCmd = this->Makefile->GetSafeDefinition("CTEST_CMAKE_COMMAND"); + this->CMOutFile = + this->Makefile->GetSafeDefinition("CTEST_CMAKE_OUTPUT_FILE_NAME"); + + this->Backup = this->Makefile->IsOn("CTEST_BACKUP_AND_RESTORE"); + this->EmptyBinDir = + this->Makefile->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY"); + this->EmptyBinDirOnce = + this->Makefile->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY_ONCE"); + + minInterval = + this->Makefile->GetDefinition("CTEST_CONTINUOUS_MINIMUM_INTERVAL"); + contDuration = this->Makefile->GetDefinition("CTEST_CONTINUOUS_DURATION"); char updateVar[40]; int i; - for (i = 1; i < 10; ++i) - { - sprintf(updateVar,"CTEST_EXTRA_UPDATES_%i",i); - const char *updateVal = this->Makefile->GetDefinition(updateVar); - if ( updateVal ) - { - if ( this->UpdateCmd.empty() ) - { - cmSystemTools::Error(updateVar, - " specified without specifying CTEST_CVS_COMMAND."); + for (i = 1; i < 10; ++i) { + sprintf(updateVar, "CTEST_EXTRA_UPDATES_%i", i); + const char* updateVal = this->Makefile->GetDefinition(updateVar); + if (updateVal) { + if (this->UpdateCmd.empty()) { + cmSystemTools::Error( + updateVar, " specified without specifying CTEST_CVS_COMMAND."); return 12; - } - this->ExtraUpdates.push_back(updateVal); } + this->ExtraUpdates.push_back(updateVal); } + } // in order to backup and restore we also must have the cvs root - if (this->Backup && this->CVSCheckOut.empty()) - { + if (this->Backup && this->CVSCheckOut.empty()) { cmSystemTools::Error( "Backup was requested without specifying CTEST_CVS_CHECKOUT."); return 3; - } + } // make sure the required info is here - if (this->SourceDir.empty() || - this->BinaryDir.empty() || - this->CTestCmd.empty()) - { + if (this->SourceDir.empty() || this->BinaryDir.empty() || + this->CTestCmd.empty()) { std::string msg = "CTEST_SOURCE_DIRECTORY = "; msg += (!this->SourceDir.empty()) ? this->SourceDir.c_str() : "(Null)"; msg += "\nCTEST_BINARY_DIRECTORY = "; @@ -527,25 +479,21 @@ int cmCTestScriptHandler::ExtractVariables() "Some required settings in the configuration file were missing:\n", msg.c_str()); return 4; - } + } // if the dashboard root isn't specified then we can compute it from the // this->SourceDir - if (this->CTestRoot.empty() ) - { + if (this->CTestRoot.empty()) { this->CTestRoot = cmSystemTools::GetFilenamePath(this->SourceDir).c_str(); - } + } // the script may override the minimum continuous interval - if (minInterval) - { + if (minInterval) { this->MinimumInterval = 60 * atof(minInterval); - } - if (contDuration) - { + } + if (contDuration) { this->ContinuousDuration = 60.0 * atof(contDuration); - } - + } this->UpdateElapsedTime(); @@ -555,15 +503,15 @@ int cmCTestScriptHandler::ExtractVariables() void cmCTestScriptHandler::SleepInSeconds(unsigned int secondsToWait) { #if defined(_WIN32) - Sleep(1000*secondsToWait); + Sleep(1000 * secondsToWait); #else - sleep(secondsToWait); + sleep(secondsToWait); #endif } // run a specific script -int cmCTestScriptHandler::RunConfigurationScript -(const std::string& total_script_arg, bool pscope) +int cmCTestScriptHandler::RunConfigurationScript( + const std::string& total_script_arg, bool pscope) { #ifdef CMAKE_BUILD_WITH_CMAKE cmSystemTools::SaveRestoreEnvironment sre; @@ -571,32 +519,26 @@ int cmCTestScriptHandler::RunConfigurationScript int result; - this->ScriptStartTime = - cmSystemTools::GetTime(); + this->ScriptStartTime = cmSystemTools::GetTime(); // read in the script - if (pscope) - { + if (pscope) { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Reading Script: " << total_script_arg << std::endl); + "Reading Script: " << total_script_arg << std::endl); result = this->ReadInScript(total_script_arg); - } - else - { + } else { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Executing Script: " << total_script_arg << std::endl); + "Executing Script: " << total_script_arg << std::endl); result = this->ExecuteScript(total_script_arg); - } - if (result) - { + } + if (result) { return result; - } + } // only run the curent script if we should - if (this->Makefile && this->Makefile->IsOn("CTEST_RUN_CURRENT_SCRIPT")) - { + if (this->Makefile && this->Makefile->IsOn("CTEST_RUN_CURRENT_SCRIPT")) { return this->RunCurrentScript(); - } + } return result; } @@ -612,52 +554,43 @@ int cmCTestScriptHandler::RunCurrentScript() // extract the vars from the cache and store in ivars result = this->ExtractVariables(); - if (result) - { + if (result) { return result; - } + } // set any environment variables - if (!this->CTestEnv.empty()) - { + if (!this->CTestEnv.empty()) { std::vector<std::string> envArgs; - cmSystemTools::ExpandListArgument(this->CTestEnv,envArgs); + cmSystemTools::ExpandListArgument(this->CTestEnv, envArgs); cmSystemTools::AppendEnv(envArgs); - } + } // now that we have done most of the error checking finally run the // dashboard, we may be asked to repeatedly run this dashboard, such as // for a continuous, do we ned to run it more than once? - if ( this->ContinuousDuration >= 0 ) - { + if (this->ContinuousDuration >= 0) { this->UpdateElapsedTime(); - double ending_time = cmSystemTools::GetTime() + this->ContinuousDuration; - if (this->EmptyBinDirOnce) - { + double ending_time = cmSystemTools::GetTime() + this->ContinuousDuration; + if (this->EmptyBinDirOnce) { this->EmptyBinDir = true; - } - do - { + } + do { double interval = cmSystemTools::GetTime(); result = this->RunConfigurationDashboard(); interval = cmSystemTools::GetTime() - interval; - if (interval < this->MinimumInterval) - { + if (interval < this->MinimumInterval) { this->SleepInSeconds( static_cast<unsigned int>(this->MinimumInterval - interval)); - } - if (this->EmptyBinDirOnce) - { + } + if (this->EmptyBinDirOnce) { this->EmptyBinDir = false; - } } - while (cmSystemTools::GetTime() < ending_time); - } + } while (cmSystemTools::GetTime() < ending_time); + } // otherwise just run it once - else - { + else { result = this->RunConfigurationDashboard(); - } + } return result; } @@ -670,23 +603,20 @@ int cmCTestScriptHandler::CheckOutSourceDir() bool res; if (!cmSystemTools::FileExists(this->SourceDir.c_str()) && - !this->CVSCheckOut.empty()) - { + !this->CVSCheckOut.empty()) { // we must now checkout the src dir output = ""; cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Run cvs: " << this->CVSCheckOut << std::endl); + "Run cvs: " << this->CVSCheckOut << std::endl); res = cmSystemTools::RunSingleCommand( - this->CVSCheckOut.c_str(), &output, &output, - &retVal, this->CTestRoot.c_str(), this->HandlerVerbose, - 0 /*this->TimeOut*/); - if (!res || retVal != 0) - { + this->CVSCheckOut.c_str(), &output, &output, &retVal, + this->CTestRoot.c_str(), this->HandlerVerbose, 0 /*this->TimeOut*/); + if (!res || retVal != 0) { cmSystemTools::Error("Unable to perform cvs checkout:\n", output.c_str()); return 6; - } } + } return 0; } @@ -701,17 +631,14 @@ int cmCTestScriptHandler::BackupDirectories() this->BackupBinaryDir += "_CMakeBackup"; // backup the binary and src directories if requested - if (this->Backup) - { + if (this->Backup) { // if for some reason those directories exist then first delete them - if (cmSystemTools::FileExists(this->BackupSourceDir.c_str())) - { + if (cmSystemTools::FileExists(this->BackupSourceDir.c_str())) { cmSystemTools::RemoveADirectory(this->BackupSourceDir); - } - if (cmSystemTools::FileExists(this->BackupBinaryDir.c_str())) - { + } + if (cmSystemTools::FileExists(this->BackupBinaryDir.c_str())) { cmSystemTools::RemoveADirectory(this->BackupBinaryDir); - } + } // first rename the src and binary directories rename(this->SourceDir.c_str(), this->BackupSourceDir.c_str()); @@ -719,17 +646,15 @@ int cmCTestScriptHandler::BackupDirectories() // we must now checkout the src dir retVal = this->CheckOutSourceDir(); - if (retVal) - { + if (retVal) { this->RestoreBackupDirectories(); return retVal; - } } + } return 0; } - int cmCTestScriptHandler::PerformExtraUpdates() { std::string command; @@ -740,38 +665,30 @@ int cmCTestScriptHandler::PerformExtraUpdates() // do an initial cvs update as required command = this->UpdateCmd; std::vector<std::string>::iterator it; - for (it = this->ExtraUpdates.begin(); - it != this->ExtraUpdates.end(); - ++ it ) - { + for (it = this->ExtraUpdates.begin(); it != this->ExtraUpdates.end(); ++it) { std::vector<std::string> cvsArgs; - cmSystemTools::ExpandListArgument(*it,cvsArgs); - if (cvsArgs.size() == 2) - { + cmSystemTools::ExpandListArgument(*it, cvsArgs); + if (cvsArgs.size() == 2) { std::string fullCommand = command; fullCommand += " update "; fullCommand += cvsArgs[1]; output = ""; retVal = 0; - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run Update: " - << fullCommand << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "Run Update: " << fullCommand << std::endl); res = cmSystemTools::RunSingleCommand( - fullCommand.c_str(), &output, &output, - &retVal, cvsArgs[0].c_str(), + fullCommand.c_str(), &output, &output, &retVal, cvsArgs[0].c_str(), this->HandlerVerbose, 0 /*this->TimeOut*/); - if (!res || retVal != 0) - { - cmSystemTools::Error("Unable to perform extra updates:\n", - it->c_str(), "\nWith output:\n", - output.c_str()); + if (!res || retVal != 0) { + cmSystemTools::Error("Unable to perform extra updates:\n", it->c_str(), + "\nWith output:\n", output.c_str()); return 0; - } } } + } return 0; } - // run a single dashboard entry int cmCTestScriptHandler::RunConfigurationDashboard() { @@ -784,180 +701,153 @@ int cmCTestScriptHandler::RunConfigurationDashboard() // make sure the src directory is there, if it isn't then we might be able // to check it out from cvs retVal = this->CheckOutSourceDir(); - if (retVal) - { + if (retVal) { return retVal; - } + } // backup the dirs if requested retVal = this->BackupDirectories(); - if (retVal) - { + if (retVal) { return retVal; - } + } // clear the binary directory? - if (this->EmptyBinDir) - { - if ( !cmCTestScriptHandler::EmptyBinaryDirectory( - this->BinaryDir.c_str()) ) - { + if (this->EmptyBinDir) { + if (!cmCTestScriptHandler::EmptyBinaryDirectory(this->BinaryDir.c_str())) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem removing the binary directory" << std::endl); - } + "Problem removing the binary directory" << std::endl); } + } // make sure the binary directory exists if it isn't the srcdir if (!cmSystemTools::FileExists(this->BinaryDir.c_str()) && - this->SourceDir != this->BinaryDir) - { - if (!cmSystemTools::MakeDirectory(this->BinaryDir.c_str())) - { + this->SourceDir != this->BinaryDir) { + if (!cmSystemTools::MakeDirectory(this->BinaryDir.c_str())) { cmSystemTools::Error("Unable to create the binary directory:\n", this->BinaryDir.c_str()); this->RestoreBackupDirectories(); return 7; - } } + } // if the binary directory and the source directory are the same, // and we are starting with an empty binary directory, then that means // we must check out the source tree - if (this->EmptyBinDir && this->SourceDir == this->BinaryDir) - { + if (this->EmptyBinDir && this->SourceDir == this->BinaryDir) { // make sure we have the required info - if (this->CVSCheckOut.empty()) - { - cmSystemTools::Error("You have specified the source and binary " + if (this->CVSCheckOut.empty()) { + cmSystemTools::Error( + "You have specified the source and binary " "directories to be the same (an in source build). You have also " "specified that the binary directory is to be erased. This means " "that the source will have to be checked out from CVS. But you have " "not specified CTEST_CVS_CHECKOUT"); return 8; - } + } // we must now checkout the src dir retVal = this->CheckOutSourceDir(); - if (retVal) - { + if (retVal) { this->RestoreBackupDirectories(); return retVal; - } } + } // backup the dirs if requested retVal = this->PerformExtraUpdates(); - if (retVal) - { + if (retVal) { return retVal; - } + } // put the initial cache into the bin dir - if (!this->InitialCache.empty()) - { + if (!this->InitialCache.empty()) { if (!this->WriteInitialCache(this->BinaryDir.c_str(), - this->InitialCache.c_str())) - { + this->InitialCache.c_str())) { this->RestoreBackupDirectories(); return 9; - } } + } // do an initial cmake to setup the DartConfig file int cmakeFailed = 0; std::string cmakeFailedOuput; - if (!this->CMakeCmd.empty()) - { + if (!this->CMakeCmd.empty()) { command = this->CMakeCmd; command += " \""; command += this->SourceDir; output = ""; command += "\""; retVal = 0; - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run cmake command: " - << command << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "Run cmake command: " << command << std::endl); res = cmSystemTools::RunSingleCommand( - command.c_str(), &output, &output, - &retVal, this->BinaryDir.c_str(), + command.c_str(), &output, &output, &retVal, this->BinaryDir.c_str(), this->HandlerVerbose, 0 /*this->TimeOut*/); - if ( !this->CMOutFile.empty() ) - { + if (!this->CMOutFile.empty()) { std::string cmakeOutputFile = this->CMOutFile; - if ( !cmSystemTools::FileIsFullPath(cmakeOutputFile.c_str()) ) - { + if (!cmSystemTools::FileIsFullPath(cmakeOutputFile.c_str())) { cmakeOutputFile = this->BinaryDir + "/" + cmakeOutputFile; - } + } cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Write CMake output to file: " << cmakeOutputFile - << std::endl); + "Write CMake output to file: " << cmakeOutputFile + << std::endl); cmGeneratedFileStream fout(cmakeOutputFile.c_str()); - if ( fout ) - { + if (fout) { fout << output.c_str(); - } - else - { + } else { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open CMake output file: " - << cmakeOutputFile << " for writing" << std::endl); - } + "Cannot open CMake output file: " + << cmakeOutputFile << " for writing" << std::endl); } - if (!res || retVal != 0) - { + } + if (!res || retVal != 0) { // even if this fails continue to the next step cmakeFailed = 1; cmakeFailedOuput = output; - } } + } // run ctest, it may be more than one command in here std::vector<std::string> ctestCommands; - cmSystemTools::ExpandListArgument(this->CTestCmd,ctestCommands); + cmSystemTools::ExpandListArgument(this->CTestCmd, ctestCommands); // for each variable/argument do a putenv - for (unsigned i = 0; i < ctestCommands.size(); ++i) - { + for (unsigned i = 0; i < ctestCommands.size(); ++i) { command = ctestCommands[i]; output = ""; retVal = 0; - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run ctest command: " - << command << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "Run ctest command: " << command << std::endl); res = cmSystemTools::RunSingleCommand( - command.c_str(), &output, &output, - &retVal, this->BinaryDir.c_str(), this->HandlerVerbose, - 0 /*this->TimeOut*/); + command.c_str(), &output, &output, &retVal, this->BinaryDir.c_str(), + this->HandlerVerbose, 0 /*this->TimeOut*/); // did something critical fail in ctest - if (!res || cmakeFailed || - retVal & cmCTest::BUILD_ERRORS) - { + if (!res || cmakeFailed || retVal & cmCTest::BUILD_ERRORS) { this->RestoreBackupDirectories(); - if (cmakeFailed) - { + if (cmakeFailed) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unable to run cmake:" << std::endl - << cmakeFailedOuput << std::endl); + "Unable to run cmake:" << std::endl + << cmakeFailedOuput << std::endl); return 10; - } + } cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unable to run ctest:" << std::endl - << "command: " << command << std::endl - << "output: " << output << std::endl); - if (!res) - { + "Unable to run ctest:" << std::endl + << "command: " << command << std::endl + << "output: " << output << std::endl); + if (!res) { return 11; - } - return retVal * 100; } + return retVal * 100; } + } // if all was succesful, delete the backup dirs to free up disk space - if (this->Backup) - { + if (this->Backup) { cmSystemTools::RemoveADirectory(this->BackupSourceDir); cmSystemTools::RemoveADirectory(this->BackupBinaryDir); - } + } return 0; } @@ -968,15 +858,13 @@ bool cmCTestScriptHandler::WriteInitialCache(const char* directory, std::string cacheFile = directory; cacheFile += "/CMakeCache.txt"; cmGeneratedFileStream fout(cacheFile.c_str()); - if(!fout) - { + if (!fout) { return false; - } + } - if (text!=0) - { + if (text != 0) { fout.write(text, strlen(text)); - } + } // Make sure the operating system has finished writing the file // before closing it. This will ensure the file is finished before @@ -990,69 +878,60 @@ void cmCTestScriptHandler::RestoreBackupDirectories() { // if we backed up the dirs and the build failed, then restore // the backed up dirs - if (this->Backup) - { + if (this->Backup) { // if for some reason those directories exist then first delete them - if (cmSystemTools::FileExists(this->SourceDir.c_str())) - { + if (cmSystemTools::FileExists(this->SourceDir.c_str())) { cmSystemTools::RemoveADirectory(this->SourceDir); - } - if (cmSystemTools::FileExists(this->BinaryDir.c_str())) - { + } + if (cmSystemTools::FileExists(this->BinaryDir.c_str())) { cmSystemTools::RemoveADirectory(this->BinaryDir); - } + } // rename the src and binary directories rename(this->BackupSourceDir.c_str(), this->SourceDir.c_str()); rename(this->BackupBinaryDir.c_str(), this->BinaryDir.c_str()); - } + } } -bool cmCTestScriptHandler::RunScript(cmCTest* ctest, const char *sname, +bool cmCTestScriptHandler::RunScript(cmCTest* ctest, const char* sname, bool InProcess, int* returnValue) { cmCTestScriptHandler* sh = new cmCTestScriptHandler(); sh->SetCTestInstance(ctest); - sh->AddConfigurationScript(sname,InProcess); + sh->AddConfigurationScript(sname, InProcess); int res = sh->ProcessHandler(); - if(returnValue) - { + if (returnValue) { *returnValue = res; - } + } delete sh; return true; } -bool cmCTestScriptHandler::EmptyBinaryDirectory(const char *sname) +bool cmCTestScriptHandler::EmptyBinaryDirectory(const char* sname) { // try to avoid deleting root - if (!sname || strlen(sname) < 2) - { + if (!sname || strlen(sname) < 2) { return false; - } + } // consider non existing target directory a success - if(!cmSystemTools::FileExists(sname)) - { + if (!cmSystemTools::FileExists(sname)) { return true; - } + } // try to avoid deleting directories that we shouldn't std::string check = sname; check += "/CMakeCache.txt"; - if(!cmSystemTools::FileExists(check.c_str())) - { + if (!cmSystemTools::FileExists(check.c_str())) { return false; - } + } - for(int i = 0; i < 5; ++i) - { - if(TryToRemoveBinaryDirectoryOnce(sname)) - { + for (int i = 0; i < 5; ++i) { + if (TryToRemoveBinaryDirectoryOnce(sname)) { return true; - } - cmSystemTools::Delay(100); } + cmSystemTools::Delay(100); + } return false; } @@ -1063,34 +942,27 @@ bool cmCTestScriptHandler::TryToRemoveBinaryDirectoryOnce( cmsys::Directory directory; directory.Load(directoryPath); - for(unsigned long i = 0; i < directory.GetNumberOfFiles(); ++i) - { + for (unsigned long i = 0; i < directory.GetNumberOfFiles(); ++i) { std::string path = directory.GetFile(i); - if(path == "." || path == ".." || path == "CMakeCache.txt") - { + if (path == "." || path == ".." || path == "CMakeCache.txt") { continue; - } + } std::string fullPath = directoryPath + std::string("/") + path; bool isDirectory = cmSystemTools::FileIsDirectory(fullPath) && !cmSystemTools::FileIsSymlink(fullPath); - if(isDirectory) - { - if(!cmSystemTools::RemoveADirectory(fullPath)) - { + if (isDirectory) { + if (!cmSystemTools::RemoveADirectory(fullPath)) { return false; - } } - else - { - if(!cmSystemTools::RemoveFile(fullPath)) - { + } else { + if (!cmSystemTools::RemoveFile(fullPath)) { return false; - } } + } } return cmSystemTools::RemoveADirectory(directoryPath); @@ -1098,18 +970,15 @@ bool cmCTestScriptHandler::TryToRemoveBinaryDirectoryOnce( double cmCTestScriptHandler::GetRemainingTimeAllowed() { - if (!this->Makefile) - { + if (!this->Makefile) { return 1.0e7; - } + } - const char *timelimitS - = this->Makefile->GetDefinition("CTEST_TIME_LIMIT"); + const char* timelimitS = this->Makefile->GetDefinition("CTEST_TIME_LIMIT"); - if (!timelimitS) - { + if (!timelimitS) { return 1.0e7; - } + } double timelimit = atof(timelimitS); |