cmCTestUpdateHandler.cxx 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestUpdateHandler.h"
  14. #include "cmCTest.h"
  15. #include "cmake.h"
  16. #include "cmMakefile.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmGlobalGenerator.h"
  19. #include "cmVersion.h"
  20. #include "cmGeneratedFileStream.h"
  21. #include "cmXMLParser.h"
  22. //#include <cmsys/RegularExpression.hxx>
  23. #include <cmsys/Process.h>
  24. // used for sleep
  25. #ifdef _WIN32
  26. #include "windows.h"
  27. #endif
  28. #include <stdlib.h>
  29. #include <math.h>
  30. #include <float.h>
  31. //----------------------------------------------------------------------
  32. static const char* cmCTestUpdateHandlerUpdateStrings[] =
  33. {
  34. "Unknown",
  35. "CVS",
  36. "SVN"
  37. };
  38. static const char* cmCTestUpdateHandlerUpdateToString(int type)
  39. {
  40. if ( type < cmCTestUpdateHandler::e_UNKNOWN ||
  41. type >= cmCTestUpdateHandler::e_LAST )
  42. {
  43. return cmCTestUpdateHandlerUpdateStrings[cmCTestUpdateHandler::e_UNKNOWN];
  44. }
  45. return cmCTestUpdateHandlerUpdateStrings[type];
  46. }
  47. //----------------------------------------------------------------------
  48. //**********************************************************************
  49. class cmCTestUpdateHandlerSVNXMLParser : public cmXMLParser
  50. {
  51. public:
  52. struct t_CommitLog
  53. {
  54. int Revision;
  55. std::string Author;
  56. std::string Date;
  57. std::string Message;
  58. };
  59. cmCTestUpdateHandlerSVNXMLParser(cmCTestUpdateHandler* up)
  60. : cmXMLParser(), UpdateHandler(up), MinRevision(-1), MaxRevision(-1)
  61. {
  62. }
  63. int Parse(const char* str)
  64. {
  65. this->MinRevision = -1;
  66. this->MaxRevision = -1;
  67. int res = this->cmXMLParser::Parse(str);
  68. if ( this->MinRevision == -1 || this->MaxRevision == -1 )
  69. {
  70. return 0;
  71. }
  72. return res;
  73. }
  74. typedef std::vector<t_CommitLog> t_VectorOfCommits;
  75. t_VectorOfCommits* GetCommits() { return &this->Commits; }
  76. int GetMinRevision() { return this->MinRevision; }
  77. int GetMaxRevision() { return this->MaxRevision; }
  78. protected:
  79. void StartElement(const char* name, const char** atts)
  80. {
  81. if ( strcmp(name, "logentry") == 0 )
  82. {
  83. this->CommitLog = t_CommitLog();
  84. const char* rev = this->FindAttribute(atts, "revision");
  85. if ( rev)
  86. {
  87. this->CommitLog.Revision = atoi(rev);
  88. if ( this->MinRevision < 0 ||
  89. this->MinRevision > this->CommitLog.Revision )
  90. {
  91. this->MinRevision = this->CommitLog.Revision;
  92. }
  93. if ( this->MaxRevision < 0 ||
  94. this->MaxRevision < this->CommitLog.Revision )
  95. {
  96. this->MaxRevision = this->CommitLog.Revision;
  97. }
  98. }
  99. }
  100. this->CharacterData.erase(
  101. this->CharacterData.begin(), this->CharacterData.end());
  102. }
  103. void EndElement(const char* name)
  104. {
  105. if ( strcmp(name, "logentry") == 0 )
  106. {
  107. cmCTestLog(this->UpdateHandler->GetCTestInstance(),
  108. HANDLER_VERBOSE_OUTPUT,
  109. "\tRevision: " << this->CommitLog.Revision<< std::endl
  110. << "\tAuthor: " << this->CommitLog.Author.c_str() << std::endl
  111. << "\tDate: " << this->CommitLog.Date.c_str() << std::endl
  112. << "\tMessage: " << this->CommitLog.Message.c_str() << std::endl);
  113. this->Commits.push_back(this->CommitLog);
  114. }
  115. else if ( strcmp(name, "author") == 0 )
  116. {
  117. this->CommitLog.Author.assign(&(*(this->CharacterData.begin())),
  118. this->CharacterData.size());
  119. }
  120. else if ( strcmp(name, "date") == 0 )
  121. {
  122. this->CommitLog.Date.assign(&(*(this->CharacterData.begin())),
  123. this->CharacterData.size());
  124. }
  125. else if ( strcmp(name, "msg") == 0 )
  126. {
  127. this->CommitLog.Message.assign(&(*(this->CharacterData.begin())),
  128. this->CharacterData.size());
  129. }
  130. this->CharacterData.erase(this->CharacterData.begin(),
  131. this->CharacterData.end());
  132. }
  133. void CharacterDataHandler(const char* data, int length)
  134. {
  135. this->CharacterData.insert(this->CharacterData.end(), data, data+length);
  136. }
  137. const char* FindAttribute( const char** atts, const char* attribute )
  138. {
  139. if ( !atts || !attribute )
  140. {
  141. return 0;
  142. }
  143. const char **atr = atts;
  144. while ( *atr && **atr && **(atr+1) )
  145. {
  146. if ( strcmp(*atr, attribute) == 0 )
  147. {
  148. return *(atr+1);
  149. }
  150. atr+=2;
  151. }
  152. return 0;
  153. }
  154. private:
  155. std::vector<char> CharacterData;
  156. cmCTestUpdateHandler* UpdateHandler;
  157. t_CommitLog CommitLog;
  158. t_VectorOfCommits Commits;
  159. int MinRevision;
  160. int MaxRevision;
  161. };
  162. //**********************************************************************
  163. //----------------------------------------------------------------------
  164. //----------------------------------------------------------------------
  165. cmCTestUpdateHandler::cmCTestUpdateHandler()
  166. {
  167. }
  168. //----------------------------------------------------------------------
  169. void cmCTestUpdateHandler::Initialize()
  170. {
  171. this->Superclass::Initialize();
  172. }
  173. //----------------------------------------------------------------------
  174. int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
  175. {
  176. cmCTestLog(this->CTest, DEBUG, "Determine update type from command: " << cmd
  177. << " and type: " << type << std::endl);
  178. if ( type && *type )
  179. {
  180. cmCTestLog(this->CTest, DEBUG, "Type specified: " << type << std::endl);
  181. std::string stype = cmSystemTools::LowerCase(type);
  182. if ( stype.find("cvs") != std::string::npos )
  183. {
  184. return cmCTestUpdateHandler::e_CVS;
  185. }
  186. if ( stype.find("svn") != std::string::npos )
  187. {
  188. return cmCTestUpdateHandler::e_SVN;
  189. }
  190. }
  191. else
  192. {
  193. cmCTestLog(this->CTest, DEBUG, "Type not specified, check command: "
  194. << cmd << std::endl);
  195. std::string stype = cmSystemTools::LowerCase(cmd);
  196. if ( stype.find("cvs") != std::string::npos )
  197. {
  198. return cmCTestUpdateHandler::e_CVS;
  199. }
  200. if ( stype.find("svn") != std::string::npos )
  201. {
  202. return cmCTestUpdateHandler::e_SVN;
  203. }
  204. }
  205. std::string sourceDirectory = this->GetOption("SourceDirectory");
  206. cmCTestLog(this->CTest, DEBUG, "Check directory: "
  207. << sourceDirectory.c_str() << std::endl);
  208. sourceDirectory += "/.svn";
  209. if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
  210. {
  211. return cmCTestUpdateHandler::e_SVN;
  212. }
  213. sourceDirectory = this->GetOption("SourceDirectory");
  214. sourceDirectory += "/CVS";
  215. if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
  216. {
  217. return cmCTestUpdateHandler::e_CVS;
  218. }
  219. return cmCTestUpdateHandler::e_UNKNOWN;
  220. }
  221. //----------------------------------------------------------------------
  222. //clearly it would be nice if this were broken up into a few smaller
  223. //functions and commented...
  224. int cmCTestUpdateHandler::ProcessHandler()
  225. {
  226. int count = 0;
  227. int updateType = e_CVS;
  228. std::string::size_type cc, kk;
  229. bool updateProducedError = false;
  230. std::string goutput;
  231. std::string errors;
  232. // make sure
  233. std::string saveLCMessages;
  234. const char* lcmess = cmSystemTools::GetEnv("LC_MESSAGES");
  235. if(lcmess)
  236. {
  237. saveLCMessages = lcmess;
  238. }
  239. // if LC_MESSAGES is not set to en_EN, then
  240. // set it, so that svn/cvs info will be in english
  241. if(! (lcmess && strcmp(lcmess, "en_EN") == 0))
  242. {
  243. cmSystemTools::PutEnv("LC_MESSAGES=en_EN");
  244. }
  245. std::string checkoutErrorMessages;
  246. int retVal = 0;
  247. // Get source dir
  248. const char* sourceDirectory = this->GetOption("SourceDirectory");
  249. if ( !sourceDirectory )
  250. {
  251. cmCTestLog(this->CTest, ERROR_MESSAGE,
  252. "Cannot find SourceDirectory key in the DartConfiguration.tcl"
  253. << std::endl);
  254. return -1;
  255. }
  256. cmGeneratedFileStream ofs;
  257. if ( !this->CTest->GetShowOnly() )
  258. {
  259. this->StartLogFile("Update", ofs);
  260. }
  261. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  262. "Updating the repository" << std::endl);
  263. const char* initialCheckoutCommand = this->GetOption("InitialCheckout");
  264. if ( initialCheckoutCommand )
  265. {
  266. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  267. " First perform the initial checkout: " << initialCheckoutCommand
  268. << std::endl);
  269. cmStdString parent = cmSystemTools::GetParentDirectory(sourceDirectory);
  270. if ( parent.empty() )
  271. {
  272. cmCTestLog(this->CTest, ERROR_MESSAGE,
  273. "Something went wrong when trying "
  274. "to determine the parent directory of " << sourceDirectory
  275. << std::endl);
  276. return -1;
  277. }
  278. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  279. " Perform checkout in directory: " << parent.c_str() << std::endl);
  280. if ( !cmSystemTools::MakeDirectory(parent.c_str()) )
  281. {
  282. cmCTestLog(this->CTest, ERROR_MESSAGE,
  283. "Cannot create parent directory: " << parent.c_str()
  284. << " of the source directory: " << sourceDirectory << std::endl);
  285. return -1;
  286. }
  287. ofs << "* Run initial checkout" << std::endl;
  288. ofs << " Command: " << initialCheckoutCommand << std::endl;
  289. cmCTestLog(this->CTest, DEBUG, " Before: "
  290. << initialCheckoutCommand << std::endl);
  291. bool retic = this->CTest->RunCommand(initialCheckoutCommand, &goutput,
  292. &errors, &retVal, parent.c_str(), 0 /* Timeout */);
  293. cmCTestLog(this->CTest, DEBUG, " After: "
  294. << initialCheckoutCommand << std::endl);
  295. ofs << " Output: " << goutput.c_str() << std::endl;
  296. ofs << " Errors: " << errors.c_str() << std::endl;
  297. if ( !retic || retVal )
  298. {
  299. cmOStringStream ostr;
  300. ostr << "Problem running initial checkout Output [" << goutput
  301. << "] Errors [" << errors << "]";
  302. cmCTestLog(this->CTest, ERROR_MESSAGE, ostr.str().c_str() << std::endl);
  303. checkoutErrorMessages += ostr.str();
  304. updateProducedError = true;
  305. }
  306. if(!this->CTest->InitializeFromCommand(this->Command))
  307. {
  308. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  309. " Fatal Error in initialize: "
  310. << std::endl);
  311. cmSystemTools::SetFatalErrorOccured();
  312. return -1;
  313. }
  314. }
  315. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Updating the repository: "
  316. << sourceDirectory << std::endl);
  317. // Get update command
  318. std::string updateCommand
  319. = this->CTest->GetCTestConfiguration("UpdateCommand");
  320. if ( updateCommand.empty() )
  321. {
  322. updateCommand = this->CTest->GetCTestConfiguration("CVSCommand");
  323. if ( updateCommand.empty() )
  324. {
  325. updateCommand = this->CTest->GetCTestConfiguration("SVNCommand");
  326. if ( updateCommand.empty() )
  327. {
  328. cmCTestLog(this->CTest, ERROR_MESSAGE,
  329. "Cannot find CVSCommand, SVNCommand, or UpdateCommand key in the "
  330. "DartConfiguration.tcl" << std::endl);
  331. return -1;
  332. }
  333. else
  334. {
  335. updateType = e_SVN;
  336. }
  337. }
  338. else
  339. {
  340. updateType = e_CVS;
  341. }
  342. }
  343. else
  344. {
  345. updateType = this->DetermineType(updateCommand.c_str(),
  346. this->CTest->GetCTestConfiguration("UpdateType").c_str());
  347. }
  348. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Use "
  349. << cmCTestUpdateHandlerUpdateToString(updateType) << " repository type"
  350. << std::endl;);
  351. // And update options
  352. std::string updateOptions
  353. = this->CTest->GetCTestConfiguration("UpdateOptions");
  354. if ( updateOptions.empty() )
  355. {
  356. switch (updateType)
  357. {
  358. case cmCTestUpdateHandler::e_CVS:
  359. updateOptions = this->CTest->GetCTestConfiguration("CVSUpdateOptions");
  360. if ( updateOptions.empty() )
  361. {
  362. updateOptions = "-dP";
  363. }
  364. break;
  365. case cmCTestUpdateHandler::e_SVN:
  366. updateOptions = this->CTest->GetCTestConfiguration("SVNUpdateOptions");
  367. break;
  368. }
  369. }
  370. // Get update time
  371. std::string extra_update_opts;
  372. if ( this->CTest->GetTestModel() == cmCTest::NIGHTLY )
  373. {
  374. struct tm* t = this->CTest->GetNightlyTime(
  375. this->CTest->GetCTestConfiguration("NightlyStartTime"),
  376. this->CTest->GetTomorrowTag());
  377. char current_time[1024];
  378. sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d",
  379. t->tm_year + 1900,
  380. t->tm_mon + 1,
  381. t->tm_mday,
  382. t->tm_hour,
  383. t->tm_min,
  384. t->tm_sec);
  385. std::string today_update_date = current_time;
  386. // TODO: SVN
  387. switch ( updateType )
  388. {
  389. case cmCTestUpdateHandler::e_CVS:
  390. extra_update_opts += "-D \"" + today_update_date +" UTC\"";
  391. break;
  392. case cmCTestUpdateHandler::e_SVN:
  393. extra_update_opts += "-r \"{" + today_update_date +" +0000}\"";
  394. break;
  395. }
  396. }
  397. bool res = true;
  398. updateCommand = "\"" + updateCommand + "\"";
  399. // First, check what the current state of repository is
  400. std::string command = "";
  401. switch( updateType )
  402. {
  403. case cmCTestUpdateHandler::e_CVS:
  404. // TODO: CVS - for now just leave empty
  405. break;
  406. case cmCTestUpdateHandler::e_SVN:
  407. command = updateCommand + " cleanup";
  408. break;
  409. }
  410. //
  411. // Get initial repository information if that is possible. With subversion,
  412. // this will check the current revision.
  413. //
  414. if ( !command.empty() )
  415. {
  416. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  417. "* Cleanup repository: " << command.c_str() << std::endl);
  418. if ( !this->CTest->GetShowOnly() )
  419. {
  420. ofs << "* Cleanup repository" << std::endl;
  421. ofs << " Command: " << command.c_str() << std::endl;
  422. res = this->CTest->RunCommand(command.c_str(), &goutput, &errors,
  423. &retVal, sourceDirectory, 0 /*this->TimeOut*/);
  424. ofs << " Output: " << goutput.c_str() << std::endl;
  425. ofs << " Errors: " << errors.c_str() << std::endl;
  426. if ( ofs )
  427. {
  428. ofs << "--- Cleanup ---" << std::endl;
  429. ofs << goutput << std::endl;
  430. }
  431. }
  432. else
  433. {
  434. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  435. "Cleanup with command: " << command << std::endl);
  436. }
  437. }
  438. // First, check what the current state of repository is
  439. command = "";
  440. switch( updateType )
  441. {
  442. case cmCTestUpdateHandler::e_CVS:
  443. // TODO: CVS - for now just leave empty
  444. break;
  445. case cmCTestUpdateHandler::e_SVN:
  446. command = updateCommand + " info";
  447. break;
  448. }
  449. // CVS variables
  450. // SVN variables
  451. int svn_current_revision = 0;
  452. int svn_latest_revision = 0;
  453. int svn_use_status = 0;
  454. //
  455. // Get initial repository information if that is possible. With subversion,
  456. // this will check the current revision.
  457. //
  458. if ( !command.empty() )
  459. {
  460. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  461. "* Get repository information: " << command.c_str() << std::endl);
  462. if ( !this->CTest->GetShowOnly() )
  463. {
  464. ofs << "* Get repository information" << std::endl;
  465. ofs << " Command: " << command.c_str() << std::endl;
  466. res = this->CTest->RunCommand(command.c_str(), &goutput, &errors,
  467. &retVal, sourceDirectory, 0 /*this->TimeOut*/);
  468. ofs << " Output: " << goutput.c_str() << std::endl;
  469. ofs << " Errors: " << errors.c_str() << std::endl;
  470. if ( ofs )
  471. {
  472. ofs << "--- Update information ---" << std::endl;
  473. ofs << goutput << std::endl;
  474. }
  475. switch ( updateType )
  476. {
  477. case cmCTestUpdateHandler::e_CVS:
  478. // TODO: CVS - for now just leave empty
  479. break;
  480. case cmCTestUpdateHandler::e_SVN:
  481. {
  482. cmsys::RegularExpression current_revision_regex(
  483. "Revision: ([0-9]+)");
  484. if ( current_revision_regex.find(goutput.c_str()) )
  485. {
  486. std::string currentRevisionString
  487. = current_revision_regex.match(1);
  488. svn_current_revision = atoi(currentRevisionString.c_str());
  489. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  490. " Old revision of repository is: " << svn_current_revision
  491. << std::endl);
  492. }
  493. }
  494. break;
  495. }
  496. }
  497. else
  498. {
  499. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  500. "Get information with command: " << command << std::endl);
  501. }
  502. }
  503. //
  504. // Now update repository and remember what files were updated
  505. //
  506. cmGeneratedFileStream os;
  507. if ( !this->StartResultingXML("Update", os) )
  508. {
  509. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open log file"
  510. << std::endl);
  511. return -1;
  512. }
  513. std::string start_time = this->CTest->CurrentTime();
  514. unsigned int start_time_time =
  515. static_cast<unsigned int>(cmSystemTools::GetTime());
  516. double elapsed_time_start = cmSystemTools::GetTime();
  517. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "* Update repository: "
  518. << command.c_str() << std::endl);
  519. if ( !this->CTest->GetShowOnly() )
  520. {
  521. command = "";
  522. switch( updateType )
  523. {
  524. case cmCTestUpdateHandler::e_CVS:
  525. command = updateCommand + " -z3 update " + updateOptions +
  526. " " + extra_update_opts;
  527. ofs << "* Update repository: " << std::endl;
  528. ofs << " Command: " << command.c_str() << std::endl;
  529. res = this->CTest->RunCommand(command.c_str(), &goutput, &errors,
  530. &retVal, sourceDirectory, 0 /*this->TimeOut*/);
  531. ofs << " Output: " << goutput.c_str() << std::endl;
  532. ofs << " Errors: " << errors.c_str() << std::endl;
  533. break;
  534. case cmCTestUpdateHandler::e_SVN:
  535. {
  536. std::string partialOutput;
  537. command = updateCommand + " update " + updateOptions +
  538. " " + extra_update_opts;
  539. ofs << "* Update repository: " << std::endl;
  540. ofs << " Command: " << command.c_str() << std::endl;
  541. bool res1 = this->CTest->RunCommand(command.c_str(), &partialOutput,
  542. &errors,
  543. &retVal, sourceDirectory, 0 /*this->TimeOut*/);
  544. ofs << " Output: " << partialOutput.c_str() << std::endl;
  545. ofs << " Errors: " << errors.c_str() << std::endl;
  546. goutput = partialOutput;
  547. command = updateCommand + " status";
  548. ofs << "* Status repository: " << std::endl;
  549. ofs << " Command: " << command.c_str() << std::endl;
  550. res = this->CTest->RunCommand(command.c_str(), &partialOutput,
  551. &errors, &retVal, sourceDirectory, 0 /*this->TimeOut*/);
  552. ofs << " Output: " << partialOutput.c_str() << std::endl;
  553. ofs << " Errors: " << errors.c_str() << std::endl;
  554. goutput += partialOutput;
  555. res = res && res1;
  556. ofs << " Total output of update: " << goutput.c_str() << std::endl;
  557. }
  558. }
  559. if ( ofs )
  560. {
  561. ofs << "--- Update repository ---" << std::endl;
  562. ofs << goutput << std::endl;
  563. }
  564. }
  565. if ( !res || retVal )
  566. {
  567. updateProducedError = true;
  568. checkoutErrorMessages += " " + goutput;
  569. }
  570. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  571. << "<Update mode=\"Client\" Generator=\"ctest-"
  572. << cmVersion::GetCMakeVersion() << "\">\n"
  573. << "\t<Site>" << this->CTest->GetCTestConfiguration("Site") << "</Site>\n"
  574. << "\t<BuildName>" << this->CTest->GetCTestConfiguration("BuildName")
  575. << "</BuildName>\n"
  576. << "\t<BuildStamp>" << this->CTest->GetCurrentTag() << "-"
  577. << this->CTest->GetTestModelString() << "</BuildStamp>" << std::endl;
  578. os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
  579. << "\t<StartTime>" << start_time_time << "</StartTime>\n"
  580. << "\t<UpdateCommand>" << this->CTest->MakeXMLSafe(command)
  581. << "</UpdateCommand>\n"
  582. << "\t<UpdateType>" << this->CTest->MakeXMLSafe(
  583. cmCTestUpdateHandlerUpdateToString(updateType))
  584. << "</UpdateType>\n";
  585. // Even though it failed, we may have some useful information. Try to
  586. // continue...
  587. std::vector<cmStdString> lines;
  588. cmSystemTools::Split(goutput.c_str(), lines);
  589. std::vector<cmStdString> errLines;
  590. cmSystemTools::Split(errors.c_str(), errLines);
  591. lines.insert(lines.end(), errLines.begin(), errLines.end());
  592. // CVS style regular expressions
  593. cmsys::RegularExpression cvs_date_author_regex(
  594. "^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
  595. cmsys::RegularExpression cvs_revision_regex("^revision +([^ ]*) *$");
  596. cmsys::RegularExpression cvs_end_of_file_regex(
  597. "^=========================================="
  598. "===================================$");
  599. cmsys::RegularExpression cvs_end_of_comment_regex(
  600. "^----------------------------$");
  601. // Subversion style regular expressions
  602. cmsys::RegularExpression svn_status_line_regex(
  603. "^ *([0-9]+) *([0-9]+) *([^ ]+) *([^ ][^\t\r\n]*)[ \t\r\n]*$");
  604. cmsys::RegularExpression svn_latest_revision_regex(
  605. "(Updated to|At) revision ([0-9]+)\\.");
  606. cmsys::RegularExpression file_removed_line(
  607. "cvs update: `(.*)' is no longer in the repository");
  608. cmsys::RegularExpression file_update_line("([A-Z]) *(.*)");
  609. std::string current_path = "<no-path>";
  610. bool first_file = true;
  611. cmCTestUpdateHandler::AuthorsToUpdatesMap authors_files_map;
  612. int numUpdated = 0;
  613. int numModiefied = 0;
  614. int numConflicting = 0;
  615. // In subversion, get the latest revision
  616. if ( updateType == cmCTestUpdateHandler::e_SVN )
  617. {
  618. for ( cc= 0; cc < lines.size(); cc ++ )
  619. {
  620. const char* line = lines[cc].c_str();
  621. if ( svn_latest_revision_regex.find(line) )
  622. {
  623. svn_latest_revision = atoi(
  624. svn_latest_revision_regex.match(2).c_str());
  625. }
  626. }
  627. if ( svn_latest_revision <= 0 )
  628. {
  629. cmCTestLog(this->CTest, ERROR_MESSAGE,
  630. "Problem determining the current "
  631. "revision of the repository from output:" << std::endl
  632. << goutput.c_str() << std::endl);
  633. }
  634. else
  635. {
  636. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  637. " Current revision of repository is: " << svn_latest_revision
  638. << std::endl);
  639. }
  640. }
  641. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  642. " Gathering version information (each . represents one updated file):"
  643. << std::endl);
  644. int file_count = 0;
  645. std::string removed_line;
  646. for ( cc= 0; cc < lines.size(); cc ++ )
  647. {
  648. const char* line = lines[cc].c_str();
  649. if ( file_removed_line.find(line) )
  650. {
  651. removed_line = "D " + file_removed_line.match(1);
  652. line = removed_line.c_str();
  653. }
  654. if ( file_update_line.find(line) )
  655. {
  656. if ( file_count == 0 )
  657. {
  658. cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << std::flush);
  659. }
  660. cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
  661. std::string upChar = file_update_line.match(1);
  662. std::string upFile = file_update_line.match(2);
  663. char mod = upChar[0];
  664. bool modifiedOrConflict = false;
  665. if ( mod == 'X' || mod == 'L')
  666. {
  667. continue;
  668. }
  669. if ( mod != 'M' && mod != 'C' && mod != 'G' )
  670. {
  671. count ++;
  672. modifiedOrConflict = true;
  673. }
  674. const char* file = upFile.c_str();
  675. cmCTestLog(this->CTest, DEBUG, "Line" << cc << ": " << mod << " - "
  676. << file << std::endl);
  677. std::string output;
  678. if ( modifiedOrConflict )
  679. {
  680. std::string logcommand;
  681. switch ( updateType )
  682. {
  683. case cmCTestUpdateHandler::e_CVS:
  684. logcommand = updateCommand + " -z3 log -N \"" + file + "\"";
  685. break;
  686. case cmCTestUpdateHandler::e_SVN:
  687. if ( svn_latest_revision > 0 &&
  688. svn_latest_revision > svn_current_revision )
  689. {
  690. cmOStringStream logCommandStream;
  691. logCommandStream << updateCommand << " log -r "
  692. << svn_current_revision << ":" << svn_latest_revision
  693. << " --xml \"" << file << "\"";
  694. logcommand = logCommandStream.str();
  695. }
  696. else
  697. {
  698. logcommand = updateCommand +
  699. " status --verbose \"" + file + "\"";
  700. svn_use_status = 1;
  701. }
  702. break;
  703. }
  704. cmCTestLog(this->CTest, DEBUG, "Do log: " << logcommand << std::endl);
  705. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  706. "* Get file update information: " << logcommand.c_str()
  707. << std::endl);
  708. ofs << "* Get log information for file: " << file << std::endl;
  709. ofs << " Command: " << logcommand.c_str() << std::endl;
  710. res = this->CTest->RunCommand(logcommand.c_str(), &output, &errors,
  711. &retVal, sourceDirectory, 0 /*this->TimeOut*/);
  712. ofs << " Output: " << output.c_str() << std::endl;
  713. ofs << " Errors: " << errors.c_str() << std::endl;
  714. if ( ofs )
  715. {
  716. ofs << output << std::endl;
  717. }
  718. }
  719. if ( res )
  720. {
  721. cmCTestLog(this->CTest, DEBUG, output << std::endl);
  722. std::string::size_type sline = 0;
  723. std::string srevision1 = "Unknown";
  724. std::string sdate1 = "Unknown";
  725. std::string sauthor1 = "Unknown";
  726. std::string semail1 = "Unknown";
  727. std::string comment1 = "";
  728. std::string srevision2 = "Unknown";
  729. std::string sdate2 = "Unknown";
  730. std::string sauthor2 = "Unknown";
  731. std::string comment2 = "";
  732. std::string semail2 = "Unknown";
  733. if ( updateType == cmCTestUpdateHandler::e_CVS )
  734. {
  735. bool have_first = false;
  736. bool have_second = false;
  737. std::vector<cmStdString> ulines;
  738. cmSystemTools::Split(output.c_str(), ulines);
  739. for ( kk = 0; kk < ulines.size(); kk ++ )
  740. {
  741. const char* clp = ulines[kk].c_str();
  742. if ( !have_second && !sline && cvs_revision_regex.find(clp) )
  743. {
  744. if ( !have_first )
  745. {
  746. srevision1 = cvs_revision_regex.match(1);
  747. }
  748. else
  749. {
  750. srevision2 = cvs_revision_regex.match(1);
  751. }
  752. }
  753. else if ( !have_second && !sline &&
  754. cvs_date_author_regex.find(clp) )
  755. {
  756. sline = kk + 1;
  757. if ( !have_first )
  758. {
  759. sdate1 = cvs_date_author_regex.match(1);
  760. sauthor1 = cvs_date_author_regex.match(2);
  761. }
  762. else
  763. {
  764. sdate2 = cvs_date_author_regex.match(1);
  765. sauthor2 = cvs_date_author_regex.match(2);
  766. }
  767. }
  768. else if ( sline && cvs_end_of_comment_regex.find(clp) ||
  769. cvs_end_of_file_regex.find(clp))
  770. {
  771. if ( !have_first )
  772. {
  773. have_first = true;
  774. }
  775. else if ( !have_second )
  776. {
  777. have_second = true;
  778. }
  779. sline = 0;
  780. }
  781. else if ( sline )
  782. {
  783. if ( !have_first )
  784. {
  785. comment1 += clp;
  786. comment1 += "\n";
  787. }
  788. else
  789. {
  790. comment2 += clp;
  791. comment2 += "\n";
  792. }
  793. }
  794. }
  795. }
  796. else if ( updateType == cmCTestUpdateHandler::e_SVN )
  797. {
  798. if ( svn_use_status )
  799. {
  800. cmOStringStream str;
  801. str << svn_current_revision;
  802. srevision1 = str.str();
  803. if (!svn_status_line_regex.find(output))
  804. {
  805. cmCTestLog(this->CTest, ERROR_MESSAGE,
  806. "Bad output from SVN status command: " << output
  807. << std::endl);
  808. }
  809. else if ( svn_status_line_regex.match(4) != file )
  810. {
  811. cmCTestLog(this->CTest, ERROR_MESSAGE,
  812. "Bad output from SVN status command. "
  813. "The file name returned: \""
  814. << svn_status_line_regex.match(4)
  815. << "\" was different than the file specified: \"" << file
  816. << "\"" << std::endl);
  817. }
  818. else
  819. {
  820. srevision1 = svn_status_line_regex.match(2);
  821. int latest_revision = atoi(
  822. svn_status_line_regex.match(2).c_str());
  823. if ( svn_current_revision < latest_revision )
  824. {
  825. srevision2 = str.str();
  826. }
  827. sauthor1 = svn_status_line_regex.match(3);
  828. }
  829. }
  830. else
  831. {
  832. cmCTestUpdateHandlerSVNXMLParser parser(this);
  833. if ( parser.Parse(output.c_str()) )
  834. {
  835. int minrev = parser.GetMinRevision();
  836. int maxrev = parser.GetMaxRevision();
  837. cmCTestUpdateHandlerSVNXMLParser::
  838. t_VectorOfCommits::iterator it;
  839. for ( it = parser.GetCommits()->begin();
  840. it != parser.GetCommits()->end();
  841. ++ it )
  842. {
  843. if ( it->Revision == maxrev )
  844. {
  845. cmOStringStream mRevStream;
  846. mRevStream << maxrev;
  847. srevision1 = mRevStream.str();
  848. sauthor1 = it->Author;
  849. comment1 = it->Message;
  850. sdate1 = it->Date;
  851. }
  852. else if ( it->Revision == minrev )
  853. {
  854. cmOStringStream mRevStream;
  855. mRevStream << minrev;
  856. srevision2 = mRevStream.str();
  857. sauthor2 = it->Author;
  858. comment2 = it->Message;
  859. sdate2 = it->Date;
  860. }
  861. }
  862. }
  863. }
  864. }
  865. if ( mod == 'M' )
  866. {
  867. comment1 = "Locally modified file\n";
  868. sauthor1 = "Local User";
  869. }
  870. if ( mod == 'D' )
  871. {
  872. comment1 += " - Removed file\n";
  873. }
  874. if ( mod == 'C' )
  875. {
  876. comment1 = "Conflict while updating\n";
  877. sauthor1 = "Local User";
  878. }
  879. std::string path = cmSystemTools::GetFilenamePath(file);
  880. std::string fname = cmSystemTools::GetFilenameName(file);
  881. if ( path != current_path )
  882. {
  883. if ( !first_file )
  884. {
  885. os << "\t</Directory>" << std::endl;
  886. }
  887. else
  888. {
  889. first_file = false;
  890. }
  891. os << "\t<Directory>\n"
  892. << "\t\t<Name>" << path << "</Name>" << std::endl;
  893. }
  894. if ( mod == 'C' )
  895. {
  896. numConflicting ++;
  897. os << "\t<Conflicting>" << std::endl;
  898. }
  899. else if ( mod == 'G' )
  900. {
  901. numConflicting ++;
  902. os << "\t<Conflicting>" << std::endl;
  903. }
  904. else if ( mod == 'M' )
  905. {
  906. numModiefied ++;
  907. os << "\t<Modified>" << std::endl;
  908. }
  909. else
  910. {
  911. numUpdated ++;
  912. os << "\t<Updated>" << std::endl;
  913. }
  914. if ( srevision2 == "Unknown" )
  915. {
  916. srevision2 = srevision1;
  917. }
  918. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "File: "
  919. << path.c_str() << " / " << fname.c_str() << " was updated by "
  920. << sauthor1.c_str() << " to revision: " << srevision1.c_str()
  921. << " from revision: " << srevision2.c_str() << std::endl);
  922. os << "\t\t<File Directory=\"" << cmCTest::MakeXMLSafe(path) << "\">"
  923. << cmCTest::MakeXMLSafe(fname)
  924. << "</File>\n"
  925. << "\t\t<Directory>" << cmCTest::MakeXMLSafe(path)
  926. << "</Directory>\n"
  927. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(file) << "</FullName>\n"
  928. << "\t\t<CheckinDate>" << cmCTest::MakeXMLSafe(sdate1)
  929. << "</CheckinDate>\n"
  930. << "\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1) << "</Author>\n"
  931. << "\t\t<Email>" << cmCTest::MakeXMLSafe(semail1) << "</Email>\n"
  932. << "\t\t<Log>" << cmCTest::MakeXMLSafe(comment1) << "</Log>\n"
  933. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  934. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  935. << std::endl;
  936. if ( srevision2 != srevision1 )
  937. {
  938. os
  939. << "\t\t<Revisions>\n"
  940. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  941. << "\t\t\t<PreviousRevision>" << srevision2
  942. << "</PreviousRevision>\n"
  943. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1)
  944. << "</Author>\n"
  945. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate1)
  946. << "</Date>\n"
  947. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment1)
  948. << "</Comment>\n"
  949. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail1)
  950. << "</Email>\n"
  951. << "\t\t</Revisions>\n"
  952. << "\t\t<Revisions>\n"
  953. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  954. << "\t\t\t<PreviousRevision>" << srevision2
  955. << "</PreviousRevision>\n"
  956. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor2)
  957. << "</Author>\n"
  958. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate2)
  959. << "</Date>\n"
  960. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment2)
  961. << "</Comment>\n"
  962. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail2)
  963. << "</Email>\n"
  964. << "\t\t</Revisions>" << std::endl;
  965. }
  966. if ( mod == 'C' )
  967. {
  968. os << "\t</Conflicting>" << std::endl;
  969. }
  970. else if ( mod == 'G' )
  971. {
  972. os << "\t</Conflicting>" << std::endl;
  973. }
  974. else if ( mod == 'M' )
  975. {
  976. os << "\t</Modified>" << std::endl;
  977. }
  978. else
  979. {
  980. os << "\t</Updated>" << std::endl;
  981. }
  982. cmCTestUpdateHandler::UpdateFiles *u = &authors_files_map[sauthor1];
  983. cmCTestUpdateHandler::StringPair p;
  984. p.first = path;
  985. p.second = fname;
  986. u->push_back(p);
  987. current_path = path;
  988. }
  989. file_count ++;
  990. }
  991. }
  992. if ( file_count )
  993. {
  994. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
  995. }
  996. if ( numUpdated )
  997. {
  998. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Found " << numUpdated
  999. << " updated files" << std::endl);
  1000. }
  1001. if ( numModiefied )
  1002. {
  1003. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Found " << numModiefied
  1004. << " locally modified files"
  1005. << std::endl);
  1006. }
  1007. if ( numConflicting )
  1008. {
  1009. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Found " << numConflicting
  1010. << " conflicting files"
  1011. << std::endl);
  1012. }
  1013. if ( numModiefied == 0 && numConflicting == 0 && numUpdated == 0 )
  1014. {
  1015. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Project is up-to-date"
  1016. << std::endl);
  1017. }
  1018. if ( !first_file )
  1019. {
  1020. os << "\t</Directory>" << std::endl;
  1021. }
  1022. cmCTestUpdateHandler::AuthorsToUpdatesMap::iterator it;
  1023. for ( it = authors_files_map.begin();
  1024. it != authors_files_map.end();
  1025. it ++ )
  1026. {
  1027. os << "\t<Author>\n"
  1028. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  1029. cmCTestUpdateHandler::UpdateFiles *u = &(it->second);
  1030. for ( cc = 0; cc < u->size(); cc ++ )
  1031. {
  1032. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  1033. << (*u)[cc].second << "</File>" << std::endl;
  1034. }
  1035. os << "\t</Author>" << std::endl;
  1036. }
  1037. cmCTestLog(this->CTest, DEBUG, "End" << std::endl);
  1038. std::string end_time = this->CTest->CurrentTime();
  1039. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  1040. << "\t<EndTime>" << static_cast<unsigned int>(cmSystemTools::GetTime())
  1041. << "</EndTime>\n"
  1042. << "<ElapsedMinutes>" <<
  1043. static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  1044. << "</ElapsedMinutes>\n"
  1045. << "\t<UpdateReturnStatus>";
  1046. if ( numModiefied > 0 || numConflicting > 0 )
  1047. {
  1048. os << "Update error: There are modified or conflicting files in the "
  1049. "repository";
  1050. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1051. " There are modified or conflicting files in the repository"
  1052. << std::endl);
  1053. }
  1054. if ( updateProducedError )
  1055. {
  1056. os << "Update error: ";
  1057. os << this->CTest->MakeXMLSafe(checkoutErrorMessages);
  1058. cmCTestLog(this->CTest, ERROR_MESSAGE, " Update with command: "
  1059. << command << " failed" << std::endl);
  1060. }
  1061. os << "</UpdateReturnStatus>" << std::endl;
  1062. os << "</Update>" << std::endl;
  1063. // restore the value of LC_MESSAGES after running the version control
  1064. // commands
  1065. if(saveLCMessages.size())
  1066. {
  1067. std::string put = "LC_MESSAGES=";
  1068. put += saveLCMessages;
  1069. cmSystemTools::PutEnv(put.c_str());
  1070. }
  1071. else
  1072. {
  1073. cmSystemTools::UnsetEnv("LC_MESSAGES");
  1074. }
  1075. if (! res )
  1076. {
  1077. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1078. "Error(s) when updating the project" << std::endl);
  1079. cmCTestLog(this->CTest, ERROR_MESSAGE, "Output: "
  1080. << goutput << std::endl);
  1081. return -1;
  1082. }
  1083. return count;
  1084. }