2013-10-23 02:11:22 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2013 Kitware, Inc.
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
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.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmCTestP4.h"
|
|
|
|
|
|
|
|
#include "cmCTest.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
|
|
|
#include <cmsys/Process.h>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
#include <ctype.h>
|
2016-05-02 22:05:39 +03:00
|
|
|
#include <sys/types.h>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <time.h>
|
2013-10-23 02:11:22 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCTestP4::cmCTestP4(cmCTest* ct, std::ostream& log)
|
|
|
|
: cmCTestGlobalVC(ct, log)
|
2013-10-23 02:11:22 +04:00
|
|
|
{
|
|
|
|
this->PriorRev = this->Unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCTestP4::~cmCTestP4()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
class cmCTestP4::IdentifyParser : public cmCTestVC::LineParser
|
2013-10-23 02:11:22 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-05-16 17:34:04 +03:00
|
|
|
IdentifyParser(cmCTestP4* p4, const char* prefix, std::string& rev)
|
|
|
|
: Rev(rev)
|
|
|
|
{
|
2013-10-23 02:11:22 +04:00
|
|
|
this->SetLog(&p4->Log, prefix);
|
|
|
|
this->RegexIdentify.compile("^Change ([0-9]+) on");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
|
2013-10-23 02:11:22 +04:00
|
|
|
private:
|
|
|
|
std::string& Rev;
|
|
|
|
cmsys::RegularExpression RegexIdentify;
|
|
|
|
|
|
|
|
bool ProcessLine()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->RegexIdentify.find(this->Line)) {
|
2013-10-23 02:11:22 +04:00
|
|
|
this->Rev = this->RegexIdentify.match(1);
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
};
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
class cmCTestP4::ChangesParser : public cmCTestVC::LineParser
|
2013-10-23 02:11:22 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-05-16 17:34:04 +03:00
|
|
|
ChangesParser(cmCTestP4* p4, const char* prefix)
|
|
|
|
: P4(p4)
|
|
|
|
{
|
2013-10-23 02:11:22 +04:00
|
|
|
this->SetLog(&P4->Log, prefix);
|
|
|
|
this->RegexIdentify.compile("^Change ([0-9]+) on");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
|
2013-10-23 02:11:22 +04:00
|
|
|
private:
|
|
|
|
cmsys::RegularExpression RegexIdentify;
|
|
|
|
cmCTestP4* P4;
|
|
|
|
|
|
|
|
bool ProcessLine()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->RegexIdentify.find(this->Line)) {
|
2013-10-23 02:11:22 +04:00
|
|
|
P4->ChangeLists.push_back(this->RegexIdentify.match(1));
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
};
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
class cmCTestP4::UserParser : public cmCTestVC::LineParser
|
2013-10-23 02:11:22 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-05-16 17:34:04 +03:00
|
|
|
UserParser(cmCTestP4* p4, const char* prefix)
|
|
|
|
: P4(p4)
|
|
|
|
{
|
2013-10-23 02:11:22 +04:00
|
|
|
this->SetLog(&P4->Log, prefix);
|
|
|
|
this->RegexUser.compile("^(.+) <(.*)> \\((.*)\\) accessed (.*)$");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
|
2013-10-23 02:11:22 +04:00
|
|
|
private:
|
|
|
|
cmsys::RegularExpression RegexUser;
|
|
|
|
cmCTestP4* P4;
|
|
|
|
|
|
|
|
bool ProcessLine()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->RegexUser.find(this->Line)) {
|
2013-10-23 02:11:22 +04:00
|
|
|
User NewUser;
|
|
|
|
|
|
|
|
NewUser.UserName = this->RegexUser.match(1);
|
|
|
|
NewUser.EMail = this->RegexUser.match(2);
|
|
|
|
NewUser.Name = this->RegexUser.match(3);
|
|
|
|
NewUser.AccessTime = this->RegexUser.match(4);
|
|
|
|
P4->Users[this->RegexUser.match(1)] = NewUser;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Diff format:
|
|
|
|
==== //depot/file#rev - /absolute/path/to/file ====
|
|
|
|
(diff data)
|
|
|
|
==== //depot/file2#rev - /absolute/path/to/file2 ====
|
|
|
|
(diff data)
|
|
|
|
==== //depot/file3#rev - /absolute/path/to/file3 ====
|
|
|
|
==== //depot/file4#rev - /absolute/path/to/file4 ====
|
|
|
|
(diff data)
|
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
class cmCTestP4::DiffParser : public cmCTestVC::LineParser
|
2013-10-23 02:11:22 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DiffParser(cmCTestP4* p4, const char* prefix)
|
2016-05-16 17:34:04 +03:00
|
|
|
: P4(p4)
|
|
|
|
, AlreadyNotified(false)
|
|
|
|
{
|
2013-10-23 02:11:22 +04:00
|
|
|
this->SetLog(&P4->Log, prefix);
|
|
|
|
this->RegexDiff.compile("^==== (.*)#[0-9]+ - (.*)");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
|
2013-10-23 02:11:22 +04:00
|
|
|
private:
|
|
|
|
cmCTestP4* P4;
|
|
|
|
bool AlreadyNotified;
|
|
|
|
std::string CurrentPath;
|
|
|
|
cmsys::RegularExpression RegexDiff;
|
|
|
|
|
|
|
|
bool ProcessLine()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (!this->Line.empty() && this->Line[0] == '=' &&
|
|
|
|
this->RegexDiff.find(this->Line)) {
|
|
|
|
CurrentPath = this->RegexDiff.match(1);
|
|
|
|
AlreadyNotified = false;
|
|
|
|
} else {
|
|
|
|
if (!AlreadyNotified) {
|
2013-10-23 02:11:22 +04:00
|
|
|
P4->DoModification(PathModified, CurrentPath);
|
|
|
|
AlreadyNotified = true;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
cmCTestP4::User cmCTestP4::GetUserData(const std::string& username)
|
|
|
|
{
|
|
|
|
std::map<std::string, cmCTestP4::User>::const_iterator it =
|
2016-05-16 17:34:04 +03:00
|
|
|
Users.find(username);
|
2013-10-23 02:11:22 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (it == Users.end()) {
|
2013-10-23 02:11:22 +04:00
|
|
|
std::vector<char const*> p4_users;
|
|
|
|
SetP4Options(p4_users);
|
|
|
|
p4_users.push_back("users");
|
|
|
|
p4_users.push_back("-m");
|
|
|
|
p4_users.push_back("1");
|
|
|
|
p4_users.push_back(username.c_str());
|
|
|
|
p4_users.push_back(0);
|
|
|
|
|
|
|
|
UserParser out(this, "users-out> ");
|
|
|
|
OutputLogger err(this->Log, "users-err> ");
|
|
|
|
RunChild(&p4_users[0], &out, &err);
|
|
|
|
|
|
|
|
// The user should now be added to the map. Search again.
|
|
|
|
it = Users.find(username);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (it == Users.end()) {
|
2013-10-23 02:11:22 +04:00
|
|
|
return cmCTestP4::User();
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Commit format:
|
|
|
|
|
|
|
|
Change 1111111 by user@client on 2013/09/26 11:50:36
|
|
|
|
|
|
|
|
text
|
|
|
|
text
|
|
|
|
|
|
|
|
Affected files ...
|
|
|
|
|
|
|
|
... //path/to/file#rev edit
|
|
|
|
... //path/to/file#rev add
|
|
|
|
... //path/to/file#rev delete
|
|
|
|
... //path/to/file#rev integrate
|
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
class cmCTestP4::DescribeParser : public cmCTestVC::LineParser
|
2013-10-23 02:11:22 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-05-16 17:34:04 +03:00
|
|
|
DescribeParser(cmCTestP4* p4, const char* prefix)
|
|
|
|
: LineParser('\n', false)
|
|
|
|
, P4(p4)
|
|
|
|
, Section(SectionHeader)
|
|
|
|
{
|
2013-10-23 02:11:22 +04:00
|
|
|
this->SetLog(&P4->Log, prefix);
|
|
|
|
this->RegexHeader.compile("^Change ([0-9]+) by (.+)@(.+) on (.*)$");
|
|
|
|
this->RegexDiff.compile("^\\.\\.\\. (.*)#[0-9]+ ([^ ]+)$");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
|
2013-10-23 02:11:22 +04:00
|
|
|
private:
|
|
|
|
cmsys::RegularExpression RegexHeader;
|
|
|
|
cmsys::RegularExpression RegexDiff;
|
|
|
|
cmCTestP4* P4;
|
|
|
|
|
|
|
|
typedef cmCTestP4::Revision Revision;
|
|
|
|
typedef cmCTestP4::Change Change;
|
|
|
|
std::vector<Change> Changes;
|
2016-05-16 17:34:04 +03:00
|
|
|
enum SectionType
|
|
|
|
{
|
|
|
|
SectionHeader,
|
|
|
|
SectionBody,
|
|
|
|
SectionDiffHeader,
|
|
|
|
SectionDiff,
|
|
|
|
SectionCount
|
|
|
|
};
|
2013-10-23 02:11:22 +04:00
|
|
|
SectionType Section;
|
|
|
|
Revision Rev;
|
|
|
|
|
|
|
|
virtual bool ProcessLine()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->Line.empty()) {
|
2013-10-23 02:11:22 +04:00
|
|
|
this->NextSection();
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
switch (this->Section) {
|
|
|
|
case SectionHeader:
|
|
|
|
this->DoHeaderLine();
|
|
|
|
break;
|
|
|
|
case SectionBody:
|
|
|
|
this->DoBodyLine();
|
|
|
|
break;
|
|
|
|
case SectionDiffHeader:
|
|
|
|
break; // nothing to do
|
|
|
|
case SectionDiff:
|
|
|
|
this->DoDiffLine();
|
|
|
|
break;
|
|
|
|
case SectionCount:
|
|
|
|
break; // never happens
|
2013-10-23 02:11:22 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
void NextSection()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->Section == SectionDiff) {
|
2013-10-23 02:11:22 +04:00
|
|
|
this->P4->DoRevision(this->Rev, this->Changes);
|
|
|
|
this->Rev = Revision();
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Section = SectionType((this->Section + 1) % SectionCount);
|
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
void DoHeaderLine()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->RegexHeader.find(this->Line)) {
|
2013-10-23 02:11:22 +04:00
|
|
|
this->Rev.Rev = this->RegexHeader.match(1);
|
|
|
|
this->Rev.Date = this->RegexHeader.match(4);
|
|
|
|
|
|
|
|
cmCTestP4::User user = P4->GetUserData(this->RegexHeader.match(2));
|
|
|
|
this->Rev.Author = user.Name;
|
|
|
|
this->Rev.EMail = user.EMail;
|
|
|
|
|
|
|
|
this->Rev.Committer = this->Rev.Author;
|
|
|
|
this->Rev.CommitterEMail = this->Rev.EMail;
|
|
|
|
this->Rev.CommitDate = this->Rev.Date;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
void DoBodyLine()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->Line[0] == '\t') {
|
2013-10-23 02:11:22 +04:00
|
|
|
this->Rev.Log += this->Line.substr(1);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Rev.Log += "\n";
|
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
void DoDiffLine()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->RegexDiff.find(this->Line)) {
|
|
|
|
Change change;
|
|
|
|
std::string Path = this->RegexDiff.match(1);
|
|
|
|
if (Path.length() > 2 && Path[0] == '/' && Path[1] == '/') {
|
|
|
|
size_t found = Path.find('/', 2);
|
|
|
|
if (found != std::string::npos) {
|
|
|
|
Path = Path.substr(found + 1);
|
2013-10-23 02:11:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
change.Path = Path;
|
|
|
|
std::string action = this->RegexDiff.match(2);
|
2013-10-23 02:11:22 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (action == "add") {
|
|
|
|
change.Action = 'A';
|
|
|
|
} else if (action == "delete") {
|
|
|
|
change.Action = 'D';
|
|
|
|
} else if (action == "edit" || action == "integrate") {
|
|
|
|
change.Action = 'M';
|
2013-10-23 02:11:22 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
Changes.push_back(change);
|
2013-10-23 02:11:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCTestP4::SetP4Options(std::vector<char const*>& CommandOptions)
|
2013-10-23 02:11:22 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (P4Options.empty()) {
|
2013-10-23 02:11:22 +04:00
|
|
|
const char* p4 = this->CommandLineTool.c_str();
|
|
|
|
P4Options.push_back(p4);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// The CTEST_P4_CLIENT variable sets the P4 client used when issuing
|
|
|
|
// Perforce commands, if it's different from the default one.
|
2013-10-23 02:11:22 +04:00
|
|
|
std::string client = this->CTest->GetCTestConfiguration("P4Client");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!client.empty()) {
|
2013-10-23 02:11:22 +04:00
|
|
|
P4Options.push_back("-c");
|
|
|
|
P4Options.push_back(client);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// Set the message language to be English, in case the P4 admin
|
|
|
|
// has localized them
|
2013-10-23 02:11:22 +04:00
|
|
|
P4Options.push_back("-L");
|
|
|
|
P4Options.push_back("en");
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// The CTEST_P4_OPTIONS variable adds additional Perforce command line
|
|
|
|
// options before the main command
|
2013-10-23 02:11:22 +04:00
|
|
|
std::string opts = this->CTest->GetCTestConfiguration("P4Options");
|
2014-02-10 09:21:34 +04:00
|
|
|
std::vector<std::string> args =
|
2016-05-16 17:34:04 +03:00
|
|
|
cmSystemTools::ParseArguments(opts.c_str());
|
2013-10-23 02:11:22 +04:00
|
|
|
|
2014-11-22 13:00:45 +03:00
|
|
|
P4Options.insert(P4Options.end(), args.begin(), args.end());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
CommandOptions.clear();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator i = P4Options.begin();
|
|
|
|
i != P4Options.end(); ++i) {
|
2013-10-23 02:11:22 +04:00
|
|
|
CommandOptions.push_back(i->c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCTestP4::GetWorkingRevision()
|
|
|
|
{
|
|
|
|
std::vector<char const*> p4_identify;
|
|
|
|
SetP4Options(p4_identify);
|
|
|
|
|
|
|
|
p4_identify.push_back("changes");
|
|
|
|
p4_identify.push_back("-m");
|
|
|
|
p4_identify.push_back("1");
|
|
|
|
p4_identify.push_back("-t");
|
|
|
|
|
|
|
|
std::string source = this->SourceDirectory + "/...#have";
|
|
|
|
p4_identify.push_back(source.c_str());
|
|
|
|
p4_identify.push_back(0);
|
|
|
|
|
|
|
|
std::string rev;
|
2014-01-22 05:02:25 +04:00
|
|
|
IdentifyParser out(this, "p4_changes-out> ", rev);
|
|
|
|
OutputLogger err(this->Log, "p4_changes-err> ");
|
2013-10-23 02:11:22 +04:00
|
|
|
|
2014-01-22 05:02:25 +04:00
|
|
|
bool result = RunChild(&p4_identify[0], &out, &err);
|
|
|
|
|
|
|
|
// If there was a problem contacting the server return "<unknown>"
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!result) {
|
2014-01-22 05:02:25 +04:00
|
|
|
return "<unknown>";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (rev.empty()) {
|
2013-10-23 02:11:22 +04:00
|
|
|
return "0";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-10-23 02:11:22 +04:00
|
|
|
return rev;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestP4::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");
|
2013-10-23 02:11:22 +04:00
|
|
|
this->PriorRev.Rev = this->OldRevision;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestP4::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");
|
2013-10-23 02:11:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestP4::LoadRevisions()
|
|
|
|
{
|
|
|
|
std::vector<char const*> p4_changes;
|
|
|
|
SetP4Options(p4_changes);
|
|
|
|
|
|
|
|
// Use 'p4 changes ...@old,new' to get a list of changelists
|
|
|
|
std::string range = this->SourceDirectory + "/...";
|
|
|
|
|
2014-01-22 05:02:25 +04:00
|
|
|
// If any revision is unknown it means we couldn't contact the server.
|
|
|
|
// Do not process updates
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->OldRevision == "<unknown>" || this->NewRevision == "<unknown>") {
|
2014-01-22 05:02:25 +04:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " At least one of the revisions "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "is unknown. No repository changes will be reported.\n");
|
2014-01-22 05:02:25 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
range.append("@")
|
|
|
|
.append(this->OldRevision)
|
|
|
|
.append(",")
|
|
|
|
.append(this->NewRevision);
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
p4_changes.push_back("changes");
|
|
|
|
p4_changes.push_back(range.c_str());
|
|
|
|
p4_changes.push_back(0);
|
|
|
|
|
2014-01-22 05:02:25 +04:00
|
|
|
ChangesParser out(this, "p4_changes-out> ");
|
|
|
|
OutputLogger err(this->Log, "p4_changes-err> ");
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
ChangeLists.clear();
|
|
|
|
this->RunChild(&p4_changes[0], &out, &err);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ChangeLists.empty())
|
|
|
|
return;
|
2013-10-23 02:11:22 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// p4 describe -s ...@1111111,2222222
|
2013-10-23 02:11:22 +04:00
|
|
|
std::vector<char const*> p4_describe;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::reverse_iterator i = ChangeLists.rbegin();
|
|
|
|
i != ChangeLists.rend(); ++i) {
|
2013-10-23 02:11:22 +04:00
|
|
|
SetP4Options(p4_describe);
|
|
|
|
p4_describe.push_back("describe");
|
|
|
|
p4_describe.push_back("-s");
|
|
|
|
p4_describe.push_back(i->c_str());
|
|
|
|
p4_describe.push_back(0);
|
|
|
|
|
2014-01-22 05:02:25 +04:00
|
|
|
DescribeParser outDescribe(this, "p4_describe-out> ");
|
|
|
|
OutputLogger errDescribe(this->Log, "p4_describe-err> ");
|
2013-10-23 02:11:22 +04:00
|
|
|
this->RunChild(&p4_describe[0], &outDescribe, &errDescribe);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestP4::LoadModifications()
|
|
|
|
{
|
|
|
|
std::vector<char const*> p4_diff;
|
|
|
|
SetP4Options(p4_diff);
|
|
|
|
|
|
|
|
p4_diff.push_back("diff");
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// Ideally we would use -Od but not all clients support it
|
2013-10-23 02:11:22 +04:00
|
|
|
p4_diff.push_back("-dn");
|
|
|
|
std::string source = this->SourceDirectory + "/...";
|
|
|
|
p4_diff.push_back(source.c_str());
|
|
|
|
p4_diff.push_back(0);
|
|
|
|
|
2014-01-22 05:02:25 +04:00
|
|
|
DiffParser out(this, "p4_diff-out> ");
|
|
|
|
OutputLogger err(this->Log, "p4_diff-err> ");
|
2013-10-23 02:11:22 +04:00
|
|
|
this->RunChild(&p4_diff[0], &out, &err);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestP4::UpdateCustom(const std::string& custom)
|
|
|
|
{
|
|
|
|
std::vector<std::string> p4_custom_command;
|
|
|
|
cmSystemTools::ExpandListArgument(custom, p4_custom_command, true);
|
|
|
|
|
|
|
|
std::vector<char const*> p4_custom;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator i = p4_custom_command.begin();
|
|
|
|
i != p4_custom_command.end(); ++i) {
|
2013-10-23 02:11:22 +04:00
|
|
|
p4_custom.push_back(i->c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
p4_custom.push_back(0);
|
|
|
|
|
2014-01-22 05:02:25 +04:00
|
|
|
OutputLogger custom_out(this->Log, "p4_customsync-out> ");
|
|
|
|
OutputLogger custom_err(this->Log, "p4_customsync-err> ");
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
return this->RunUpdateCommand(&p4_custom[0], &custom_out, &custom_err);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestP4::UpdateImpl()
|
|
|
|
{
|
|
|
|
std::string custom = this->CTest->GetCTestConfiguration("P4UpdateCustom");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!custom.empty()) {
|
2013-10-23 02:11:22 +04:00
|
|
|
return this->UpdateCustom(custom);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
|
2014-01-22 05:02:25 +04:00
|
|
|
// If we couldn't get a revision number before updating, abort.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->OldRevision == "<unknown>") {
|
2014-01-22 05:02:25 +04:00
|
|
|
this->UpdateCommandLine = "Unknown current revision";
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, " Unknown current revision\n");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-01-22 05:02:25 +04:00
|
|
|
|
2013-10-23 02:11:22 +04:00
|
|
|
std::vector<char const*> p4_sync;
|
|
|
|
SetP4Options(p4_sync);
|
|
|
|
|
|
|
|
p4_sync.push_back("sync");
|
|
|
|
|
|
|
|
// Get user-specified update options.
|
|
|
|
std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (opts.empty()) {
|
2013-10-23 02:11:22 +04:00
|
|
|
opts = this->CTest->GetCTestConfiguration("P4UpdateOptions");
|
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) {
|
2013-10-23 02:11:22 +04:00
|
|
|
p4_sync.push_back(ai->c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
std::string source = this->SourceDirectory + "/...";
|
|
|
|
|
|
|
|
// Specify the start time for nightly testing.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CTest->GetTestModel() == cmCTest::NIGHTLY) {
|
2013-10-23 02:11:22 +04:00
|
|
|
std::string date = this->GetNightlyTime();
|
2016-05-16 17:34:04 +03:00
|
|
|
// CTest reports the date as YYYY-MM-DD, Perforce needs it as YYYY/MM/DD
|
2013-10-23 02:11:22 +04:00
|
|
|
std::replace(date.begin(), date.end(), '-', '/');
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// Revision specification: /...@"YYYY/MM/DD HH:MM:SS"
|
2013-10-23 02:11:22 +04:00
|
|
|
source.append("@\"").append(date).append("\"");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
p4_sync.push_back(source.c_str());
|
|
|
|
p4_sync.push_back(0);
|
|
|
|
|
2014-01-22 05:02:25 +04:00
|
|
|
OutputLogger out(this->Log, "p4_sync-out> ");
|
|
|
|
OutputLogger err(this->Log, "p4_sync-err> ");
|
2013-10-23 02:11:22 +04:00
|
|
|
|
|
|
|
return this->RunUpdateCommand(&p4_sync[0], &out, &err);
|
|
|
|
}
|