2004-09-06 20:45:14 +04:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
|
|
|
|
2006-03-09 19:17:10 +03:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
2004-09-06 20:45:14 +04:00
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
|
|
|
|
#include "cmCTestScriptHandler.h"
|
|
|
|
|
|
|
|
#include "cmCTest.h"
|
|
|
|
#include "cmake.h"
|
2005-01-27 18:11:04 +03:00
|
|
|
#include "cmFunctionBlocker.h"
|
2004-09-06 20:45:14 +04:00
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
2005-05-28 00:17:38 +04:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2004-09-06 20:45:14 +04:00
|
|
|
|
|
|
|
//#include <cmsys/RegularExpression.hxx>
|
|
|
|
#include <cmsys/Process.h>
|
|
|
|
|
|
|
|
// used for sleep
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "windows.h"
|
|
|
|
#endif
|
|
|
|
|
2006-03-09 19:17:10 +03:00
|
|
|
#include <stdlib.h>
|
2004-09-06 20:45:14 +04:00
|
|
|
#include <time.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
|
|
|
|
|
|
|
// needed for sleep
|
|
|
|
#if !defined(_WIN32)
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2005-05-02 22:15:29 +04:00
|
|
|
#include "cmCTestBuildCommand.h"
|
|
|
|
#include "cmCTestConfigureCommand.h"
|
2005-06-14 22:00:45 +04:00
|
|
|
#include "cmCTestCoverageCommand.h"
|
2005-01-27 18:11:04 +03:00
|
|
|
#include "cmCTestEmptyBinaryDirectoryCommand.h"
|
2005-06-14 22:00:45 +04:00
|
|
|
#include "cmCTestMemCheckCommand.h"
|
2006-03-28 23:37:44 +04:00
|
|
|
#include "cmCTestReadCustomFilesCommand.h"
|
2005-01-27 18:11:04 +03:00
|
|
|
#include "cmCTestRunScriptCommand.h"
|
|
|
|
#include "cmCTestSleepCommand.h"
|
2005-02-17 18:51:52 +03:00
|
|
|
#include "cmCTestStartCommand.h"
|
2005-05-03 16:17:39 +04:00
|
|
|
#include "cmCTestSubmitCommand.h"
|
2005-06-14 22:00:45 +04:00
|
|
|
#include "cmCTestTestCommand.h"
|
|
|
|
#include "cmCTestUpdateCommand.h"
|
2005-01-27 18:11:04 +03:00
|
|
|
|
2004-09-28 17:00:06 +04:00
|
|
|
#define CTEST_INITIAL_CMAKE_OUTPUT_FILE_NAME "CTestInitialCMakeOutput.log"
|
|
|
|
|
2005-01-27 18:11:04 +03:00
|
|
|
// used to keep elapsed time up to date
|
|
|
|
class cmCTestScriptFunctionBlocker : public cmFunctionBlocker
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmCTestScriptFunctionBlocker() {}
|
|
|
|
virtual ~cmCTestScriptFunctionBlocker() {}
|
|
|
|
virtual bool IsFunctionBlocked(const cmListFileFunction& lff,
|
|
|
|
cmMakefile &mf);
|
|
|
|
//virtual bool ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf);
|
|
|
|
//virtual void ScopeEnded(cmMakefile &mf);
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestScriptHandler* CTestScriptHandler;
|
2005-01-27 18:11:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// simply update the time and don't block anything
|
|
|
|
bool cmCTestScriptFunctionBlocker::
|
2006-03-09 19:17:10 +03:00
|
|
|
IsFunctionBlocked(const cmListFileFunction& , cmMakefile &)
|
2005-01-27 18:11:04 +03:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->CTestScriptHandler->UpdateElapsedTime();
|
2005-01-27 18:11:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
cmCTestScriptHandler::cmCTestScriptHandler()
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Backup = false;
|
|
|
|
this->EmptyBinDir = false;
|
|
|
|
this->EmptyBinDirOnce = false;
|
|
|
|
this->Makefile = 0;
|
|
|
|
this->LocalGenerator = 0;
|
|
|
|
this->CMake = 0;
|
|
|
|
this->GlobalGenerator = 0;
|
2005-01-27 18:11:04 +03:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
this->ScriptStartTime = 0;
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// the *60 is becuase the settings are in minutes but GetTime is seconds
|
2006-03-10 23:03:09 +03:00
|
|
|
this->MinimumInterval = 30*60;
|
|
|
|
this->ContinuousDuration = -1;
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
|
|
|
|
2005-06-17 21:04:56 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void cmCTestScriptHandler::Initialize()
|
|
|
|
{
|
2005-06-23 21:04:18 +04:00
|
|
|
this->Superclass::Initialize();
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Backup = false;
|
|
|
|
this->EmptyBinDir = false;
|
|
|
|
this->EmptyBinDirOnce = false;
|
|
|
|
|
|
|
|
this->SourceDir = "";
|
|
|
|
this->BinaryDir = "";
|
|
|
|
this->BackupSourceDir = "";
|
|
|
|
this->BackupBinaryDir = "";
|
|
|
|
this->CTestRoot = "";
|
|
|
|
this->CVSCheckOut = "";
|
|
|
|
this->CTestCmd = "";
|
|
|
|
this->CVSCmd = "";
|
|
|
|
this->CTestEnv = "";
|
|
|
|
this->InitCache = "";
|
|
|
|
this->CMakeCmd = "";
|
|
|
|
this->CMOutFile = "";
|
|
|
|
this->ExtraUpdates.clear();
|
|
|
|
|
|
|
|
this->MinimumInterval = 20*60;
|
|
|
|
this->ContinuousDuration = -1;
|
2005-06-17 21:04:56 +04:00
|
|
|
|
|
|
|
// what time in seconds did this script start running
|
2006-03-10 23:03:09 +03:00
|
|
|
this->ScriptStartTime = 0;
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Makefile = 0;
|
|
|
|
if (this->LocalGenerator)
|
2005-06-17 21:04:56 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
delete this->LocalGenerator;
|
2005-06-17 21:04:56 +04:00
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
this->LocalGenerator = 0;
|
|
|
|
if (this->GlobalGenerator)
|
2005-06-17 21:04:56 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
delete this->GlobalGenerator;
|
2005-06-17 21:04:56 +04:00
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
this->GlobalGenerator = 0;
|
|
|
|
if (this->CMake)
|
2005-06-17 21:04:56 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
delete this->CMake;
|
2005-06-17 21:04:56 +04:00
|
|
|
}
|
|
|
|
}
|
2004-09-06 20:45:14 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
cmCTestScriptHandler::~cmCTestScriptHandler()
|
|
|
|
{
|
2004-09-07 17:17:15 +04:00
|
|
|
// local generator owns the makefile
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Makefile = 0;
|
|
|
|
if (this->LocalGenerator)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
delete this->LocalGenerator;
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
this->LocalGenerator = 0;
|
|
|
|
if (this->GlobalGenerator)
|
2004-09-07 17:17:15 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
delete this->GlobalGenerator;
|
2004-09-07 17:17:15 +04:00
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
this->GlobalGenerator = 0;
|
|
|
|
if (this->CMake)
|
2004-09-07 17:17:15 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
delete this->CMake;
|
2004-09-07 17:17:15 +04:00
|
|
|
}
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// just adds an argument to the vector
|
|
|
|
void cmCTestScriptHandler::AddConfigurationScript(const char *script)
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->ConfigurationScripts.push_back(script);
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// the generic entry point for handling scripts, this routine will run all
|
|
|
|
// the scripts provides a -S arguments
|
2005-01-27 23:54:47 +03:00
|
|
|
int cmCTestScriptHandler::ProcessHandler()
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
std::vector<cmStdString>::iterator it;
|
2006-03-10 23:03:09 +03:00
|
|
|
for ( it = this->ConfigurationScripts.begin();
|
|
|
|
it != this->ConfigurationScripts.end();
|
2004-09-06 20:45:14 +04:00
|
|
|
it ++ )
|
|
|
|
{
|
|
|
|
// for each script run it
|
2005-01-27 19:43:22 +03:00
|
|
|
res += this->RunConfigurationScript(
|
2004-09-06 20:45:14 +04:00
|
|
|
cmSystemTools::CollapseFullPath(it->c_str()));
|
|
|
|
}
|
2005-01-27 23:54:47 +03:00
|
|
|
if ( res )
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
|
|
|
|
2005-01-27 18:11:04 +03:00
|
|
|
void cmCTestScriptHandler::UpdateElapsedTime()
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
if (this->LocalGenerator)
|
2005-01-27 18:11:04 +03:00
|
|
|
{
|
|
|
|
// set the current elapsed time
|
|
|
|
char timeString[20];
|
|
|
|
int itime = static_cast<unsigned int>(cmSystemTools::GetTime()
|
2006-03-10 23:03:09 +03:00
|
|
|
- this->ScriptStartTime);
|
2005-01-27 18:11:04 +03:00
|
|
|
sprintf(timeString,"%i",itime);
|
2006-03-10 23:03:09 +03:00
|
|
|
this->LocalGenerator->GetMakefile()->AddDefinition("CTEST_ELAPSED_TIME",
|
2005-01-27 18:11:04 +03:00
|
|
|
timeString);
|
|
|
|
}
|
|
|
|
}
|
2004-09-06 20:45:14 +04:00
|
|
|
|
2005-02-17 18:51:52 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void cmCTestScriptHandler::AddCTestCommand(cmCTestCommand* command)
|
|
|
|
{
|
|
|
|
cmCTestCommand* newCom = command;
|
2006-03-10 23:03:09 +03:00
|
|
|
newCom->CTest = this->CTest;
|
|
|
|
newCom->CTestScriptHandler = this;
|
|
|
|
this->CMake->AddCommand(newCom);
|
2005-02-17 18:51:52 +03:00
|
|
|
}
|
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// this sets up some variables for thew script to use, creates the required
|
|
|
|
// cmake instance and generators, and then reads in the script
|
2005-01-27 19:43:22 +03:00
|
|
|
int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
|
|
|
// if the argument has a , in it then it needs to be broken into the fist
|
|
|
|
// argument (which is the script) and the second argument which will be
|
|
|
|
// 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);
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// make sure the file exists
|
|
|
|
if (!cmSystemTools::FileExists(script.c_str()))
|
|
|
|
{
|
2004-09-28 17:00:06 +04:00
|
|
|
cmSystemTools::Error("Cannot find file: ", script.c_str());
|
2004-09-06 20:45:14 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a cmake instance to read the configuration script
|
|
|
|
// read in the list file to fill the cache
|
2006-03-10 23:03:09 +03:00
|
|
|
if (this->CMake)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
delete this->CMake;
|
|
|
|
delete this->GlobalGenerator;
|
|
|
|
delete this->LocalGenerator;
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
this->CMake = new cmake;
|
|
|
|
this->CMake->AddCMakePaths(this->CTest->GetCTestExecutable());
|
|
|
|
this->GlobalGenerator = new cmGlobalGenerator;
|
|
|
|
this->GlobalGenerator->SetCMakeInstance(this->CMake);
|
2004-09-06 20:45:14 +04:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
this->LocalGenerator = this->GlobalGenerator->CreateLocalGenerator();
|
|
|
|
this->LocalGenerator->SetGlobalGenerator(this->GlobalGenerator);
|
|
|
|
this->Makefile = this->LocalGenerator->GetMakefile();
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// set a variable with the path to the current script
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Makefile->AddDefinition("CTEST_SCRIPT_DIRECTORY",
|
2005-01-27 21:31:31 +03:00
|
|
|
cmSystemTools::GetFilenamePath(script).c_str());
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Makefile->AddDefinition("CTEST_SCRIPT_NAME",
|
2005-01-27 21:31:31 +03:00
|
|
|
cmSystemTools::GetFilenameName(script).c_str());
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Makefile->AddDefinition("CTEST_EXECUTABLE_NAME",
|
|
|
|
this->CTest->GetCTestExecutable());
|
|
|
|
this->Makefile->AddDefinition("CMAKE_EXECUTABLE_NAME",
|
|
|
|
this->CTest->GetCMakeExecutable());
|
|
|
|
this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", true);
|
2005-01-27 18:11:04 +03:00
|
|
|
this->UpdateElapsedTime();
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-01-27 18:11:04 +03:00
|
|
|
// add any ctest specific commands, probably should have common superclass
|
|
|
|
// for ctest commands to clean this up. If a couple more commands are
|
|
|
|
// created with the same format lets do that - ken
|
2005-05-02 22:15:29 +04:00
|
|
|
this->AddCTestCommand(new cmCTestBuildCommand);
|
|
|
|
this->AddCTestCommand(new cmCTestConfigureCommand);
|
2005-06-14 22:00:45 +04:00
|
|
|
this->AddCTestCommand(new cmCTestCoverageCommand);
|
2005-02-17 18:51:52 +03:00
|
|
|
this->AddCTestCommand(new cmCTestEmptyBinaryDirectoryCommand);
|
2005-06-14 22:00:45 +04:00
|
|
|
this->AddCTestCommand(new cmCTestMemCheckCommand);
|
2006-03-28 23:37:44 +04:00
|
|
|
this->AddCTestCommand(new cmCTestReadCustomFilesCommand);
|
2005-05-02 22:15:29 +04:00
|
|
|
this->AddCTestCommand(new cmCTestRunScriptCommand);
|
2005-02-17 18:51:52 +03:00
|
|
|
this->AddCTestCommand(new cmCTestSleepCommand);
|
|
|
|
this->AddCTestCommand(new cmCTestStartCommand);
|
2005-05-03 16:17:39 +04:00
|
|
|
this->AddCTestCommand(new cmCTestSubmitCommand);
|
|
|
|
this->AddCTestCommand(new cmCTestTestCommand);
|
2005-02-17 23:23:00 +03:00
|
|
|
this->AddCTestCommand(new cmCTestUpdateCommand);
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// add the script arg if defined
|
|
|
|
if (script_arg.size())
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Makefile->AddDefinition("CTEST_SCRIPT_ARG", script_arg.c_str());
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
2005-01-27 18:11:04 +03:00
|
|
|
|
|
|
|
// always add a function blocker to update the elapsed time
|
|
|
|
cmCTestScriptFunctionBlocker *f = new cmCTestScriptFunctionBlocker();
|
2006-03-10 23:03:09 +03:00
|
|
|
f->CTestScriptHandler = this;
|
|
|
|
this->Makefile->AddFunctionBlocker(f);
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// finally read in the script
|
2006-03-10 23:03:09 +03:00
|
|
|
if (!this->Makefile->ReadListFile(0, script.c_str()))
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// extract variabels from the script to set ivars
|
|
|
|
int cmCTestScriptHandler::ExtractVariables()
|
|
|
|
{
|
2004-09-29 01:51:29 +04:00
|
|
|
// Temporary variables
|
|
|
|
const char* minInterval;
|
|
|
|
const char* contDuration;
|
2004-09-06 20:45:14 +04:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
this->SourceDir
|
|
|
|
= this->Makefile->GetSafeDefinition("CTEST_SOURCE_DIRECTORY");
|
|
|
|
this->BinaryDir
|
|
|
|
= this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY");
|
|
|
|
this->CTestCmd
|
|
|
|
= this->Makefile->GetSafeDefinition("CTEST_COMMAND");
|
|
|
|
this->CVSCheckOut
|
|
|
|
= this->Makefile->GetSafeDefinition("CTEST_CVS_CHECKOUT");
|
|
|
|
this->CTestRoot
|
|
|
|
= this->Makefile->GetSafeDefinition("CTEST_DASHBOARD_ROOT");
|
|
|
|
this->CVSCmd
|
|
|
|
= this->Makefile->GetSafeDefinition("CTEST_CVS_COMMAND");
|
|
|
|
this->CTestEnv
|
|
|
|
= this->Makefile->GetSafeDefinition("CTEST_ENVIRONMENT");
|
|
|
|
this->InitCache
|
|
|
|
= 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");
|
2004-09-29 01:51:29 +04:00
|
|
|
|
2006-03-09 19:17:10 +03:00
|
|
|
minInterval
|
2006-03-10 23:03:09 +03:00
|
|
|
= this->Makefile->GetDefinition("CTEST_CONTINUOUS_MINIMUM_INTERVAL");
|
|
|
|
contDuration
|
|
|
|
= this->Makefile->GetDefinition("CTEST_CONTINUOUS_DURATION");
|
2004-09-29 01:51:29 +04:00
|
|
|
|
|
|
|
char updateVar[40];
|
|
|
|
int i;
|
|
|
|
for (i = 1; i < 10; ++i)
|
|
|
|
{
|
|
|
|
sprintf(updateVar,"CTEST_EXTRA_UPDATES_%i",i);
|
2006-03-10 23:03:09 +03:00
|
|
|
const char *updateVal = this->Makefile->GetDefinition(updateVar);
|
2004-09-29 01:51:29 +04:00
|
|
|
if ( updateVal )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
if ( this->CVSCmd.empty() )
|
2004-09-29 01:51:29 +04:00
|
|
|
{
|
2006-03-09 19:17:10 +03:00
|
|
|
cmSystemTools::Error(updateVar,
|
|
|
|
" specified without specifying CTEST_CVS_COMMAND.");
|
2004-09-29 01:51:29 +04:00
|
|
|
return 12;
|
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
this->ExtraUpdates.push_back(updateVal);
|
2004-09-29 01:51:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// in order to backup and restore we also must have the cvs root
|
2006-03-10 23:03:09 +03:00
|
|
|
if (this->Backup && this->CVSCheckOut.empty())
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
|
|
|
cmSystemTools::Error(
|
2006-03-09 19:17:10 +03:00
|
|
|
"Backup was requested without specifying CTEST_CVS_CHECKOUT.");
|
2004-09-06 20:45:14 +04:00
|
|
|
return 3;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// make sure the required info is here
|
2006-03-10 23:03:09 +03:00
|
|
|
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 = ";
|
|
|
|
msg += (!this->BinaryDir.empty()) ? this->BinaryDir.c_str() : "(Null)";
|
|
|
|
msg += "\nCTEST_COMMAND = ";
|
|
|
|
msg += (!this->CTestCmd.empty()) ? this->CTestCmd.c_str() : "(Null)";
|
2004-09-06 20:45:14 +04:00
|
|
|
cmSystemTools::Error(
|
|
|
|
"Some required settings in the configuration file were missing:\n",
|
2006-03-10 23:03:09 +03:00
|
|
|
msg.c_str());
|
2004-09-06 20:45:14 +04:00
|
|
|
return 4;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// if the dashboard root isn't specified then we can compute it from the
|
2006-03-10 23:03:09 +03:00
|
|
|
// this->SourceDir
|
|
|
|
if (this->CTestRoot.empty() )
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->CTestRoot = cmSystemTools::GetFilenamePath(this->SourceDir).c_str();
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// the script may override the minimum continuous interval
|
2004-09-29 01:51:29 +04:00
|
|
|
if (minInterval)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->MinimumInterval = 60 * atof(minInterval);
|
2004-09-29 01:51:29 +04:00
|
|
|
}
|
|
|
|
if (contDuration)
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->ContinuousDuration = 60.0 * atof(contDuration);
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
|
|
|
|
2005-01-27 18:11:04 +03:00
|
|
|
this->UpdateElapsedTime();
|
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2005-01-27 18:11:04 +03:00
|
|
|
void cmCTestScriptHandler::SleepInSeconds(unsigned int secondsToWait)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
|
|
|
#if defined(_WIN32)
|
|
|
|
Sleep(1000*secondsToWait);
|
|
|
|
#else
|
|
|
|
sleep(secondsToWait);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// run a specific script
|
2006-03-09 19:17:10 +03:00
|
|
|
int cmCTestScriptHandler::RunConfigurationScript(
|
|
|
|
const std::string& total_script_arg)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
|
|
|
int result;
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
this->ScriptStartTime =
|
2005-01-27 18:11:04 +03:00
|
|
|
cmSystemTools::GetTime();
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// read in the script
|
2005-01-27 19:43:22 +03:00
|
|
|
result = this->ReadInScript(total_script_arg);
|
2004-09-06 20:45:14 +04:00
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-01-27 21:31:31 +03:00
|
|
|
// only run the curent script if we should
|
2006-03-10 23:03:09 +03:00
|
|
|
if (this->Makefile && this->Makefile->IsOn("CTEST_RUN_CURRENT_SCRIPT"))
|
2005-01-27 18:11:04 +03:00
|
|
|
{
|
2005-01-27 19:01:56 +03:00
|
|
|
return this->RunCurrentScript();
|
2005-01-27 18:11:04 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-05-02 22:15:29 +04:00
|
|
|
//----------------------------------------------------------------------
|
2005-01-27 19:01:56 +03:00
|
|
|
int cmCTestScriptHandler::RunCurrentScript()
|
2005-01-27 18:11:04 +03:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
2005-01-27 21:31:31 +03:00
|
|
|
// do not run twice
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", false);
|
2005-01-27 18:11:04 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// no popup widows
|
|
|
|
cmSystemTools::SetRunCommandHideConsole(true);
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// extract the vars from the cache and store in ivars
|
|
|
|
result = this->ExtractVariables();
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// set any environment variables
|
2006-03-10 23:03:09 +03:00
|
|
|
if (!this->CTestEnv.empty())
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
|
|
|
std::vector<std::string> envArgs;
|
2006-03-10 23:03:09 +03:00
|
|
|
cmSystemTools::ExpandListArgument(this->CTestEnv.c_str(),envArgs);
|
2004-09-06 20:45:14 +04:00
|
|
|
// for each variable/argument do a putenv
|
|
|
|
for (unsigned i = 0; i < envArgs.size(); ++i)
|
|
|
|
{
|
|
|
|
cmSystemTools::PutEnv(envArgs[i].c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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?
|
2006-03-10 23:03:09 +03:00
|
|
|
if ( this->ContinuousDuration >= 0 )
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2005-01-27 18:11:04 +03:00
|
|
|
this->UpdateElapsedTime();
|
2006-03-10 23:03:09 +03:00
|
|
|
double ending_time = cmSystemTools::GetTime() + this->ContinuousDuration;
|
|
|
|
if (this->EmptyBinDirOnce)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->EmptyBinDir = true;
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
|
|
|
do
|
|
|
|
{
|
|
|
|
double interval = cmSystemTools::GetTime();
|
|
|
|
result = this->RunConfigurationDashboard();
|
|
|
|
interval = cmSystemTools::GetTime() - interval;
|
2006-03-10 23:03:09 +03:00
|
|
|
if (interval < this->MinimumInterval)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2005-01-27 18:11:04 +03:00
|
|
|
this->SleepInSeconds(
|
2006-03-10 23:03:09 +03:00
|
|
|
static_cast<unsigned int>(this->MinimumInterval - interval));
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
if (this->EmptyBinDirOnce)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->EmptyBinDir = false;
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while (cmSystemTools::GetTime() < ending_time);
|
|
|
|
}
|
|
|
|
// otherwise just run it once
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = this->RunConfigurationDashboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int cmCTestScriptHandler::CheckOutSourceDir()
|
|
|
|
{
|
|
|
|
std::string command;
|
|
|
|
std::string output;
|
|
|
|
int retVal;
|
2006-03-09 19:17:10 +03:00
|
|
|
bool res;
|
2004-09-06 20:45:14 +04:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
if (!cmSystemTools::FileExists(this->SourceDir.c_str()) &&
|
|
|
|
!this->CVSCheckOut.empty())
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
|
|
|
// we must now checkout the src dir
|
|
|
|
output = "";
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
"Run cvs: " << this->CVSCheckOut << std::endl);
|
|
|
|
res = cmSystemTools::RunSingleCommand(this->CVSCheckOut.c_str(), &output,
|
|
|
|
&retVal, this->CTestRoot.c_str(), this->HandlerVerbose,
|
|
|
|
0 /*this->TimeOut*/);
|
2004-09-06 20:45:14 +04:00
|
|
|
if (!res || retVal != 0)
|
|
|
|
{
|
2006-03-09 19:17:10 +03:00
|
|
|
cmSystemTools::Error("Unable to perform cvs checkout:\n",
|
|
|
|
output.c_str());
|
2004-09-06 20:45:14 +04:00
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int cmCTestScriptHandler::BackupDirectories()
|
|
|
|
{
|
|
|
|
int retVal;
|
|
|
|
|
|
|
|
// compute the backup names
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BackupSourceDir = this->SourceDir;
|
|
|
|
this->BackupSourceDir += "_CMakeBackup";
|
|
|
|
this->BackupBinaryDir = this->BinaryDir;
|
|
|
|
this->BackupBinaryDir += "_CMakeBackup";
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// backup the binary and src directories if requested
|
2006-03-10 23:03:09 +03:00
|
|
|
if (this->Backup)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
|
|
|
// if for some reason those directories exist then first delete them
|
2006-03-10 23:03:09 +03:00
|
|
|
if (cmSystemTools::FileExists(this->BackupSourceDir.c_str()))
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmSystemTools::RemoveADirectory(this->BackupSourceDir.c_str());
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
if (cmSystemTools::FileExists(this->BackupBinaryDir.c_str()))
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmSystemTools::RemoveADirectory(this->BackupBinaryDir.c_str());
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
|
|
|
// first rename the src and binary directories
|
2006-03-10 23:03:09 +03:00
|
|
|
rename(this->SourceDir.c_str(), this->BackupSourceDir.c_str());
|
|
|
|
rename(this->BinaryDir.c_str(), this->BackupBinaryDir.c_str());
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// we must now checkout the src dir
|
|
|
|
retVal = this->CheckOutSourceDir();
|
|
|
|
if (retVal)
|
|
|
|
{
|
|
|
|
this->RestoreBackupDirectories();
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int cmCTestScriptHandler::PerformExtraUpdates()
|
|
|
|
{
|
|
|
|
std::string command;
|
|
|
|
std::string output;
|
|
|
|
int retVal;
|
2006-03-09 19:17:10 +03:00
|
|
|
bool res;
|
2004-09-06 20:45:14 +04:00
|
|
|
|
|
|
|
// do an initial cvs update as required
|
2006-03-10 23:03:09 +03:00
|
|
|
command = this->CVSCmd;
|
2004-09-29 01:51:29 +04:00
|
|
|
std::vector<cmStdString>::iterator it;
|
2006-03-10 23:03:09 +03:00
|
|
|
for (it = this->ExtraUpdates.begin();
|
|
|
|
it != this->ExtraUpdates.end();
|
|
|
|
++ it )
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2004-09-29 01:51:29 +04:00
|
|
|
std::vector<std::string> cvsArgs;
|
|
|
|
cmSystemTools::ExpandListArgument(it->c_str(),cvsArgs);
|
|
|
|
if (cvsArgs.size() == 2)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2004-09-29 01:51:29 +04:00
|
|
|
std::string fullCommand = command;
|
|
|
|
fullCommand += " update ";
|
|
|
|
fullCommand += cvsArgs[1];
|
|
|
|
output = "";
|
|
|
|
retVal = 0;
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run CVS: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< fullCommand.c_str() << std::endl);
|
|
|
|
res = cmSystemTools::RunSingleCommand(fullCommand.c_str(), &output,
|
2004-09-29 01:51:29 +04:00
|
|
|
&retVal, cvsArgs[0].c_str(),
|
2006-03-10 23:03:09 +03:00
|
|
|
this->HandlerVerbose, 0 /*this->TimeOut*/);
|
2004-09-29 01:51:29 +04:00
|
|
|
if (!res || retVal != 0)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-09 19:17:10 +03:00
|
|
|
cmSystemTools::Error("Unable to perform extra cvs updates:\n",
|
2004-09-29 01:51:29 +04:00
|
|
|
output.c_str());
|
2004-09-29 19:52:02 +04:00
|
|
|
return 0;
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// run a single dashboard entry
|
|
|
|
int cmCTestScriptHandler::RunConfigurationDashboard()
|
|
|
|
{
|
|
|
|
// local variables
|
|
|
|
std::string command;
|
|
|
|
std::string output;
|
|
|
|
int retVal;
|
2006-03-09 19:17:10 +03:00
|
|
|
bool res;
|
2004-09-06 20:45:14 +04:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
// backup the dirs if requested
|
|
|
|
retVal = this->BackupDirectories();
|
|
|
|
if (retVal)
|
|
|
|
{
|
|
|
|
return retVal;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// clear the binary directory?
|
2006-03-10 23:03:09 +03:00
|
|
|
if (this->EmptyBinDir)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
if ( !cmCTestScriptHandler::EmptyBinaryDirectory(
|
|
|
|
this->BinaryDir.c_str()) )
|
2005-02-17 00:06:11 +03:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2006-03-09 19:17:10 +03:00
|
|
|
"Problem removing the binary directory" << std::endl);
|
2005-02-17 00:06:11 +03:00
|
|
|
}
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// make sure the binary directory exists if it isn't the srcdir
|
2006-03-10 23:03:09 +03:00
|
|
|
if (!cmSystemTools::FileExists(this->BinaryDir.c_str()) &&
|
|
|
|
this->SourceDir != this->BinaryDir)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
if (!cmSystemTools::MakeDirectory(this->BinaryDir.c_str()))
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-09 19:17:10 +03:00
|
|
|
cmSystemTools::Error("Unable to create the binary directory:\n",
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BinaryDir.c_str());
|
2004-09-06 20:45:14 +04:00
|
|
|
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
|
2006-03-10 23:03:09 +03:00
|
|
|
if (this->EmptyBinDir && this->SourceDir == this->BinaryDir)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
|
|
|
// make sure we have the required info
|
2006-03-10 23:03:09 +03:00
|
|
|
if (this->CVSCheckOut.empty())
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-09 19:17:10 +03:00
|
|
|
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");
|
2004-09-06 20:45:14 +04:00
|
|
|
return 8;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// we must now checkout the src dir
|
|
|
|
retVal = this->CheckOutSourceDir();
|
|
|
|
if (retVal)
|
|
|
|
{
|
|
|
|
this->RestoreBackupDirectories();
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// backup the dirs if requested
|
|
|
|
retVal = this->PerformExtraUpdates();
|
|
|
|
if (retVal)
|
|
|
|
{
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
// put the initial cache into the bin dir
|
2006-03-10 23:03:09 +03:00
|
|
|
if (!this->InitCache.empty())
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
std::string cacheFile = this->BinaryDir;
|
2004-09-06 20:45:14 +04:00
|
|
|
cacheFile += "/CMakeCache.txt";
|
2005-05-28 00:17:38 +04:00
|
|
|
cmGeneratedFileStream fout(cacheFile.c_str());
|
2004-09-06 20:45:14 +04:00
|
|
|
if(!fout)
|
|
|
|
{
|
|
|
|
this->RestoreBackupDirectories();
|
|
|
|
return 9;
|
|
|
|
}
|
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
fout.write(this->InitCache.c_str(), this->InitCache.size());
|
2004-09-06 20:45:14 +04:00
|
|
|
|
|
|
|
// Make sure the operating system has finished writing the file
|
|
|
|
// before closing it. This will ensure the file is finished before
|
|
|
|
// the check below.
|
|
|
|
fout.flush();
|
|
|
|
fout.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// do an initial cmake to setup the DartConfig file
|
|
|
|
int cmakeFailed = 0;
|
|
|
|
std::string cmakeFailedOuput;
|
2006-03-10 23:03:09 +03:00
|
|
|
if (!this->CMakeCmd.empty())
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
command = this->CMakeCmd;
|
2004-09-06 20:45:14 +04:00
|
|
|
command += " \"";
|
2006-03-10 23:03:09 +03:00
|
|
|
command += this->SourceDir;
|
2004-09-06 20:45:14 +04:00
|
|
|
output = "";
|
|
|
|
command += "\"";
|
|
|
|
retVal = 0;
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run cmake command: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< command.c_str() << std::endl);
|
|
|
|
res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
|
2006-03-10 23:03:09 +03:00
|
|
|
&retVal, this->BinaryDir.c_str(),
|
|
|
|
this->HandlerVerbose, 0 /*this->TimeOut*/);
|
2004-09-28 17:00:06 +04:00
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
if ( !this->CMOutFile.empty() )
|
2004-09-28 17:00:06 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
std::string cmakeOutputFile = this->CMOutFile;
|
2004-09-28 17:00:06 +04:00
|
|
|
if ( !cmSystemTools::FileIsFullPath(cmakeOutputFile.c_str()) )
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmakeOutputFile = this->BinaryDir + "/" + cmakeOutputFile;
|
2004-09-28 17:00:06 +04:00
|
|
|
}
|
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2006-03-09 19:17:10 +03:00
|
|
|
"Write CMake output to file: " << cmakeOutputFile.c_str()
|
2005-06-01 01:32:40 +04:00
|
|
|
<< std::endl);
|
2005-05-28 00:17:38 +04:00
|
|
|
cmGeneratedFileStream fout(cmakeOutputFile.c_str());
|
2004-09-28 17:00:06 +04:00
|
|
|
if ( fout )
|
|
|
|
{
|
|
|
|
fout << output.c_str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Cannot open CMake output file: "
|
2005-06-01 01:32:40 +04:00
|
|
|
<< cmakeOutputFile.c_str() << " for writing" << std::endl);
|
2004-09-28 17:00:06 +04:00
|
|
|
}
|
|
|
|
}
|
2004-09-06 20:45:14 +04:00
|
|
|
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;
|
2006-03-10 23:03:09 +03:00
|
|
|
cmSystemTools::ExpandListArgument(this->CTestCmd,ctestCommands);
|
2004-09-06 20:45:14 +04:00
|
|
|
// for each variable/argument do a putenv
|
|
|
|
for (unsigned i = 0; i < ctestCommands.size(); ++i)
|
|
|
|
{
|
|
|
|
command = ctestCommands[i];
|
|
|
|
output = "";
|
|
|
|
retVal = 0;
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run ctest command: "
|
2006-03-09 19:17:10 +03:00
|
|
|
<< command.c_str() << std::endl);
|
|
|
|
res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
|
2006-03-10 23:03:09 +03:00
|
|
|
&retVal, this->BinaryDir.c_str(), this->HandlerVerbose,
|
|
|
|
0 /*this->TimeOut*/);
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// did something critical fail in ctest
|
|
|
|
if (!res || cmakeFailed ||
|
|
|
|
retVal & cmCTest::BUILD_ERRORS)
|
|
|
|
{
|
|
|
|
this->RestoreBackupDirectories();
|
|
|
|
if (cmakeFailed)
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unable to run cmake:" << std::endl
|
2005-06-01 01:32:40 +04:00
|
|
|
<< cmakeFailedOuput.c_str() << std::endl);
|
2004-09-06 20:45:14 +04:00
|
|
|
return 10;
|
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unable to run ctest:" << std::endl
|
2005-06-01 01:32:40 +04:00
|
|
|
<< output.c_str() << std::endl);
|
2004-09-06 20:45:14 +04:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
return 11;
|
|
|
|
}
|
|
|
|
return retVal * 100;
|
|
|
|
}
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2004-09-06 20:45:14 +04:00
|
|
|
// if all was succesful, delete the backup dirs to free up disk space
|
2006-03-10 23:03:09 +03:00
|
|
|
if (this->Backup)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmSystemTools::RemoveADirectory(this->BackupSourceDir.c_str());
|
|
|
|
cmSystemTools::RemoveADirectory(this->BackupBinaryDir.c_str());
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
|
|
|
|
2006-03-09 19:17:10 +03:00
|
|
|
return 0;
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void cmCTestScriptHandler::RestoreBackupDirectories()
|
|
|
|
{
|
|
|
|
// if we backed up the dirs and the build failed, then restore
|
|
|
|
// the backed up dirs
|
2006-03-10 23:03:09 +03:00
|
|
|
if (this->Backup)
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
|
|
|
// if for some reason those directories exist then first delete them
|
2006-03-10 23:03:09 +03:00
|
|
|
if (cmSystemTools::FileExists(this->SourceDir.c_str()))
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmSystemTools::RemoveADirectory(this->SourceDir.c_str());
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
if (cmSystemTools::FileExists(this->BinaryDir.c_str()))
|
2004-09-06 20:45:14 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmSystemTools::RemoveADirectory(this->BinaryDir.c_str());
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
// rename the src and binary directories
|
2006-03-10 23:03:09 +03:00
|
|
|
rename(this->BackupSourceDir.c_str(), this->SourceDir.c_str());
|
|
|
|
rename(this->BackupBinaryDir.c_str(), this->BinaryDir.c_str());
|
2004-09-06 20:45:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-27 19:43:22 +03:00
|
|
|
bool cmCTestScriptHandler::RunScript(cmCTest* ctest, const char *sname)
|
2005-01-27 18:11:04 +03:00
|
|
|
{
|
|
|
|
cmCTestScriptHandler* sh = new cmCTestScriptHandler();
|
2005-01-27 19:43:22 +03:00
|
|
|
sh->SetCTestInstance(ctest);
|
2005-01-27 18:11:04 +03:00
|
|
|
sh->AddConfigurationScript(sname);
|
2005-01-27 23:54:47 +03:00
|
|
|
sh->ProcessHandler();
|
2005-01-27 18:11:04 +03:00
|
|
|
delete sh;
|
|
|
|
return true;
|
|
|
|
}
|
2004-09-06 20:45:14 +04:00
|
|
|
|
2005-01-27 18:11:04 +03:00
|
|
|
bool cmCTestScriptHandler::EmptyBinaryDirectory(const char *sname)
|
|
|
|
{
|
|
|
|
// try to avoid deleting root
|
|
|
|
if (!sname || strlen(sname) < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-01-27 18:11:04 +03:00
|
|
|
// try to avoid deleting directories that we shouldn't
|
|
|
|
std::string check = sname;
|
|
|
|
check += "/CMakeCache.txt";
|
2005-03-11 20:56:10 +03:00
|
|
|
if(cmSystemTools::FileExists(check.c_str()) &&
|
|
|
|
!cmSystemTools::RemoveADirectory(sname))
|
2005-01-27 18:11:04 +03:00
|
|
|
{
|
2005-03-11 20:56:10 +03:00
|
|
|
return false;
|
2005-01-27 18:11:04 +03:00
|
|
|
}
|
2005-03-11 20:56:10 +03:00
|
|
|
return true;
|
2005-01-27 18:11:04 +03:00
|
|
|
}
|