2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc.
|
2009-02-24 18:39:55 +03: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-02-24 18:39:55 +03: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-02-24 18:39:55 +03:00
|
|
|
#include "cmCTestCVS.h"
|
|
|
|
|
2009-02-25 22:42:45 +03:00
|
|
|
#include "cmCTest.h"
|
|
|
|
#include "cmSystemTools.h"
|
2015-05-24 01:33:24 +03:00
|
|
|
#include "cmXMLWriter.h"
|
2009-02-25 22:42:45 +03:00
|
|
|
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
2009-02-25 22:42:45 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCTestCVS::cmCTestCVS(cmCTest* ct, std::ostream& log)
|
|
|
|
: cmCTestVC(ct, log)
|
2009-02-24 18:39:55 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCTestCVS::~cmCTestCVS()
|
|
|
|
{
|
|
|
|
}
|
2009-02-25 22:42:45 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
class cmCTestCVS::UpdateParser : public cmCTestVC::LineParser
|
2009-02-25 22:42:45 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-05-16 17:34:04 +03:00
|
|
|
UpdateParser(cmCTestCVS* cvs, const char* prefix)
|
|
|
|
: CVS(cvs)
|
|
|
|
{
|
2009-02-25 22:42:45 +03:00
|
|
|
this->SetLog(&cvs->Log, prefix);
|
|
|
|
// See "man cvs", section "update output".
|
|
|
|
this->RegexFileUpdated.compile("^([UP]) *(.*)");
|
|
|
|
this->RegexFileModified.compile("^([MRA]) *(.*)");
|
|
|
|
this->RegexFileConflicting.compile("^([C]) *(.*)");
|
|
|
|
this->RegexFileRemoved1.compile(
|
2009-06-23 17:06:13 +04:00
|
|
|
"cvs[^ ]* update: `?([^']*)'? is no longer in the repository");
|
2009-02-25 22:42:45 +03:00
|
|
|
this->RegexFileRemoved2.compile(
|
2009-06-23 17:06:13 +04:00
|
|
|
"cvs[^ ]* update: "
|
|
|
|
"warning: `?([^']*)'? is not \\(any longer\\) pertinent");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
|
2009-02-25 22:42:45 +03:00
|
|
|
private:
|
|
|
|
cmCTestCVS* CVS;
|
|
|
|
cmsys::RegularExpression RegexFileUpdated;
|
|
|
|
cmsys::RegularExpression RegexFileModified;
|
|
|
|
cmsys::RegularExpression RegexFileConflicting;
|
|
|
|
cmsys::RegularExpression RegexFileRemoved1;
|
|
|
|
cmsys::RegularExpression RegexFileRemoved2;
|
|
|
|
|
2016-06-23 02:02:39 +03:00
|
|
|
bool ProcessLine() CM_OVERRIDE
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->RegexFileUpdated.find(this->Line)) {
|
2009-02-25 22:42:45 +03:00
|
|
|
this->DoFile(PathUpdated, this->RegexFileUpdated.match(2));
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->RegexFileModified.find(this->Line)) {
|
2009-02-25 22:42:45 +03:00
|
|
|
this->DoFile(PathModified, this->RegexFileModified.match(2));
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->RegexFileConflicting.find(this->Line)) {
|
2009-02-25 22:42:45 +03:00
|
|
|
this->DoFile(PathConflicting, this->RegexFileConflicting.match(2));
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->RegexFileRemoved1.find(this->Line)) {
|
2009-02-25 22:42:45 +03:00
|
|
|
this->DoFile(PathUpdated, this->RegexFileRemoved1.match(1));
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->RegexFileRemoved2.find(this->Line)) {
|
2009-02-25 22:42:45 +03:00
|
|
|
this->DoFile(PathUpdated, this->RegexFileRemoved2.match(1));
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
2009-02-25 22:42:45 +03:00
|
|
|
|
|
|
|
void DoFile(PathStatus status, std::string const& file)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2009-02-25 22:42:45 +03:00
|
|
|
std::string dir = cmSystemTools::GetFilenamePath(file);
|
|
|
|
std::string name = cmSystemTools::GetFilenameName(file);
|
|
|
|
this->CVS->Dirs[dir][name] = status;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-25 22:42:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
bool cmCTestCVS::UpdateImpl()
|
|
|
|
{
|
|
|
|
// Get user-specified update options.
|
|
|
|
std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (opts.empty()) {
|
2009-02-25 22:42:45 +03:00
|
|
|
opts = this->CTest->GetCTestConfiguration("CVSUpdateOptions");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (opts.empty()) {
|
2009-02-25 22:42:45 +03:00
|
|
|
opts = "-dP";
|
|
|
|
}
|
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());
|
2009-02-25 22:42:45 +03:00
|
|
|
|
|
|
|
// Specify the start time for nightly testing.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CTest->GetTestModel() == cmCTest::NIGHTLY) {
|
2009-02-25 22:42:45 +03:00
|
|
|
args.push_back("-D" + this->GetNightlyTime() + " UTC");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-25 22:42:45 +03:00
|
|
|
|
|
|
|
// Run "cvs update" to update the work tree.
|
|
|
|
std::vector<char const*> cvs_update;
|
|
|
|
cvs_update.push_back(this->CommandLineTool.c_str());
|
|
|
|
cvs_update.push_back("-z3");
|
|
|
|
cvs_update.push_back("update");
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator ai = args.begin();
|
|
|
|
ai != args.end(); ++ai) {
|
2009-02-25 22:42:45 +03:00
|
|
|
cvs_update.push_back(ai->c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-25 22:42:45 +03:00
|
|
|
cvs_update.push_back(0);
|
|
|
|
|
|
|
|
UpdateParser out(this, "up-out> ");
|
|
|
|
UpdateParser err(this, "up-err> ");
|
|
|
|
return this->RunUpdateCommand(&cvs_update[0], &out, &err);
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
class cmCTestCVS::LogParser : public cmCTestVC::LineParser
|
2009-02-25 22:42:45 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef cmCTestCVS::Revision Revision;
|
2016-05-16 17:34:04 +03:00
|
|
|
LogParser(cmCTestCVS* cvs, const char* prefix, std::vector<Revision>& revs)
|
|
|
|
: CVS(cvs)
|
|
|
|
, Revisions(revs)
|
|
|
|
, Section(SectionHeader)
|
|
|
|
{
|
2009-02-25 22:42:45 +03:00
|
|
|
this->SetLog(&cvs->Log, prefix),
|
2016-05-16 17:34:04 +03:00
|
|
|
this->RegexRevision.compile("^revision +([^ ]*) *$");
|
2009-02-25 22:42:45 +03:00
|
|
|
this->RegexBranches.compile("^branches: .*$");
|
|
|
|
this->RegexPerson.compile("^date: +([^;]+); +author: +([^;]+);");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
|
2009-02-25 22:42:45 +03:00
|
|
|
private:
|
|
|
|
cmCTestCVS* CVS;
|
|
|
|
std::vector<Revision>& Revisions;
|
|
|
|
cmsys::RegularExpression RegexRevision;
|
|
|
|
cmsys::RegularExpression RegexBranches;
|
|
|
|
cmsys::RegularExpression RegexPerson;
|
2016-05-16 17:34:04 +03:00
|
|
|
enum SectionType
|
|
|
|
{
|
|
|
|
SectionHeader,
|
|
|
|
SectionRevisions,
|
|
|
|
SectionEnd
|
|
|
|
};
|
2009-02-25 22:42:45 +03:00
|
|
|
SectionType Section;
|
|
|
|
Revision Rev;
|
|
|
|
|
2016-06-23 02:02:39 +03:00
|
|
|
bool ProcessLine() CM_OVERRIDE
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->Line == ("======================================="
|
|
|
|
"======================================")) {
|
2009-02-25 22:42:45 +03:00
|
|
|
// This line ends the revision list.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Section == SectionRevisions) {
|
2009-02-25 22:42:45 +03:00
|
|
|
this->FinishRevision();
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Section = SectionEnd;
|
|
|
|
} else if (this->Line == "----------------------------") {
|
2009-02-25 22:42:45 +03:00
|
|
|
// This line divides revisions from the header and each other.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Section == SectionHeader) {
|
2009-02-25 22:42:45 +03:00
|
|
|
this->Section = SectionRevisions;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->Section == SectionRevisions) {
|
2009-02-25 22:42:45 +03:00
|
|
|
this->FinishRevision();
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->Section == SectionRevisions) {
|
|
|
|
if (!this->Rev.Log.empty()) {
|
2009-02-25 22:42:45 +03:00
|
|
|
// Continue the existing log.
|
|
|
|
this->Rev.Log += this->Line;
|
|
|
|
this->Rev.Log += "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->Rev.Rev.empty() &&
|
|
|
|
this->RegexRevision.find(this->Line)) {
|
2009-02-25 22:42:45 +03:00
|
|
|
this->Rev.Rev = this->RegexRevision.match(1);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->Rev.Date.empty() &&
|
|
|
|
this->RegexPerson.find(this->Line)) {
|
2009-02-25 22:42:45 +03:00
|
|
|
this->Rev.Date = this->RegexPerson.match(1);
|
|
|
|
this->Rev.Author = this->RegexPerson.match(2);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!this->RegexBranches.find(this->Line)) {
|
2009-02-25 22:42:45 +03:00
|
|
|
// Start the log.
|
|
|
|
this->Rev.Log += this->Line;
|
|
|
|
this->Rev.Log += "\n";
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return this->Section != SectionEnd;
|
|
|
|
}
|
2009-02-25 22:42:45 +03:00
|
|
|
|
|
|
|
void FinishRevision()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (!this->Rev.Rev.empty()) {
|
2009-02-25 22:42:45 +03:00
|
|
|
// Record this revision.
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2009-02-25 22:42:45 +03:00
|
|
|
this->CVS->Log << "Found revision " << this->Rev.Rev << "\n"
|
|
|
|
<< " author = " << this->Rev.Author << "\n"
|
|
|
|
<< " date = " << this->Rev.Date << "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2009-02-25 22:42:45 +03:00
|
|
|
this->Revisions.push_back(this->Rev);
|
|
|
|
|
|
|
|
// We only need two revisions.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Revisions.size() >= 2) {
|
2009-02-25 22:42:45 +03:00
|
|
|
this->Section = SectionEnd;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Rev = Revision();
|
|
|
|
}
|
2009-02-25 22:42:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
std::string cmCTestCVS::ComputeBranchFlag(std::string const& dir)
|
|
|
|
{
|
|
|
|
// Compute the tag file location for this directory.
|
|
|
|
std::string tagFile = this->SourceDirectory;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!dir.empty()) {
|
2009-02-25 22:42:45 +03:00
|
|
|
tagFile += "/";
|
|
|
|
tagFile += dir;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-25 22:42:45 +03:00
|
|
|
tagFile += "/CVS/Tag";
|
|
|
|
|
|
|
|
// Lookup the branch in the tag file, if any.
|
|
|
|
std::string tagLine;
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream tagStream(tagFile.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (tagStream && cmSystemTools::GetLineFromStream(tagStream, tagLine) &&
|
|
|
|
tagLine.size() > 1 && tagLine[0] == 'T') {
|
2009-02-25 22:42:45 +03:00
|
|
|
// Use the branch specified in the tag file.
|
|
|
|
std::string flag = "-r";
|
|
|
|
flag += tagLine.substr(1);
|
|
|
|
return flag;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2009-02-25 22:42:45 +03:00
|
|
|
// Use the default branch.
|
|
|
|
return "-b";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-25 22:42:45 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCTestCVS::LoadRevisions(std::string const& file, const char* branchFlag,
|
2009-02-25 22:42:45 +03:00
|
|
|
std::vector<Revision>& revisions)
|
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
|
|
|
|
|
|
|
|
// Run "cvs log" to get revisions of this file on this branch.
|
|
|
|
const char* cvs = this->CommandLineTool.c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* cvs_log[] = { cvs, "log", "-N", branchFlag, file.c_str(), 0 };
|
2009-02-25 22:42:45 +03:00
|
|
|
|
|
|
|
LogParser out(this, "log-out> ", revisions);
|
|
|
|
OutputLogger err(this->Log, "log-err> ");
|
|
|
|
this->RunChild(cvs_log, &out, &err);
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCTestCVS::WriteXMLDirectory(cmXMLWriter& xml, std::string const& path,
|
2009-02-25 22:42:45 +03:00
|
|
|
Directory const& dir)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* slash = path.empty() ? "" : "/";
|
2015-05-24 01:33:24 +03:00
|
|
|
xml.StartElement("Directory");
|
|
|
|
xml.Element("Name", path);
|
2009-02-25 22:42:45 +03:00
|
|
|
|
|
|
|
// Lookup the branch checked out in the working tree.
|
|
|
|
std::string branchFlag = this->ComputeBranchFlag(path);
|
|
|
|
|
|
|
|
// Load revisions and write an entry for each file in this directory.
|
|
|
|
std::vector<Revision> revisions;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (Directory::const_iterator fi = dir.begin(); fi != dir.end(); ++fi) {
|
2009-02-25 22:42:45 +03:00
|
|
|
std::string full = path + slash + fi->first;
|
|
|
|
|
|
|
|
// Load two real or unknown revisions.
|
|
|
|
revisions.clear();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (fi->second != PathUpdated) {
|
2009-02-25 22:42:45 +03:00
|
|
|
// For local modifications the current rev is unknown and the
|
|
|
|
// prior rev is the latest from cvs.
|
|
|
|
revisions.push_back(this->Unknown);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-25 22:42:45 +03:00
|
|
|
this->LoadRevisions(full, branchFlag.c_str(), revisions);
|
|
|
|
revisions.resize(2, this->Unknown);
|
|
|
|
|
|
|
|
// Write the entry for this file with these revisions.
|
|
|
|
File f(fi->second, &revisions[0], &revisions[1]);
|
|
|
|
this->WriteXMLEntry(xml, path, fi->first, full, f);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-24 01:33:24 +03:00
|
|
|
xml.EndElement(); // Directory
|
2009-02-25 22:42:45 +03:00
|
|
|
}
|
|
|
|
|
2015-05-24 01:33:24 +03:00
|
|
|
bool cmCTestCVS::WriteXMLUpdates(cmXMLWriter& xml)
|
2009-02-25 22:42:45 +03:00
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
|
|
|
" Gathering version information (one . per updated file):\n"
|
2016-05-16 17:34:04 +03:00
|
|
|
" "
|
|
|
|
<< std::flush);
|
2009-02-25 22:42:45 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, Directory>::const_iterator di =
|
|
|
|
this->Dirs.begin();
|
|
|
|
di != this->Dirs.end(); ++di) {
|
2009-02-25 22:42:45 +03:00
|
|
|
this->WriteXMLDirectory(xml, di->first, di->second);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-02-25 22:42:45 +03:00
|
|
|
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|