ENH: Refactor initial checkout into cmCTestVC
This adds cmCTestVC::InitialCheckout and uses it in cmCTestUpdateHandler to run the initial checkout command. The new implementation logs the command in the update log consistently with the rest of the new update implementation.
This commit is contained in:
parent
7960f7541c
commit
3829be4ca6
|
@ -296,51 +296,17 @@ int cmCTestUpdateHandler::ProcessHandler()
|
|||
//----------------------------------------------------------------------
|
||||
bool cmCTestUpdateHandler::InitialCheckout(std::ostream& ofs)
|
||||
{
|
||||
const char* sourceDirectory = this->GetOption("SourceDirectory");
|
||||
|
||||
// Use the user-provided command to create the source tree.
|
||||
const char* initialCheckoutCommand = this->GetOption("InitialCheckout");
|
||||
if ( initialCheckoutCommand )
|
||||
if(const char* command = this->GetOption("InitialCheckout"))
|
||||
{
|
||||
std::string goutput;
|
||||
std::string errors;
|
||||
int retVal = 0;
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
||||
" First perform the initial checkout: " << initialCheckoutCommand
|
||||
<< std::endl);
|
||||
cmStdString parent = cmSystemTools::GetParentDirectory(sourceDirectory);
|
||||
if ( parent.empty() )
|
||||
// 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))
|
||||
{
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
||||
"Something went wrong when trying "
|
||||
"to determine the parent directory of " << sourceDirectory
|
||||
<< std::endl);
|
||||
return false;
|
||||
}
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Perform checkout in directory: " << parent.c_str() << std::endl);
|
||||
if ( !cmSystemTools::MakeDirectory(parent.c_str()) )
|
||||
{
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
||||
"Cannot create parent directory: " << parent.c_str()
|
||||
<< " of the source directory: " << sourceDirectory << std::endl);
|
||||
return false;
|
||||
}
|
||||
ofs << "* Run initial checkout" << std::endl;
|
||||
ofs << " Command: " << initialCheckoutCommand << std::endl;
|
||||
cmCTestLog(this->CTest, DEBUG, " Before: "
|
||||
<< initialCheckoutCommand << std::endl);
|
||||
bool retic = this->CTest->RunCommand(initialCheckoutCommand, &goutput,
|
||||
&errors, &retVal, parent.c_str(), 0 /* Timeout */);
|
||||
cmCTestLog(this->CTest, DEBUG, " After: "
|
||||
<< initialCheckoutCommand << std::endl);
|
||||
ofs << " Output: " << goutput.c_str() << std::endl;
|
||||
ofs << " Errors: " << errors.c_str() << std::endl;
|
||||
if ( !retic || retVal )
|
||||
{
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE, "Initial checkout failed:\n"
|
||||
<< goutput << "\n" << errors << "\n");
|
||||
}
|
||||
|
||||
if(!this->CTest->InitializeFromCommand(this->Command))
|
||||
{
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "cmCTestVC.h"
|
||||
|
||||
#include "cmCTest.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmXMLSafe.h"
|
||||
|
||||
#include <cmsys/Process.h>
|
||||
|
@ -49,6 +50,47 @@ void cmCTestVC::SetSourceDirectory(std::string const& dir)
|
|||
this->SourceDirectory = dir;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool cmCTestVC::InitialCheckout(const char* command)
|
||||
{
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
||||
" First perform the initial checkout: " << command << "\n");
|
||||
|
||||
// Make the parent directory in which to perform the checkout.
|
||||
std::string parent = cmSystemTools::GetFilenamePath(this->SourceDirectory);
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Perform checkout in directory: " << parent << "\n");
|
||||
if(!cmSystemTools::MakeDirectory(parent.c_str()))
|
||||
{
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
||||
"Cannot create directory: " << parent << std::endl);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Construct the initial checkout command line.
|
||||
std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
|
||||
std::vector<char const*> vc_co;
|
||||
for(std::vector<cmStdString>::const_iterator ai = args.begin();
|
||||
ai != args.end(); ++ai)
|
||||
{
|
||||
vc_co.push_back(ai->c_str());
|
||||
}
|
||||
vc_co.push_back(0);
|
||||
|
||||
// Run the initial checkout command and log its output.
|
||||
this->Log << "--- Begin Initial Checkout ---\n";
|
||||
OutputLogger out(this->Log, "co-out> ");
|
||||
OutputLogger err(this->Log, "co-err> ");
|
||||
bool result = this->RunChild(&vc_co[0], &out, &err, parent.c_str());
|
||||
this->Log << "--- End Initial Checkout ---\n";
|
||||
if(!result)
|
||||
{
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
||||
"Initial checkout failed!" << std::endl);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool cmCTestVC::RunChild(char const* const* cmd, OutputParser* out,
|
||||
OutputParser* err, const char* workDir)
|
||||
|
|
|
@ -42,6 +42,9 @@ public:
|
|||
/** Get the date/time specification for the current nightly start time. */
|
||||
std::string GetNightlyTime();
|
||||
|
||||
/** Prepare the work tree. */
|
||||
bool InitialCheckout(const char* command);
|
||||
|
||||
/** Perform cleanup operations on the work tree. */
|
||||
void Cleanup();
|
||||
|
||||
|
|
Loading…
Reference in New Issue