~ubuntu-branches/ubuntu/lucid/cmake/lucid

« back to all changes in this revision

Viewing changes to Source/CTest/cmCTestVC.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2009-12-16 11:11:54 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091216111154-6accvv6yq86h2hkc
Tags: 2.8.0-5ubuntu1
* Merge from debian testing (LP: #497349). Remaining changes:
  - Keep the Replaces: on cmake-data to cover the Kubuntu version from
    Jaunty in case someone decides to do an (unsupported) Jaunty->Lucid
    upgrade.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*============================================================================
 
2
  CMake - Cross Platform Makefile Generator
 
3
  Copyright 2000-2009 Kitware, Inc.
 
4
 
 
5
  Distributed under the OSI-approved BSD License (the "License");
 
6
  see accompanying file Copyright.txt for details.
 
7
 
 
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"
 
13
 
 
14
#include "cmCTest.h"
 
15
#include "cmSystemTools.h"
 
16
#include "cmXMLSafe.h"
 
17
 
 
18
#include <cmsys/Process.h>
 
19
 
 
20
//----------------------------------------------------------------------------
 
21
cmCTestVC::cmCTestVC(cmCTest* ct, std::ostream& log): CTest(ct), Log(log)
 
22
{
 
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";
 
29
}
 
30
 
 
31
//----------------------------------------------------------------------------
 
32
cmCTestVC::~cmCTestVC()
 
33
{
 
34
}
 
35
 
 
36
//----------------------------------------------------------------------------
 
37
void cmCTestVC::SetCommandLineTool(std::string const& tool)
 
38
{
 
39
  this->CommandLineTool = tool;
 
40
}
 
41
 
 
42
//----------------------------------------------------------------------------
 
43
void cmCTestVC::SetSourceDirectory(std::string const& dir)
 
44
{
 
45
  this->SourceDirectory = dir;
 
46
}
 
47
 
 
48
//----------------------------------------------------------------------------
 
49
bool cmCTestVC::InitialCheckout(const char* command)
 
50
{
 
51
  cmCTestLog(this->CTest, HANDLER_OUTPUT,
 
52
             "   First perform the initial checkout: " << command << "\n");
 
53
 
 
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()))
 
59
    {
 
60
    cmCTestLog(this->CTest, ERROR_MESSAGE,
 
61
               "Cannot create directory: " << parent << std::endl);
 
62
    return false;
 
63
    }
 
64
 
 
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)
 
70
    {
 
71
    vc_co.push_back(ai->c_str());
 
72
    }
 
73
  vc_co.push_back(0);
 
74
 
 
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";
 
81
  if(!result)
 
82
    {
 
83
    cmCTestLog(this->CTest, ERROR_MESSAGE,
 
84
               "Initial checkout failed!" << std::endl);
 
85
    }
 
86
  return result;
 
87
}
 
88
 
 
89
//----------------------------------------------------------------------------
 
90
bool cmCTestVC::RunChild(char const* const* cmd, OutputParser* out,
 
91
                         OutputParser* err, const char* workDir)
 
92
{
 
93
  this->Log << this->ComputeCommandLine(cmd) << "\n";
 
94
 
 
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);
 
102
  return result == 0;
 
103
}
 
104
 
 
105
//----------------------------------------------------------------------------
 
106
std::string cmCTestVC::ComputeCommandLine(char const* const* cmd)
 
107
{
 
108
  cmOStringStream line;
 
109
  const char* sep = "";
 
110
  for(const char* const* arg = cmd; *arg; ++arg)
 
111
    {
 
112
    line << sep << "\"" << *arg << "\"";
 
113
    sep = " ";
 
114
    }
 
115
  return line.str();
 
116
}
 
117
 
 
118
//----------------------------------------------------------------------------
 
119
bool cmCTestVC::RunUpdateCommand(char const* const* cmd,
 
120
                                 OutputParser* out, OutputParser* err)
 
121
{
 
122
  // Report the command line.
 
123
  this->UpdateCommandLine = this->ComputeCommandLine(cmd);
 
124
  if(this->CTest->GetShowOnly())
 
125
    {
 
126
    this->Log << this->UpdateCommandLine << "\n";
 
127
    return true;
 
128
    }
 
129
 
 
130
  // Run the command.
 
131
  return this->RunChild(cmd, out, err);
 
132
}
 
133
 
 
134
//----------------------------------------------------------------------------
 
135
std::string cmCTestVC::GetNightlyTime()
 
136
{
 
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",
 
143
          t->tm_year + 1900,
 
144
          t->tm_mon + 1,
 
145
          t->tm_mday,
 
146
          t->tm_hour,
 
147
          t->tm_min,
 
148
          t->tm_sec);
 
149
  return std::string(current_time);
 
150
}
 
151
 
 
152
//----------------------------------------------------------------------------
 
153
void cmCTestVC::Cleanup()
 
154
{
 
155
  this->Log << "--- Begin Cleanup ---\n";
 
156
  this->CleanupImpl();
 
157
  this->Log << "--- End Cleanup ---\n";
 
158
}
 
159
 
 
160
//----------------------------------------------------------------------------
 
161
void cmCTestVC::CleanupImpl()
 
162
{
 
163
  // We do no cleanup by default.
 
164
}
 
165
 
 
166
//----------------------------------------------------------------------------
 
167
bool cmCTestVC::Update()
 
168
{
 
169
  this->NoteOldRevision();
 
170
  this->Log << "--- Begin Update ---\n";
 
171
  bool result = this->UpdateImpl();
 
172
  this->Log << "--- End Update ---\n";
 
173
  this->NoteNewRevision();
 
174
  return result;
 
175
}
 
176
 
 
177
//----------------------------------------------------------------------------
 
178
void cmCTestVC::NoteOldRevision()
 
179
{
 
180
  // We do nothing by default.
 
181
}
 
182
 
 
183
//----------------------------------------------------------------------------
 
184
void cmCTestVC::NoteNewRevision()
 
185
{
 
186
  // We do nothing by default.
 
187
}
 
188
 
 
189
//----------------------------------------------------------------------------
 
190
bool cmCTestVC::UpdateImpl()
 
191
{
 
192
  cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
 
193
             "* Unknown VCS tool, not updating!" << std::endl);
 
194
  return true;
 
195
}
 
196
 
 
197
//----------------------------------------------------------------------------
 
198
bool cmCTestVC::WriteXML(std::ostream& xml)
 
199
{
 
200
  this->Log << "--- Begin Revisions ---\n";
 
201
  bool result = this->WriteXMLUpdates(xml);
 
202
  this->Log << "--- End Revisions ---\n";
 
203
  return result;
 
204
}
 
205
 
 
206
//----------------------------------------------------------------------------
 
207
bool cmCTestVC::WriteXMLUpdates(std::ostream&)
 
208
{
 
209
  cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
 
210
             "* CTest cannot extract updates for this VCS tool.\n");
 
211
  return true;
 
212
}
 
213
 
 
214
//----------------------------------------------------------------------------
 
215
void cmCTestVC::WriteXMLEntry(std::ostream& xml,
 
216
                              std::string const& path,
 
217
                              std::string const& name,
 
218
                              std::string const& full,
 
219
                              File const& f)
 
220
{
 
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];
 
235
}