summaryrefslogtreecommitdiffstats
path: root/Source/CTest
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-02-26 14:22:32 (GMT)
committerBrad King <brad.king@kitware.com>2009-02-26 14:22:32 (GMT)
commit3829be4ca66e79310ef19750e877634169c64431 (patch)
tree18aa87c67be3653ad6f33327676423cda0c7955c /Source/CTest
parent7960f7541ce3d8d03ce68b0e5a37e67019bbe557 (diff)
downloadCMake-3829be4ca66e79310ef19750e877634169c64431.zip
CMake-3829be4ca66e79310ef19750e877634169c64431.tar.gz
CMake-3829be4ca66e79310ef19750e877634169c64431.tar.bz2
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.
Diffstat (limited to 'Source/CTest')
-rw-r--r--Source/CTest/cmCTestUpdateHandler.cxx46
-rw-r--r--Source/CTest/cmCTestVC.cxx42
-rw-r--r--Source/CTest/cmCTestVC.h3
3 files changed, 51 insertions, 40 deletions
diff --git a/Source/CTest/cmCTestUpdateHandler.cxx b/Source/CTest/cmCTestUpdateHandler.cxx
index 5ac5ebc..5f4dfc0 100644
--- a/Source/CTest/cmCTestUpdateHandler.cxx
+++ b/Source/CTest/cmCTestUpdateHandler.cxx
@@ -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,
diff --git a/Source/CTest/cmCTestVC.cxx b/Source/CTest/cmCTestVC.cxx
index 642a59a..9f079af 100644
--- a/Source/CTest/cmCTestVC.cxx
+++ b/Source/CTest/cmCTestVC.cxx
@@ -17,6 +17,7 @@
#include "cmCTestVC.h"
#include "cmCTest.h"
+#include "cmSystemTools.h"
#include "cmXMLSafe.h"
#include <cmsys/Process.h>
@@ -50,6 +51,47 @@ void cmCTestVC::SetSourceDirectory(std::string const& 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)
{
diff --git a/Source/CTest/cmCTestVC.h b/Source/CTest/cmCTestVC.h
index 43ae5b9..8f8adf4 100644
--- a/Source/CTest/cmCTestVC.h
+++ b/Source/CTest/cmCTestVC.h
@@ -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();