diff options
Diffstat (limited to 'Source/CTest')
-rw-r--r-- | Source/CTest/cmCTestRunScriptCommand.cxx | 12 | ||||
-rw-r--r-- | Source/CTest/cmCTestRunScriptCommand.h | 5 | ||||
-rw-r--r-- | Source/CTest/cmCTestScriptHandler.cxx | 101 | ||||
-rw-r--r-- | Source/CTest/cmCTestScriptHandler.h | 11 |
4 files changed, 107 insertions, 22 deletions
diff --git a/Source/CTest/cmCTestRunScriptCommand.cxx b/Source/CTest/cmCTestRunScriptCommand.cxx index 5df84bb..abb2e48 100644 --- a/Source/CTest/cmCTestRunScriptCommand.cxx +++ b/Source/CTest/cmCTestRunScriptCommand.cxx @@ -27,11 +27,17 @@ bool cmCTestRunScriptCommand::InitialPass( return true; } + bool np = false; + unsigned int i = 0; + if (args[i] == "NEW_PROCESS") + { + np = true; + i++; + } // run each script - unsigned int i; - for (i = 0; i < args.size(); ++i) + for (; i < args.size(); ++i) { - cmCTestScriptHandler::RunScript(this->CTest, args[i].c_str()); + cmCTestScriptHandler::RunScript(this->CTest, args[i].c_str(), !np); } return true; } diff --git a/Source/CTest/cmCTestRunScriptCommand.h b/Source/CTest/cmCTestRunScriptCommand.h index 1ca022e..949cb77 100644 --- a/Source/CTest/cmCTestRunScriptCommand.h +++ b/Source/CTest/cmCTestRunScriptCommand.h @@ -67,11 +67,12 @@ public: virtual const char* GetFullDocumentation() { return - " CTEST_RUN_SCRIPT(script_file_name script_file_name1 \n" + " CTEST_RUN_SCRIPT([NEW_PROCESS] script_file_name script_file_name1 \n" " script_file_name2 ...)\n" "Runs a script or scripts much like if it was run from ctest -S. " "If no argument is provided then the current script is run using " - "the current settings of the variables."; + "the current settings of the variables. If NEW_PROCESS is specified " + "then each script will be run in a seperate process."; } cmTypeMacro(cmCTestRunScriptCommand, cmCTestCommand); diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 887d8ad..9350334 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -167,9 +167,10 @@ cmCTestScriptHandler::~cmCTestScriptHandler() //---------------------------------------------------------------------- // 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); } @@ -179,14 +180,12 @@ void cmCTestScriptHandler::AddConfigurationScript(const char *script) int cmCTestScriptHandler::ProcessHandler() { int res = 0; - std::vector<cmStdString>::iterator it; - for ( it = this->ConfigurationScripts.begin(); - it != this->ConfigurationScripts.end(); - it ++ ) + for (size_t i=0; i < this->ConfigurationScripts.size(); ++i) { // for each script run it - res += this->RunConfigurationScript( - cmSystemTools::CollapseFullPath(it->c_str())); + res += this->RunConfigurationScript + (cmSystemTools::CollapseFullPath(this->ConfigurationScripts[i].c_str()), + this->ScriptProcessScope[i]); } if ( res ) { @@ -218,8 +217,73 @@ void cmCTestScriptHandler::AddCTestCommand(cmCTestCommand* command) this->CMake->AddCommand(newCom); } +int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg) +{ + // execute the script passing in the arguments to the script as well as the + // arguments from this invocation of cmake + std::vector<const char*> argv; + argv.push_back(this->CTest->GetCTestExecutable()); + argv.push_back("-SR"); + argv.push_back(total_script_arg.c_str()); + + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "Executable for CTest is: " << + this->CTest->GetCTestExecutable() << "\n"); + + // now pass through all the other arguments + std::vector<cmStdString> &initArgs = + this->CTest->GetInitialCommandLineArguments(); + 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_SetOption(cp, cmsysProcess_Option_HideWindow, 1); + //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) + { + cmCTestLog(this->CTest, ERROR_MESSAGE, line << "\n"); + } + else if(pipe == cmsysProcess_Pipe_STDOUT) + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, line << "\n"); + } + 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; + if(result == cmsysProcess_State_Exited) + { + retVal = cmsysProcess_GetExitValue(cp); + } + else + { + abort(); + } + return retVal; +} + + //---------------------------------------------------------------------- -// this sets up some variables for thew script to use, creates the required +// this sets up some variables for the script to use, creates the required // cmake instance and generators, and then reads in the script int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) { @@ -426,8 +490,8 @@ void cmCTestScriptHandler::SleepInSeconds(unsigned int secondsToWait) //---------------------------------------------------------------------- // run a specific script -int cmCTestScriptHandler::RunConfigurationScript( - const std::string& total_script_arg) +int cmCTestScriptHandler::RunConfigurationScript +(const std::string& total_script_arg, bool pscope) { int result; @@ -435,7 +499,18 @@ int cmCTestScriptHandler::RunConfigurationScript( cmSystemTools::GetTime(); // read in the script - result = this->ReadInScript(total_script_arg); + if (pscope) + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "Reading Script: " << total_script_arg << std::endl); + result = this->ReadInScript(total_script_arg); + } + else + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "Executing Script: " << total_script_arg << std::endl); + result = this->ExecuteScript(total_script_arg); + } if (result) { return result; @@ -847,11 +922,11 @@ void cmCTestScriptHandler::RestoreBackupDirectories() } } -bool cmCTestScriptHandler::RunScript(cmCTest* ctest, const char *sname) +bool cmCTestScriptHandler::RunScript(cmCTest* ctest, const char *sname, bool InProcess) { cmCTestScriptHandler* sh = new cmCTestScriptHandler(); sh->SetCTestInstance(ctest); - sh->AddConfigurationScript(sname); + sh->AddConfigurationScript(sname,InProcess); sh->ProcessHandler(); delete sh; return true; diff --git a/Source/CTest/cmCTestScriptHandler.h b/Source/CTest/cmCTestScriptHandler.h index 344192b..e354005 100644 --- a/Source/CTest/cmCTestScriptHandler.h +++ b/Source/CTest/cmCTestScriptHandler.h @@ -69,9 +69,9 @@ public: cmTypeMacro(cmCTestScriptHandler, cmCTestGenericHandler); /** - * Add a script to run + * Add a script to run, and if is should run in the current process */ - void AddConfigurationScript(const char *); + void AddConfigurationScript(const char *, bool pscope); /** * Run a dashboard using a specified confiuration script @@ -81,7 +81,7 @@ public: /* * Run a script */ - static bool RunScript(cmCTest* ctest, const char *script); + static bool RunScript(cmCTest* ctest, const char *script, bool InProcess); int RunCurrentScript(); /* @@ -99,9 +99,11 @@ public: ~cmCTestScriptHandler(); void Initialize(); + private: // reads in a script int ReadInScript(const std::string& total_script_arg); + int ExecuteScript(const std::string& total_script_arg); // extract vars from the script to set ivars int ExtractVariables(); @@ -116,13 +118,14 @@ private: int BackupDirectories(); void RestoreBackupDirectories(); - int RunConfigurationScript(const std::string& script); + int RunConfigurationScript(const std::string& script, bool pscope); int RunConfigurationDashboard(); // Add ctest command void AddCTestCommand(cmCTestCommand* command); std::vector<cmStdString> ConfigurationScripts; + std::vector<bool> ScriptProcessScope; bool Backup; bool EmptyBinDir; |