1
/*============================================================================
2
CMake - Cross Platform Makefile Generator
3
Copyright 2000-2009 Kitware, Inc.
5
Distributed under the OSI-approved BSD License (the "License");
6
see accompanying file Copyright.txt for details.
8
This software is distributed WITHOUT ANY WARRANTY; without even the
9
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
See the License for more information.
11
============================================================================*/
12
#include "cmCTestVC.h"
15
#include "cmSystemTools.h"
16
#include "cmXMLSafe.h"
18
#include <cmsys/Process.h>
20
//----------------------------------------------------------------------------
21
cmCTestVC::cmCTestVC(cmCTest* ct, std::ostream& log): CTest(ct), Log(log)
23
this->PathCount[PathUpdated] = 0;
24
this->PathCount[PathModified] = 0;
25
this->PathCount[PathConflicting] = 0;
26
this->Unknown.Date = "Unknown";
27
this->Unknown.Author = "Unknown";
28
this->Unknown.Rev = "Unknown";
31
//----------------------------------------------------------------------------
32
cmCTestVC::~cmCTestVC()
36
//----------------------------------------------------------------------------
37
void cmCTestVC::SetCommandLineTool(std::string const& tool)
39
this->CommandLineTool = tool;
42
//----------------------------------------------------------------------------
43
void cmCTestVC::SetSourceDirectory(std::string const& dir)
45
this->SourceDirectory = dir;
48
//----------------------------------------------------------------------------
49
bool cmCTestVC::InitialCheckout(const char* command)
51
cmCTestLog(this->CTest, HANDLER_OUTPUT,
52
" First perform the initial checkout: " << command << "\n");
54
// Make the parent directory in which to perform the checkout.
55
std::string parent = cmSystemTools::GetFilenamePath(this->SourceDirectory);
56
cmCTestLog(this->CTest, HANDLER_OUTPUT,
57
" Perform checkout in directory: " << parent << "\n");
58
if(!cmSystemTools::MakeDirectory(parent.c_str()))
60
cmCTestLog(this->CTest, ERROR_MESSAGE,
61
"Cannot create directory: " << parent << std::endl);
65
// Construct the initial checkout command line.
66
std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
67
std::vector<char const*> vc_co;
68
for(std::vector<cmStdString>::const_iterator ai = args.begin();
69
ai != args.end(); ++ai)
71
vc_co.push_back(ai->c_str());
75
// Run the initial checkout command and log its output.
76
this->Log << "--- Begin Initial Checkout ---\n";
77
OutputLogger out(this->Log, "co-out> ");
78
OutputLogger err(this->Log, "co-err> ");
79
bool result = this->RunChild(&vc_co[0], &out, &err, parent.c_str());
80
this->Log << "--- End Initial Checkout ---\n";
83
cmCTestLog(this->CTest, ERROR_MESSAGE,
84
"Initial checkout failed!" << std::endl);
89
//----------------------------------------------------------------------------
90
bool cmCTestVC::RunChild(char const* const* cmd, OutputParser* out,
91
OutputParser* err, const char* workDir)
93
this->Log << this->ComputeCommandLine(cmd) << "\n";
95
cmsysProcess* cp = cmsysProcess_New();
96
cmsysProcess_SetCommand(cp, cmd);
97
workDir = workDir? workDir : this->SourceDirectory.c_str();
98
cmsysProcess_SetWorkingDirectory(cp, workDir);
99
this->RunProcess(cp, out, err);
100
int result = cmsysProcess_GetExitValue(cp);
101
cmsysProcess_Delete(cp);
105
//----------------------------------------------------------------------------
106
std::string cmCTestVC::ComputeCommandLine(char const* const* cmd)
108
cmOStringStream line;
109
const char* sep = "";
110
for(const char* const* arg = cmd; *arg; ++arg)
112
line << sep << "\"" << *arg << "\"";
118
//----------------------------------------------------------------------------
119
bool cmCTestVC::RunUpdateCommand(char const* const* cmd,
120
OutputParser* out, OutputParser* err)
122
// Report the command line.
123
this->UpdateCommandLine = this->ComputeCommandLine(cmd);
124
if(this->CTest->GetShowOnly())
126
this->Log << this->UpdateCommandLine << "\n";
131
return this->RunChild(cmd, out, err);
134
//----------------------------------------------------------------------------
135
std::string cmCTestVC::GetNightlyTime()
137
// Get the nightly start time corresponding to the current dau.
138
struct tm* t = this->CTest->GetNightlyTime(
139
this->CTest->GetCTestConfiguration("NightlyStartTime"),
140
this->CTest->GetTomorrowTag());
141
char current_time[1024];
142
sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d",
149
return std::string(current_time);
152
//----------------------------------------------------------------------------
153
void cmCTestVC::Cleanup()
155
this->Log << "--- Begin Cleanup ---\n";
157
this->Log << "--- End Cleanup ---\n";
160
//----------------------------------------------------------------------------
161
void cmCTestVC::CleanupImpl()
163
// We do no cleanup by default.
166
//----------------------------------------------------------------------------
167
bool cmCTestVC::Update()
169
this->NoteOldRevision();
170
this->Log << "--- Begin Update ---\n";
171
bool result = this->UpdateImpl();
172
this->Log << "--- End Update ---\n";
173
this->NoteNewRevision();
177
//----------------------------------------------------------------------------
178
void cmCTestVC::NoteOldRevision()
180
// We do nothing by default.
183
//----------------------------------------------------------------------------
184
void cmCTestVC::NoteNewRevision()
186
// We do nothing by default.
189
//----------------------------------------------------------------------------
190
bool cmCTestVC::UpdateImpl()
192
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
193
"* Unknown VCS tool, not updating!" << std::endl);
197
//----------------------------------------------------------------------------
198
bool cmCTestVC::WriteXML(std::ostream& xml)
200
this->Log << "--- Begin Revisions ---\n";
201
bool result = this->WriteXMLUpdates(xml);
202
this->Log << "--- End Revisions ---\n";
206
//----------------------------------------------------------------------------
207
bool cmCTestVC::WriteXMLUpdates(std::ostream&)
209
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
210
"* CTest cannot extract updates for this VCS tool.\n");
214
//----------------------------------------------------------------------------
215
void cmCTestVC::WriteXMLEntry(std::ostream& xml,
216
std::string const& path,
217
std::string const& name,
218
std::string const& full,
221
static const char* desc[3] = { "Updated", "Modified", "Conflicting"};
222
Revision const& rev = f.Rev? *f.Rev : this->Unknown;
223
std::string prior = f.PriorRev? f.PriorRev->Rev : std::string("Unknown");
224
xml << "\t\t<" << desc[f.Status] << ">\n"
225
<< "\t\t\t<File>" << cmXMLSafe(name) << "</File>\n"
226
<< "\t\t\t<Directory>" << cmXMLSafe(path) << "</Directory>\n"
227
<< "\t\t\t<FullName>" << cmXMLSafe(full) << "</FullName>\n"
228
<< "\t\t\t<CheckinDate>" << cmXMLSafe(rev.Date) << "</CheckinDate>\n"
229
<< "\t\t\t<Author>" << cmXMLSafe(rev.Author) << "</Author>\n"
230
<< "\t\t\t<Log>" << cmXMLSafe(rev.Log) << "</Log>\n"
231
<< "\t\t\t<Revision>" << cmXMLSafe(rev.Rev) << "</Revision>\n"
232
<< "\t\t\t<PriorRevision>" << cmXMLSafe(prior) << "</PriorRevision>\n"
233
<< "\t\t</" << desc[f.Status] << ">\n";
234
++this->PathCount[f.Status];