CTest: Move initial checkout to ctest_start()
In CTest command-driven script mode we support starting without a source tree. Previously the ctest_start() command would do some initialization but could not do anything that required CTestConfig.cmake from the input source tree. Later, ctest_update() would run CTEST_CHECKOUT_COMMAND to create the source tree, and then re-initialize everything. This delayed-initialization approach led to many complicated cases of which only some worked. For example, the second initialization only worked correctly in Nightly mode and simply failed for Experimental and Continuous builds. A simpler solution is to run CTEST_CHECKOUT_COMMAND during ctest_start() and then have a single initialization path. In principle this change in behavior could break scripts that set the checkout command after ctest_start() but before ctest_update(). However, the convention we've always followed has been to set all variables before ctest_start(). See issue #9450.
This commit is contained in:
parent
c2ba35787e
commit
e1548142fb
|
@ -14,6 +14,8 @@
|
|||
#include "cmCTest.h"
|
||||
#include "cmLocalGenerator.h"
|
||||
#include "cmGlobalGenerator.h"
|
||||
#include "cmCTestVC.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
|
||||
bool cmCTestStartCommand
|
||||
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
|
||||
|
@ -76,10 +78,11 @@ bool cmCTestStartCommand
|
|||
cmSystemTools::AddKeepPath(bld_dir);
|
||||
|
||||
this->CTest->EmptyCTestConfiguration();
|
||||
this->CTest->SetCTestConfiguration("SourceDirectory",
|
||||
cmSystemTools::CollapseFullPath(src_dir).c_str());
|
||||
this->CTest->SetCTestConfiguration("BuildDirectory",
|
||||
cmSystemTools::CollapseFullPath(bld_dir).c_str());
|
||||
|
||||
std::string sourceDir = cmSystemTools::CollapseFullPath(src_dir);
|
||||
std::string binaryDir = cmSystemTools::CollapseFullPath(bld_dir);
|
||||
this->CTest->SetCTestConfiguration("SourceDirectory", sourceDir.c_str());
|
||||
this->CTest->SetCTestConfiguration("BuildDirectory", binaryDir.c_str());
|
||||
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Run dashboard with model "
|
||||
<< smodel << std::endl
|
||||
|
@ -92,13 +95,62 @@ bool cmCTestStartCommand
|
|||
" Track: " << track << std::endl);
|
||||
}
|
||||
|
||||
// Log startup actions.
|
||||
std::string startLogFile = binaryDir + "/Testing/Temporary/LastStart.log";
|
||||
cmGeneratedFileStream ofs(startLogFile.c_str());
|
||||
if(!ofs)
|
||||
{
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
||||
"Cannot create log file: LastStart.log" << std::endl);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the source directory exists.
|
||||
if(!this->InitialCheckout(ofs, sourceDir))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(!cmSystemTools::FileIsDirectory(sourceDir.c_str()))
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << "given source path\n"
|
||||
<< " " << sourceDir << "\n"
|
||||
<< "which is not an existing directory. "
|
||||
<< "Set CTEST_CHECKOUT_COMMAND to a command line to create it.";
|
||||
this->SetError(e.str().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", "OFF");
|
||||
this->CTest->SetSuppressUpdatingCTestConfiguration(true);
|
||||
int model = this->CTest->GetTestModelFromString(smodel);
|
||||
this->CTest->SetTestModel(model);
|
||||
this->CTest->SetProduceXML(true);
|
||||
|
||||
return this->CTest->InitializeFromCommand(this, true);
|
||||
return this->CTest->InitializeFromCommand(this);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool cmCTestStartCommand::InitialCheckout(
|
||||
std::ostream& ofs, std::string const& sourceDir)
|
||||
{
|
||||
// Use the user-provided command to create the source tree.
|
||||
const char* initialCheckoutCommand
|
||||
= this->Makefile->GetDefinition("CTEST_CHECKOUT_COMMAND");
|
||||
if(!initialCheckoutCommand)
|
||||
{
|
||||
initialCheckoutCommand =
|
||||
this->Makefile->GetDefinition("CTEST_CVS_CHECKOUT");
|
||||
}
|
||||
if(initialCheckoutCommand)
|
||||
{
|
||||
// Use a generic VC object to run and log the command.
|
||||
cmCTestVC vc(this->CTest, ofs);
|
||||
vc.SetSourceDirectory(sourceDir.c_str());
|
||||
if(!vc.InitialCheckout(initialCheckoutCommand))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -72,6 +72,8 @@ public:
|
|||
|
||||
cmTypeMacro(cmCTestStartCommand, cmCTestCommand);
|
||||
|
||||
private:
|
||||
bool InitialCheckout(std::ostream& ofs, std::string const& sourceDir);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -56,14 +56,6 @@ cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler()
|
|||
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
|
||||
"HGUpdateOptions", "CTEST_HG_UPDATE_OPTIONS");
|
||||
|
||||
const char* initialCheckoutCommand
|
||||
= this->Makefile->GetDefinition("CTEST_CHECKOUT_COMMAND");
|
||||
if ( !initialCheckoutCommand )
|
||||
{
|
||||
initialCheckoutCommand =
|
||||
this->Makefile->GetDefinition("CTEST_CVS_CHECKOUT");
|
||||
}
|
||||
|
||||
cmCTestGenericHandler* handler
|
||||
= this->CTest->GetInitializedHandler("update");
|
||||
if ( !handler )
|
||||
|
@ -78,24 +70,6 @@ cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler()
|
|||
return 0;
|
||||
}
|
||||
handler->SetOption("SourceDirectory", source_dir.c_str());
|
||||
if ( initialCheckoutCommand )
|
||||
{
|
||||
handler->SetOption("InitialCheckout", initialCheckoutCommand);
|
||||
}
|
||||
if ( (!cmSystemTools::FileExists(source_dir.c_str()) ||
|
||||
!cmSystemTools::FileIsDirectory(source_dir.c_str()))
|
||||
&& !initialCheckoutCommand )
|
||||
{
|
||||
cmOStringStream str;
|
||||
str << "cannot find source directory: " << source_dir.c_str() << ".";
|
||||
if ( !cmSystemTools::FileExists(source_dir.c_str()) )
|
||||
{
|
||||
str << " Looks like it is not checked out yet. Please specify "
|
||||
"CTEST_CHECKOUT_COMMAND.";
|
||||
}
|
||||
this->SetError(str.str().c_str());
|
||||
return 0;
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
|
|
|
@ -201,15 +201,6 @@ int cmCTestUpdateHandler::ProcessHandler()
|
|||
this->StartLogFile("Update", ofs);
|
||||
}
|
||||
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
||||
"Updating the repository" << std::endl);
|
||||
|
||||
// Make sure the source directory exists.
|
||||
if(!this->InitialCheckout(ofs))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT, " Updating the repository: "
|
||||
<< sourceDirectory << std::endl);
|
||||
|
||||
|
@ -322,32 +313,6 @@ int cmCTestUpdateHandler::ProcessHandler()
|
|||
return numUpdated;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool cmCTestUpdateHandler::InitialCheckout(std::ostream& ofs)
|
||||
{
|
||||
// Use the user-provided command to create the source tree.
|
||||
if(const char* command = this->GetOption("InitialCheckout"))
|
||||
{
|
||||
// Use a generic VC object to run and log the command.
|
||||
cmCTestVC vc(this->CTest, ofs);
|
||||
vc.SetSourceDirectory(this->GetOption("SourceDirectory"));
|
||||
if(!vc.InitialCheckout(command))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!this->CTest->InitializeFromCommand(this->Command))
|
||||
{
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Fatal Error in initialize: "
|
||||
<< std::endl);
|
||||
cmSystemTools::SetFatalErrorOccured();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
int cmCTestUpdateHandler::DetectVCS(const char* dir)
|
||||
{
|
||||
|
|
|
@ -65,7 +65,6 @@ private:
|
|||
std::string UpdateCommand;
|
||||
int UpdateType;
|
||||
|
||||
bool InitialCheckout(std::ostream& ofs);
|
||||
int DetectVCS(const char* dir);
|
||||
bool SelectVCS();
|
||||
};
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "cmXMLSafe.h"
|
||||
#include "cmVersionMacros.h"
|
||||
#include "cmCTestCommand.h"
|
||||
#include "cmCTestStartCommand.h"
|
||||
|
||||
#include "cmCTestBuildHandler.h"
|
||||
#include "cmCTestBuildAndTestHandler.h"
|
||||
|
@ -452,13 +453,8 @@ int cmCTest::Initialize(const char* binary_dir, bool script)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool cmCTest::InitializeFromCommand(cmCTestCommand* command, bool first)
|
||||
bool cmCTest::InitializeFromCommand(cmCTestStartCommand* command)
|
||||
{
|
||||
if ( !first && !this->CurrentTag.empty() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string src_dir
|
||||
= this->GetCTestConfiguration("SourceDirectory").c_str();
|
||||
std::string bld_dir = this->GetCTestConfiguration("BuildDirectory").c_str();
|
||||
|
@ -486,17 +482,11 @@ bool cmCTest::InitializeFromCommand(cmCTestCommand* command, bool first)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
else if ( !first )
|
||||
else
|
||||
{
|
||||
cmCTestLog(this, WARNING, "Cannot locate CTest configuration: "
|
||||
<< fname.c_str() << std::endl);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmCTestLog(this, HANDLER_OUTPUT, " Cannot locate CTest configuration: "
|
||||
<< fname.c_str() << std::endl
|
||||
<< " Delay the initialization of CTest" << std::endl);
|
||||
}
|
||||
|
||||
this->SetCTestConfigurationFromCMakeVariable(mf, "NightlyStartTime",
|
||||
"CTEST_NIGHTLY_START_TIME");
|
||||
|
@ -518,10 +508,6 @@ bool cmCTest::InitializeFromCommand(cmCTestCommand* command, bool first)
|
|||
|
||||
if ( !this->Initialize(bld_dir.c_str(), true) )
|
||||
{
|
||||
if ( this->GetCTestConfiguration("NightlyStartTime").empty() && first)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
cmCTestLog(this, OUTPUT, " Use " << this->GetTestModelString()
|
||||
|
|
|
@ -23,6 +23,7 @@ class cmCTestGenericHandler;
|
|||
class cmGeneratedFileStream;
|
||||
class cmCTestCommand;
|
||||
class cmCTestScriptHandler;
|
||||
class cmCTestStartCommand;
|
||||
|
||||
#define cmCTestLog(ctSelf, logType, msg) \
|
||||
do { \
|
||||
|
@ -93,7 +94,7 @@ public:
|
|||
/**
|
||||
* Initialize and finalize testing
|
||||
*/
|
||||
bool InitializeFromCommand(cmCTestCommand* command, bool first = false);
|
||||
bool InitializeFromCommand(cmCTestStartCommand* command);
|
||||
void Finalize();
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue