ENH: Create cmCTestVC::RunChild and parse helpers
This method will help VCS tool subclasses run child processes and log the output while parsing it.
This commit is contained in:
parent
1595b8e69e
commit
4e4f2a3a10
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include "cmCTest.h"
|
||||
|
||||
#include <cmsys/Process.h>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmCTestVC::cmCTestVC(cmCTest* ct, std::ostream& log): CTest(ct), Log(log)
|
||||
{
|
||||
|
@ -39,3 +41,32 @@ void cmCTestVC::SetSourceDirectory(std::string const& dir)
|
|||
{
|
||||
this->SourceDirectory = dir;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool cmCTestVC::RunChild(char const* const* cmd, OutputParser* out,
|
||||
OutputParser* err, const char* workDir)
|
||||
{
|
||||
this->Log << this->ComputeCommandLine(cmd) << "\n";
|
||||
|
||||
cmsysProcess* cp = cmsysProcess_New();
|
||||
cmsysProcess_SetCommand(cp, cmd);
|
||||
workDir = workDir? workDir : this->SourceDirectory.c_str();
|
||||
cmsysProcess_SetWorkingDirectory(cp, workDir);
|
||||
this->RunProcess(cp, out, err);
|
||||
int result = cmsysProcess_GetExitValue(cp);
|
||||
cmsysProcess_Delete(cp);
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
std::string cmCTestVC::ComputeCommandLine(char const* const* cmd)
|
||||
{
|
||||
cmOStringStream line;
|
||||
const char* sep = "";
|
||||
for(const char* const* arg = cmd; *arg; ++arg)
|
||||
{
|
||||
line << sep << "\"" << *arg << "\"";
|
||||
sep = " ";
|
||||
}
|
||||
return line.str();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#ifndef cmCTestVC_h
|
||||
#define cmCTestVC_h
|
||||
|
||||
#include "cmStandardIncludes.h"
|
||||
#include "cmProcessTools.h"
|
||||
|
||||
class cmCTest;
|
||||
|
||||
|
@ -25,7 +25,7 @@ class cmCTest;
|
|||
* \brief Base class for version control system handlers
|
||||
*
|
||||
*/
|
||||
class cmCTestVC
|
||||
class cmCTestVC: public cmProcessTools
|
||||
{
|
||||
public:
|
||||
/** Construct with a CTest instance and update log stream. */
|
||||
|
@ -41,6 +41,13 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
/** Convert a list of arguments to a human-readable command line. */
|
||||
static std::string ComputeCommandLine(char const* const* cmd);
|
||||
|
||||
/** Run a command line and send output to given parsers. */
|
||||
bool RunChild(char const* const* cmd, OutputParser* out,
|
||||
OutputParser* err, const char* workDir = 0);
|
||||
|
||||
// Instance of cmCTest running the script.
|
||||
cmCTest* CTest;
|
||||
|
||||
|
|
Loading…
Reference in New Issue