2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc.
|
2009-07-10 19:08:05 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2009-07-10 19:08:05 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2009-07-10 19:08:05 +04:00
|
|
|
#include "cmCTestHG.h"
|
|
|
|
|
|
|
|
#include "cmCTest.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmXMLParser.h"
|
|
|
|
|
|
|
|
#include <cmsys/RegularExpression.hxx>
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCTestHG::cmCTestHG(cmCTest* ct, std::ostream& log)
|
|
|
|
: cmCTestGlobalVC(ct, log)
|
2009-07-10 19:08:05 +04:00
|
|
|
{
|
|
|
|
this->PriorRev = this->Unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCTestHG::~cmCTestHG()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
class cmCTestHG::IdentifyParser : public cmCTestVC::LineParser
|
2009-07-10 19:08:05 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-05-16 17:34:04 +03:00
|
|
|
IdentifyParser(cmCTestHG* hg, const char* prefix, std::string& rev)
|
|
|
|
: Rev(rev)
|
|
|
|
{
|
2009-07-10 19:08:05 +04:00
|
|
|
this->SetLog(&hg->Log, prefix);
|
|
|
|
this->RegexIdentify.compile("^([0-9a-f]+)");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
|
2009-07-10 19:08:05 +04:00
|
|
|
private:
|
|
|
|
std::string& Rev;
|
|
|
|
cmsys::RegularExpression RegexIdentify;
|
|
|
|
|
2016-06-23 02:02:39 +03:00
|
|
|
bool ProcessLine() CM_OVERRIDE
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->RegexIdentify.find(this->Line)) {
|
2009-07-10 19:08:05 +04:00
|
|
|
this->Rev = this->RegexIdentify.match(1);
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
};
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
class cmCTestHG::StatusParser : public cmCTestVC::LineParser
|
2009-07-10 19:08:05 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-05-16 17:34:04 +03:00
|
|
|
StatusParser(cmCTestHG* hg, const char* prefix)
|
|
|
|
: HG(hg)
|
|
|
|
{
|
2009-07-10 19:08:05 +04:00
|
|
|
this->SetLog(&hg->Log, prefix);
|
|
|
|
this->RegexStatus.compile("([MARC!?I]) (.*)");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
cmCTestHG* HG;
|
|
|
|
cmsys::RegularExpression RegexStatus;
|
|
|
|
|
2016-06-23 02:02:39 +03:00
|
|
|
bool ProcessLine() CM_OVERRIDE
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->RegexStatus.find(this->Line)) {
|
|
|
|
this->DoPath(this->RegexStatus.match(1)[0], this->RegexStatus.match(2));
|
2009-07-10 19:08:05 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
|
|
|
|
void DoPath(char status, std::string const& path)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2016-06-10 19:36:24 +03:00
|
|
|
if (path.empty()) {
|
2016-05-16 17:34:04 +03:00
|
|
|
return;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
|
|
|
|
// See "hg help status". Note that there is no 'conflict' status.
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (status) {
|
|
|
|
case 'M':
|
|
|
|
case 'A':
|
|
|
|
case '!':
|
|
|
|
case 'R':
|
2009-07-10 19:08:05 +04:00
|
|
|
this->HG->DoModification(PathModified, path);
|
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
case 'I':
|
|
|
|
case '?':
|
|
|
|
case 'C':
|
|
|
|
case ' ':
|
|
|
|
default:
|
2009-07-10 19:08:05 +04:00
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
std::string cmCTestHG::GetWorkingRevision()
|
|
|
|
{
|
|
|
|
// Run plumbing "hg identify" to get work tree revision.
|
|
|
|
const char* hg = this->CommandLineTool.c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* hg_identify[] = { hg, "identify", "-i", 0 };
|
2009-07-10 19:08:05 +04:00
|
|
|
std::string rev;
|
|
|
|
IdentifyParser out(this, "rev-out> ", rev);
|
|
|
|
OutputLogger err(this->Log, "rev-err> ");
|
|
|
|
this->RunChild(hg_identify, &out, &err);
|
|
|
|
return rev;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestHG::NoteOldRevision()
|
|
|
|
{
|
|
|
|
this->OldRevision = this->GetWorkingRevision();
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " Old revision of repository is: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< this->OldRevision << "\n");
|
2009-07-10 19:08:05 +04:00
|
|
|
this->PriorRev.Rev = this->OldRevision;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestHG::NoteNewRevision()
|
|
|
|
{
|
|
|
|
this->NewRevision = this->GetWorkingRevision();
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " New revision of repository is: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< this->NewRevision << "\n");
|
2009-07-10 19:08:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestHG::UpdateImpl()
|
|
|
|
{
|
|
|
|
// Use "hg pull" followed by "hg update" to update the working tree.
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* hg = this->CommandLineTool.c_str();
|
|
|
|
const char* hg_pull[] = { hg, "pull", "-v", 0 };
|
|
|
|
OutputLogger out(this->Log, "pull-out> ");
|
|
|
|
OutputLogger err(this->Log, "pull-err> ");
|
|
|
|
this->RunChild(&hg_pull[0], &out, &err);
|
2009-07-10 19:08:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: if(this->CTest->GetTestModel() == cmCTest::NIGHTLY)
|
|
|
|
|
|
|
|
std::vector<char const*> hg_update;
|
|
|
|
hg_update.push_back(this->CommandLineTool.c_str());
|
|
|
|
hg_update.push_back("update");
|
|
|
|
hg_update.push_back("-v");
|
|
|
|
|
|
|
|
// Add user-specified update options.
|
|
|
|
std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (opts.empty()) {
|
2009-07-10 19:08:05 +04:00
|
|
|
opts = this->CTest->GetCTestConfiguration("HGUpdateOptions");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-10 09:21:34 +04:00
|
|
|
std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator ai = args.begin();
|
|
|
|
ai != args.end(); ++ai) {
|
2009-07-10 19:08:05 +04:00
|
|
|
hg_update.push_back(ai->c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
|
|
|
|
// Sentinel argument.
|
|
|
|
hg_update.push_back(0);
|
|
|
|
|
|
|
|
OutputLogger out(this->Log, "update-out> ");
|
|
|
|
OutputLogger err(this->Log, "update-err> ");
|
|
|
|
return this->RunUpdateCommand(&hg_update[0], &out, &err);
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
class cmCTestHG::LogParser : public cmCTestVC::OutputLogger,
|
|
|
|
private cmXMLParser
|
2009-07-10 19:08:05 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-05-16 17:34:04 +03:00
|
|
|
LogParser(cmCTestHG* hg, const char* prefix)
|
|
|
|
: OutputLogger(hg->Log, prefix)
|
|
|
|
, HG(hg)
|
|
|
|
{
|
|
|
|
this->InitializeParser();
|
|
|
|
}
|
2016-06-27 22:25:27 +03:00
|
|
|
~LogParser() CM_OVERRIDE { this->CleanupParser(); }
|
2009-07-10 19:08:05 +04:00
|
|
|
private:
|
|
|
|
cmCTestHG* HG;
|
|
|
|
|
|
|
|
typedef cmCTestHG::Revision Revision;
|
|
|
|
typedef cmCTestHG::Change Change;
|
|
|
|
Revision Rev;
|
|
|
|
std::vector<Change> Changes;
|
|
|
|
Change CurChange;
|
|
|
|
std::vector<char> CData;
|
|
|
|
|
2016-06-23 02:02:39 +03:00
|
|
|
bool ProcessChunk(const char* data, int length) CM_OVERRIDE
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2009-07-10 19:08:05 +04:00
|
|
|
this->OutputLogger::ProcessChunk(data, length);
|
|
|
|
this->ParseChunk(data, length);
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
|
2016-06-23 02:02:39 +03:00
|
|
|
void StartElement(const std::string& name, const char** atts) CM_OVERRIDE
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2009-07-10 19:08:05 +04:00
|
|
|
this->CData.clear();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (name == "logentry") {
|
2009-07-10 19:08:05 +04:00
|
|
|
this->Rev = Revision();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* rev = this->FindAttribute(atts, "revision")) {
|
2009-07-10 19:08:05 +04:00
|
|
|
this->Rev.Rev = rev;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Changes.clear();
|
2009-07-10 19:08:05 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
|
2016-06-23 02:02:39 +03:00
|
|
|
void CharacterDataHandler(const char* data, int length) CM_OVERRIDE
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
this->CData.insert(this->CData.end(), data, data + length);
|
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
|
2016-06-23 02:02:39 +03:00
|
|
|
void EndElement(const std::string& name) CM_OVERRIDE
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (name == "logentry") {
|
2009-07-10 19:08:05 +04:00
|
|
|
this->HG->DoRevision(this->Rev, this->Changes);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!this->CData.empty() && name == "author") {
|
2009-07-10 19:08:05 +04:00
|
|
|
this->Rev.Author.assign(&this->CData[0], this->CData.size());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!this->CData.empty() && name == "email") {
|
2010-05-07 17:17:26 +04:00
|
|
|
this->Rev.EMail.assign(&this->CData[0], this->CData.size());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!this->CData.empty() && name == "date") {
|
2009-07-10 19:08:05 +04:00
|
|
|
this->Rev.Date.assign(&this->CData[0], this->CData.size());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!this->CData.empty() && name == "msg") {
|
2009-07-10 19:08:05 +04:00
|
|
|
this->Rev.Log.assign(&this->CData[0], this->CData.size());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!this->CData.empty() && name == "files") {
|
2009-07-10 19:08:05 +04:00
|
|
|
std::vector<std::string> paths = this->SplitCData();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 0; i < paths.size(); ++i) {
|
2009-07-10 19:08:05 +04:00
|
|
|
// Updated by default, will be modified using file_adds and
|
|
|
|
// file_dels.
|
|
|
|
this->CurChange = Change('U');
|
|
|
|
this->CurChange.Path = paths[i];
|
|
|
|
this->Changes.push_back(this->CurChange);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!this->CData.empty() && name == "file_adds") {
|
2009-07-10 19:08:05 +04:00
|
|
|
std::string added_paths(this->CData.begin(), this->CData.end());
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 0; i < this->Changes.size(); ++i) {
|
|
|
|
if (added_paths.find(this->Changes[i].Path) != std::string::npos) {
|
2009-07-10 19:08:05 +04:00
|
|
|
this->Changes[i].Action = 'A';
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!this->CData.empty() && name == "file_dels") {
|
2009-07-10 19:08:05 +04:00
|
|
|
std::string added_paths(this->CData.begin(), this->CData.end());
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 0; i < this->Changes.size(); ++i) {
|
|
|
|
if (added_paths.find(this->Changes[i].Path) != std::string::npos) {
|
2009-07-10 19:08:05 +04:00
|
|
|
this->Changes[i].Action = 'D';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->CData.clear();
|
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
|
|
|
|
std::vector<std::string> SplitCData()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2009-07-10 19:08:05 +04:00
|
|
|
std::vector<std::string> output;
|
|
|
|
std::string currPath;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 0; i < this->CData.size(); ++i) {
|
|
|
|
if (this->CData[i] != ' ') {
|
2009-07-10 21:08:54 +04:00
|
|
|
currPath += this->CData[i];
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2009-07-10 19:08:05 +04:00
|
|
|
output.push_back(currPath);
|
2009-07-10 21:08:54 +04:00
|
|
|
currPath = "";
|
2009-07-10 19:08:05 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
output.push_back(currPath);
|
|
|
|
return output;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
|
2016-06-23 02:02:39 +03:00
|
|
|
void ReportError(int, int, const char* msg) CM_OVERRIDE
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2009-07-10 19:08:05 +04:00
|
|
|
this->HG->Log << "Error parsing hg log xml: " << msg << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-07-10 19:08:05 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void cmCTestHG::LoadRevisions()
|
|
|
|
{
|
|
|
|
// Use 'hg log' to get revisions in a xml format.
|
|
|
|
//
|
|
|
|
// TODO: This should use plumbing or python code to be more precise.
|
|
|
|
// The "list of strings" templates like {files} will not work when
|
|
|
|
// the project has spaces in the path. Also, they may not have
|
|
|
|
// proper XML escapes.
|
|
|
|
std::string range = this->OldRevision + ":" + this->NewRevision;
|
|
|
|
const char* hg = this->CommandLineTool.c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* hgXMLTemplate = "<logentry\n"
|
|
|
|
" revision=\"{node|short}\">\n"
|
|
|
|
" <author>{author|person}</author>\n"
|
|
|
|
" <email>{author|email}</email>\n"
|
|
|
|
" <date>{date|isodate}</date>\n"
|
|
|
|
" <msg>{desc}</msg>\n"
|
|
|
|
" <files>{files}</files>\n"
|
|
|
|
" <file_adds>{file_adds}</file_adds>\n"
|
|
|
|
" <file_dels>{file_dels}</file_dels>\n"
|
|
|
|
"</logentry>\n";
|
|
|
|
const char* hg_log[] = {
|
|
|
|
hg, "log", "--removed", "-r", range.c_str(), "--template", hgXMLTemplate, 0
|
|
|
|
};
|
2009-07-10 19:08:05 +04:00
|
|
|
|
|
|
|
LogParser out(this, "log-out> ");
|
|
|
|
out.Process("<?xml version=\"1.0\"?>\n"
|
|
|
|
"<log>\n");
|
|
|
|
OutputLogger err(this->Log, "log-err> ");
|
|
|
|
this->RunChild(hg_log, &out, &err);
|
|
|
|
out.Process("</log>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestHG::LoadModifications()
|
|
|
|
{
|
|
|
|
// Use 'hg status' to get modified files.
|
|
|
|
const char* hg = this->CommandLineTool.c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* hg_status[] = { hg, "status", 0 };
|
2009-07-10 19:08:05 +04:00
|
|
|
StatusParser out(this, "status-out> ");
|
|
|
|
OutputLogger err(this->Log, "status-err> ");
|
|
|
|
this->RunChild(hg_status, &out, &err);
|
|
|
|
}
|