cmCTestUpdateHandler.cxx 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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. std::string checkoutErrorMessages;
  233. int retVal = 0;
  234. // Get source dir
  235. const char* sourceDirectory = this->GetOption("SourceDirectory");
  236. if ( !sourceDirectory )
  237. {
  238. cmCTestLog(this->CTest, ERROR_MESSAGE,
  239. "Cannot find SourceDirectory key in the DartConfiguration.tcl"
  240. << std::endl);
  241. return -1;
  242. }
  243. cmGeneratedFileStream ofs;
  244. if ( !this->CTest->GetShowOnly() )
  245. {
  246. this->StartLogFile("Update", ofs);
  247. }
  248. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  249. "Updating the repository" << std::endl);
  250. const char* initialCheckoutCommand = this->GetOption("InitialCheckout");
  251. if ( initialCheckoutCommand )
  252. {
  253. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  254. " First perform the initial checkout: " << initialCheckoutCommand
  255. << std::endl);
  256. cmStdString parent = cmSystemTools::GetParentDirectory(sourceDirectory);
  257. if ( parent.empty() )
  258. {
  259. cmCTestLog(this->CTest, ERROR_MESSAGE,
  260. "Something went wrong when trying "
  261. "to determine the parent directory of " << sourceDirectory
  262. << std::endl);
  263. return -1;
  264. }
  265. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  266. " Perform checkout in directory: " << parent.c_str() << std::endl);
  267. if ( !cmSystemTools::MakeDirectory(parent.c_str()) )
  268. {
  269. cmCTestLog(this->CTest, ERROR_MESSAGE,
  270. "Cannot create parent directory: " << parent.c_str()
  271. << " of the source directory: " << sourceDirectory << std::endl);
  272. return -1;
  273. }
  274. ofs << "* Run initial checkout" << std::endl;
  275. ofs << " Command: " << initialCheckoutCommand << std::endl;
  276. cmCTestLog(this->CTest, DEBUG, " Before: "
  277. << initialCheckoutCommand << std::endl);
  278. bool retic = this->CTest->RunCommand(initialCheckoutCommand, &goutput,
  279. &errors, &retVal, parent.c_str(), 0 /* Timeout */);
  280. cmCTestLog(this->CTest, DEBUG, " After: "
  281. << initialCheckoutCommand << std::endl);
  282. ofs << " Output: " << goutput.c_str() << std::endl;
  283. ofs << " Errors: " << errors.c_str() << std::endl;
  284. if ( !retic || retVal )
  285. {
  286. cmOStringStream ostr;
  287. ostr << "Problem running initial checkout Output [" << goutput
  288. << "] Errors [" << errors << "]";
  289. cmCTestLog(this->CTest, ERROR_MESSAGE, ostr.str().c_str() << std::endl);
  290. checkoutErrorMessages += ostr.str();
  291. updateProducedError = true;
  292. }
  293. if(!this->CTest->InitializeFromCommand(this->Command))
  294. {
  295. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  296. " Fatal Error in initialize: "
  297. << std::endl);
  298. cmSystemTools::SetFatalErrorOccured();
  299. return -1;
  300. }
  301. }
  302. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Updating the repository: "
  303. << sourceDirectory << std::endl);
  304. // Get update command
  305. std::string updateCommand
  306. = this->CTest->GetCTestConfiguration("UpdateCommand");
  307. if ( updateCommand.empty() )
  308. {
  309. updateCommand = this->CTest->GetCTestConfiguration("CVSCommand");
  310. if ( updateCommand.empty() )
  311. {
  312. updateCommand = this->CTest->GetCTestConfiguration("SVNCommand");
  313. if ( updateCommand.empty() )
  314. {
  315. cmCTestLog(this->CTest, ERROR_MESSAGE,
  316. "Cannot find CVSCommand, SVNCommand, or UpdateCommand key in the "
  317. "DartConfiguration.tcl" << std::endl);
  318. return -1;
  319. }
  320. else
  321. {
  322. updateType = e_SVN;
  323. }
  324. }
  325. else
  326. {
  327. updateType = e_CVS;
  328. }
  329. }
  330. else
  331. {
  332. updateType = this->DetermineType(updateCommand.c_str(),
  333. this->CTest->GetCTestConfiguration("UpdateType").c_str());
  334. }
  335. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Use "
  336. << cmCTestUpdateHandlerUpdateToString(updateType) << " repository type"
  337. << std::endl;);
  338. // And update options
  339. std::string updateOptions
  340. = this->CTest->GetCTestConfiguration("UpdateOptions");
  341. if ( updateOptions.empty() )
  342. {
  343. switch (updateType)
  344. {
  345. case cmCTestUpdateHandler::e_CVS:
  346. updateOptions = this->CTest->GetCTestConfiguration("CVSUpdateOptions");
  347. if ( updateOptions.empty() )
  348. {
  349. updateOptions = "-dP";
  350. }
  351. break;
  352. case cmCTestUpdateHandler::e_SVN:
  353. updateOptions = this->CTest->GetCTestConfiguration("SVNUpdateOptions");
  354. break;
  355. }
  356. }
  357. // Get update time
  358. std::string extra_update_opts;
  359. if ( this->CTest->GetTestModel() == cmCTest::NIGHTLY )
  360. {
  361. struct tm* t = this->CTest->GetNightlyTime(
  362. this->CTest->GetCTestConfiguration("NightlyStartTime"),
  363. this->CTest->GetTomorrowTag());
  364. char current_time[1024];
  365. sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d",
  366. t->tm_year + 1900,
  367. t->tm_mon + 1,
  368. t->tm_mday,
  369. t->tm_hour,
  370. t->tm_min,
  371. t->tm_sec);
  372. std::string today_update_date = current_time;
  373. // TODO: SVN
  374. switch ( updateType )
  375. {
  376. case cmCTestUpdateHandler::e_CVS:
  377. extra_update_opts += "-D \"" + today_update_date +" UTC\"";
  378. break;
  379. case cmCTestUpdateHandler::e_SVN:
  380. extra_update_opts += "-r \"{" + today_update_date +" +0000}\"";
  381. break;
  382. }
  383. }
  384. bool res = true;
  385. updateCommand = "\"" + updateCommand + "\"";
  386. // First, check what the current state of repository is
  387. std::string command = "";
  388. switch( updateType )
  389. {
  390. case cmCTestUpdateHandler::e_CVS:
  391. // TODO: CVS - for now just leave empty
  392. break;
  393. case cmCTestUpdateHandler::e_SVN:
  394. command = updateCommand + " cleanup";
  395. break;
  396. }
  397. //
  398. // Get initial repository information if that is possible. With subversion,
  399. // this will check the current revision.
  400. //
  401. if ( !command.empty() )
  402. {
  403. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  404. "* Cleanup repository: " << command.c_str() << std::endl);
  405. if ( !this->CTest->GetShowOnly() )
  406. {
  407. ofs << "* Cleanup repository" << std::endl;
  408. ofs << " Command: " << command.c_str() << std::endl;
  409. res = this->CTest->RunCommand(command.c_str(), &goutput, &errors,
  410. &retVal, sourceDirectory, 0 /*this->TimeOut*/);
  411. ofs << " Output: " << goutput.c_str() << std::endl;
  412. ofs << " Errors: " << errors.c_str() << std::endl;
  413. if ( ofs )
  414. {
  415. ofs << "--- Cleanup ---" << std::endl;
  416. ofs << goutput << std::endl;
  417. }
  418. }
  419. else
  420. {
  421. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  422. "Cleanup with command: " << command << std::endl);
  423. }
  424. }
  425. // First, check what the current state of repository is
  426. command = "";
  427. switch( updateType )
  428. {
  429. case cmCTestUpdateHandler::e_CVS:
  430. // TODO: CVS - for now just leave empty
  431. break;
  432. case cmCTestUpdateHandler::e_SVN:
  433. command = updateCommand + " info";
  434. break;
  435. }
  436. // CVS variables
  437. // SVN variables
  438. int svn_current_revision = 0;
  439. int svn_latest_revision = 0;
  440. int svn_use_status = 0;
  441. //
  442. // Get initial repository information if that is possible. With subversion,
  443. // this will check the current revision.
  444. //
  445. if ( !command.empty() )
  446. {
  447. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  448. "* Get repository information: " << command.c_str() << std::endl);
  449. if ( !this->CTest->GetShowOnly() )
  450. {
  451. ofs << "* Get repository information" << std::endl;
  452. ofs << " Command: " << command.c_str() << std::endl;
  453. res = this->CTest->RunCommand(command.c_str(), &goutput, &errors,
  454. &retVal, sourceDirectory, 0 /*this->TimeOut*/);
  455. ofs << " Output: " << goutput.c_str() << std::endl;
  456. ofs << " Errors: " << errors.c_str() << std::endl;
  457. if ( ofs )
  458. {
  459. ofs << "--- Update information ---" << std::endl;
  460. ofs << goutput << std::endl;
  461. }
  462. switch ( updateType )
  463. {
  464. case cmCTestUpdateHandler::e_CVS:
  465. // TODO: CVS - for now just leave empty
  466. break;
  467. case cmCTestUpdateHandler::e_SVN:
  468. {
  469. cmsys::RegularExpression current_revision_regex(
  470. "Revision: ([0-9]+)");
  471. if ( current_revision_regex.find(goutput.c_str()) )
  472. {
  473. std::string currentRevisionString
  474. = current_revision_regex.match(1);
  475. svn_current_revision = atoi(currentRevisionString.c_str());
  476. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  477. " Old revision of repository is: " << svn_current_revision
  478. << std::endl);
  479. }
  480. }
  481. break;
  482. }
  483. }
  484. else
  485. {
  486. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  487. "Get information with command: " << command << std::endl);
  488. }
  489. }
  490. //
  491. // Now update repository and remember what files were updated
  492. //
  493. cmGeneratedFileStream os;
  494. if ( !this->StartResultingXML("Update", os) )
  495. {
  496. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open log file"
  497. << std::endl);
  498. return -1;
  499. }
  500. std::string start_time = this->CTest->CurrentTime();
  501. unsigned int start_time_time =
  502. static_cast<unsigned int>(cmSystemTools::GetTime());
  503. double elapsed_time_start = cmSystemTools::GetTime();
  504. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "* Update repository: "
  505. << command.c_str() << std::endl);
  506. if ( !this->CTest->GetShowOnly() )
  507. {
  508. command = "";
  509. switch( updateType )
  510. {
  511. case cmCTestUpdateHandler::e_CVS:
  512. command = updateCommand + " -z3 update " + updateOptions +
  513. " " + extra_update_opts;
  514. ofs << "* Update repository: " << std::endl;
  515. ofs << " Command: " << command.c_str() << std::endl;
  516. res = this->CTest->RunCommand(command.c_str(), &goutput, &errors,
  517. &retVal, sourceDirectory, 0 /*this->TimeOut*/);
  518. ofs << " Output: " << goutput.c_str() << std::endl;
  519. ofs << " Errors: " << errors.c_str() << std::endl;
  520. break;
  521. case cmCTestUpdateHandler::e_SVN:
  522. {
  523. std::string partialOutput;
  524. command = updateCommand + " update " + updateOptions +
  525. " " + extra_update_opts;
  526. ofs << "* Update repository: " << std::endl;
  527. ofs << " Command: " << command.c_str() << std::endl;
  528. bool res1 = this->CTest->RunCommand(command.c_str(), &partialOutput,
  529. &errors,
  530. &retVal, sourceDirectory, 0 /*this->TimeOut*/);
  531. ofs << " Output: " << partialOutput.c_str() << std::endl;
  532. ofs << " Errors: " << errors.c_str() << std::endl;
  533. goutput = partialOutput;
  534. command = updateCommand + " status";
  535. ofs << "* Status repository: " << std::endl;
  536. ofs << " Command: " << command.c_str() << std::endl;
  537. res = this->CTest->RunCommand(command.c_str(), &partialOutput,
  538. &errors, &retVal, sourceDirectory, 0 /*this->TimeOut*/);
  539. ofs << " Output: " << partialOutput.c_str() << std::endl;
  540. ofs << " Errors: " << errors.c_str() << std::endl;
  541. goutput += partialOutput;
  542. res = res && res1;
  543. ofs << " Total output of update: " << goutput.c_str() << std::endl;
  544. }
  545. }
  546. if ( ofs )
  547. {
  548. ofs << "--- Update repository ---" << std::endl;
  549. ofs << goutput << std::endl;
  550. }
  551. }
  552. if ( !res || retVal )
  553. {
  554. updateProducedError = true;
  555. checkoutErrorMessages += " " + goutput;
  556. }
  557. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  558. << "<Update mode=\"Client\" Generator=\"ctest-"
  559. << cmVersion::GetCMakeVersion() << "\">\n"
  560. << "\t<Site>" << this->CTest->GetCTestConfiguration("Site") << "</Site>\n"
  561. << "\t<BuildName>" << this->CTest->GetCTestConfiguration("BuildName")
  562. << "</BuildName>\n"
  563. << "\t<BuildStamp>" << this->CTest->GetCurrentTag() << "-"
  564. << this->CTest->GetTestModelString() << "</BuildStamp>" << std::endl;
  565. os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
  566. << "\t<StartTime>" << start_time_time << "</StartTime>\n"
  567. << "\t<UpdateCommand>" << this->CTest->MakeXMLSafe(command)
  568. << "</UpdateCommand>\n"
  569. << "\t<UpdateType>" << this->CTest->MakeXMLSafe(
  570. cmCTestUpdateHandlerUpdateToString(updateType))
  571. << "</UpdateType>\n";
  572. // Even though it failed, we may have some useful information. Try to
  573. // continue...
  574. std::vector<cmStdString> lines;
  575. cmSystemTools::Split(goutput.c_str(), lines);
  576. std::vector<cmStdString> errLines;
  577. cmSystemTools::Split(errors.c_str(), errLines);
  578. lines.insert(lines.end(), errLines.begin(), errLines.end());
  579. // CVS style regular expressions
  580. cmsys::RegularExpression cvs_date_author_regex(
  581. "^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
  582. cmsys::RegularExpression cvs_revision_regex("^revision +([^ ]*) *$");
  583. cmsys::RegularExpression cvs_end_of_file_regex(
  584. "^=========================================="
  585. "===================================$");
  586. cmsys::RegularExpression cvs_end_of_comment_regex(
  587. "^----------------------------$");
  588. // Subversion style regular expressions
  589. cmsys::RegularExpression svn_status_line_regex(
  590. "^ *([0-9]+) *([0-9]+) *([^ ]+) *([^ ][^\t\r\n]*)[ \t\r\n]*$");
  591. cmsys::RegularExpression svn_latest_revision_regex(
  592. "(Updated to|At) revision ([0-9]+)\\.");
  593. cmsys::RegularExpression file_removed_line(
  594. "cvs update: `(.*)' is no longer in the repository");
  595. cmsys::RegularExpression file_update_line("([A-Z]) *(.*)");
  596. std::string current_path = "<no-path>";
  597. bool first_file = true;
  598. cmCTestUpdateHandler::AuthorsToUpdatesMap authors_files_map;
  599. int numUpdated = 0;
  600. int numModiefied = 0;
  601. int numConflicting = 0;
  602. // In subversion, get the latest revision
  603. if ( updateType == cmCTestUpdateHandler::e_SVN )
  604. {
  605. for ( cc= 0; cc < lines.size(); cc ++ )
  606. {
  607. const char* line = lines[cc].c_str();
  608. if ( svn_latest_revision_regex.find(line) )
  609. {
  610. svn_latest_revision = atoi(
  611. svn_latest_revision_regex.match(2).c_str());
  612. }
  613. }
  614. if ( svn_latest_revision <= 0 )
  615. {
  616. cmCTestLog(this->CTest, ERROR_MESSAGE,
  617. "Problem determining the current "
  618. "revision of the repository from output:" << std::endl
  619. << goutput.c_str() << std::endl);
  620. }
  621. else
  622. {
  623. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  624. " Current revision of repository is: " << svn_latest_revision
  625. << std::endl);
  626. }
  627. }
  628. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  629. " Gathering version information (each . represents one updated file):"
  630. << std::endl);
  631. int file_count = 0;
  632. std::string removed_line;
  633. for ( cc= 0; cc < lines.size(); cc ++ )
  634. {
  635. const char* line = lines[cc].c_str();
  636. if ( file_removed_line.find(line) )
  637. {
  638. removed_line = "D " + file_removed_line.match(1);
  639. line = removed_line.c_str();
  640. }
  641. if ( file_update_line.find(line) )
  642. {
  643. if ( file_count == 0 )
  644. {
  645. cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << std::flush);
  646. }
  647. cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
  648. std::string upChar = file_update_line.match(1);
  649. std::string upFile = file_update_line.match(2);
  650. char mod = upChar[0];
  651. bool modifiedOrConflict = false;
  652. if ( mod == 'X')
  653. {
  654. continue;
  655. }
  656. if ( mod != 'M' && mod != 'C' && mod != 'G' )
  657. {
  658. count ++;
  659. modifiedOrConflict = true;
  660. }
  661. const char* file = upFile.c_str();
  662. cmCTestLog(this->CTest, DEBUG, "Line" << cc << ": " << mod << " - "
  663. << file << std::endl);
  664. std::string output;
  665. if ( modifiedOrConflict )
  666. {
  667. std::string logcommand;
  668. switch ( updateType )
  669. {
  670. case cmCTestUpdateHandler::e_CVS:
  671. logcommand = updateCommand + " -z3 log -N \"" + file + "\"";
  672. break;
  673. case cmCTestUpdateHandler::e_SVN:
  674. if ( svn_latest_revision > 0 &&
  675. svn_latest_revision > svn_current_revision )
  676. {
  677. cmOStringStream logCommandStream;
  678. logCommandStream << updateCommand << " log -r "
  679. << svn_current_revision << ":" << svn_latest_revision
  680. << " --xml \"" << file << "\"";
  681. logcommand = logCommandStream.str();
  682. }
  683. else
  684. {
  685. logcommand = updateCommand +
  686. " status --verbose \"" + file + "\"";
  687. svn_use_status = 1;
  688. }
  689. break;
  690. }
  691. cmCTestLog(this->CTest, DEBUG, "Do log: " << logcommand << std::endl);
  692. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  693. "* Get file update information: " << logcommand.c_str()
  694. << std::endl);
  695. ofs << "* Get log information for file: " << file << std::endl;
  696. ofs << " Command: " << logcommand.c_str() << std::endl;
  697. res = this->CTest->RunCommand(logcommand.c_str(), &output, &errors,
  698. &retVal, sourceDirectory, 0 /*this->TimeOut*/);
  699. ofs << " Output: " << output.c_str() << std::endl;
  700. ofs << " Errors: " << errors.c_str() << std::endl;
  701. if ( ofs )
  702. {
  703. ofs << output << std::endl;
  704. }
  705. }
  706. if ( res )
  707. {
  708. cmCTestLog(this->CTest, DEBUG, output << std::endl);
  709. std::string::size_type sline = 0;
  710. std::string srevision1 = "Unknown";
  711. std::string sdate1 = "Unknown";
  712. std::string sauthor1 = "Unknown";
  713. std::string semail1 = "Unknown";
  714. std::string comment1 = "";
  715. std::string srevision2 = "Unknown";
  716. std::string sdate2 = "Unknown";
  717. std::string sauthor2 = "Unknown";
  718. std::string comment2 = "";
  719. std::string semail2 = "Unknown";
  720. if ( updateType == cmCTestUpdateHandler::e_CVS )
  721. {
  722. bool have_first = false;
  723. bool have_second = false;
  724. std::vector<cmStdString> ulines;
  725. cmSystemTools::Split(output.c_str(), ulines);
  726. for ( kk = 0; kk < ulines.size(); kk ++ )
  727. {
  728. const char* clp = ulines[kk].c_str();
  729. if ( !have_second && !sline && cvs_revision_regex.find(clp) )
  730. {
  731. if ( !have_first )
  732. {
  733. srevision1 = cvs_revision_regex.match(1);
  734. }
  735. else
  736. {
  737. srevision2 = cvs_revision_regex.match(1);
  738. }
  739. }
  740. else if ( !have_second && !sline &&
  741. cvs_date_author_regex.find(clp) )
  742. {
  743. sline = kk + 1;
  744. if ( !have_first )
  745. {
  746. sdate1 = cvs_date_author_regex.match(1);
  747. sauthor1 = cvs_date_author_regex.match(2);
  748. }
  749. else
  750. {
  751. sdate2 = cvs_date_author_regex.match(1);
  752. sauthor2 = cvs_date_author_regex.match(2);
  753. }
  754. }
  755. else if ( sline && cvs_end_of_comment_regex.find(clp) ||
  756. cvs_end_of_file_regex.find(clp))
  757. {
  758. if ( !have_first )
  759. {
  760. have_first = true;
  761. }
  762. else if ( !have_second )
  763. {
  764. have_second = true;
  765. }
  766. sline = 0;
  767. }
  768. else if ( sline )
  769. {
  770. if ( !have_first )
  771. {
  772. comment1 += clp;
  773. comment1 += "\n";
  774. }
  775. else
  776. {
  777. comment2 += clp;
  778. comment2 += "\n";
  779. }
  780. }
  781. }
  782. }
  783. else if ( updateType == cmCTestUpdateHandler::e_SVN )
  784. {
  785. if ( svn_use_status )
  786. {
  787. cmOStringStream str;
  788. str << svn_current_revision;
  789. srevision1 = str.str();
  790. if (!svn_status_line_regex.find(output))
  791. {
  792. cmCTestLog(this->CTest, ERROR_MESSAGE,
  793. "Bad output from SVN status command: " << output
  794. << std::endl);
  795. }
  796. else if ( svn_status_line_regex.match(4) != file )
  797. {
  798. cmCTestLog(this->CTest, ERROR_MESSAGE,
  799. "Bad output from SVN status command. "
  800. "The file name returned: \""
  801. << svn_status_line_regex.match(4)
  802. << "\" was different than the file specified: \"" << file
  803. << "\"" << std::endl);
  804. }
  805. else
  806. {
  807. srevision1 = svn_status_line_regex.match(2);
  808. int latest_revision = atoi(
  809. svn_status_line_regex.match(2).c_str());
  810. if ( svn_current_revision < latest_revision )
  811. {
  812. srevision2 = str.str();
  813. }
  814. sauthor1 = svn_status_line_regex.match(3);
  815. }
  816. }
  817. else
  818. {
  819. cmCTestUpdateHandlerSVNXMLParser parser(this);
  820. if ( parser.Parse(output.c_str()) )
  821. {
  822. int minrev = parser.GetMinRevision();
  823. int maxrev = parser.GetMaxRevision();
  824. cmCTestUpdateHandlerSVNXMLParser::
  825. t_VectorOfCommits::iterator it;
  826. for ( it = parser.GetCommits()->begin();
  827. it != parser.GetCommits()->end();
  828. ++ it )
  829. {
  830. if ( it->Revision == maxrev )
  831. {
  832. cmOStringStream mRevStream;
  833. mRevStream << maxrev;
  834. srevision1 = mRevStream.str();
  835. sauthor1 = it->Author;
  836. comment1 = it->Message;
  837. sdate1 = it->Date;
  838. }
  839. else if ( it->Revision == minrev )
  840. {
  841. cmOStringStream mRevStream;
  842. mRevStream << minrev;
  843. srevision2 = mRevStream.str();
  844. sauthor2 = it->Author;
  845. comment2 = it->Message;
  846. sdate2 = it->Date;
  847. }
  848. }
  849. }
  850. }
  851. }
  852. if ( mod == 'M' )
  853. {
  854. comment1 = "Locally modified file\n";
  855. sauthor1 = "Local User";
  856. }
  857. if ( mod == 'D' )
  858. {
  859. comment1 += " - Removed file\n";
  860. }
  861. if ( mod == 'C' )
  862. {
  863. comment1 = "Conflict while updating\n";
  864. sauthor1 = "Local User";
  865. }
  866. std::string path = cmSystemTools::GetFilenamePath(file);
  867. std::string fname = cmSystemTools::GetFilenameName(file);
  868. if ( path != current_path )
  869. {
  870. if ( !first_file )
  871. {
  872. os << "\t</Directory>" << std::endl;
  873. }
  874. else
  875. {
  876. first_file = false;
  877. }
  878. os << "\t<Directory>\n"
  879. << "\t\t<Name>" << path << "</Name>" << std::endl;
  880. }
  881. if ( mod == 'C' )
  882. {
  883. numConflicting ++;
  884. os << "\t<Conflicting>" << std::endl;
  885. }
  886. else if ( mod == 'G' )
  887. {
  888. numConflicting ++;
  889. os << "\t<Conflicting>" << std::endl;
  890. }
  891. else if ( mod == 'M' )
  892. {
  893. numModiefied ++;
  894. os << "\t<Modified>" << std::endl;
  895. }
  896. else
  897. {
  898. numUpdated ++;
  899. os << "\t<Updated>" << std::endl;
  900. }
  901. if ( srevision2 == "Unknown" )
  902. {
  903. srevision2 = srevision1;
  904. }
  905. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "File: "
  906. << path.c_str() << " / " << fname.c_str() << " was updated by "
  907. << sauthor1.c_str() << " to revision: " << srevision1.c_str()
  908. << " from revision: " << srevision2.c_str() << std::endl);
  909. os << "\t\t<File Directory=\"" << cmCTest::MakeXMLSafe(path) << "\">"
  910. << cmCTest::MakeXMLSafe(fname)
  911. << "</File>\n"
  912. << "\t\t<Directory>" << cmCTest::MakeXMLSafe(path)
  913. << "</Directory>\n"
  914. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(file) << "</FullName>\n"
  915. << "\t\t<CheckinDate>" << cmCTest::MakeXMLSafe(sdate1)
  916. << "</CheckinDate>\n"
  917. << "\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1) << "</Author>\n"
  918. << "\t\t<Email>" << cmCTest::MakeXMLSafe(semail1) << "</Email>\n"
  919. << "\t\t<Log>" << cmCTest::MakeXMLSafe(comment1) << "</Log>\n"
  920. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  921. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  922. << std::endl;
  923. if ( srevision2 != srevision1 )
  924. {
  925. os
  926. << "\t\t<Revisions>\n"
  927. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  928. << "\t\t\t<PreviousRevision>" << srevision2
  929. << "</PreviousRevision>\n"
  930. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1)
  931. << "</Author>\n"
  932. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate1)
  933. << "</Date>\n"
  934. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment1)
  935. << "</Comment>\n"
  936. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail1)
  937. << "</Email>\n"
  938. << "\t\t</Revisions>\n"
  939. << "\t\t<Revisions>\n"
  940. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  941. << "\t\t\t<PreviousRevision>" << srevision2
  942. << "</PreviousRevision>\n"
  943. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor2)
  944. << "</Author>\n"
  945. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate2)
  946. << "</Date>\n"
  947. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment2)
  948. << "</Comment>\n"
  949. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail2)
  950. << "</Email>\n"
  951. << "\t\t</Revisions>" << std::endl;
  952. }
  953. if ( mod == 'C' )
  954. {
  955. os << "\t</Conflicting>" << std::endl;
  956. }
  957. else if ( mod == 'G' )
  958. {
  959. os << "\t</Conflicting>" << std::endl;
  960. }
  961. else if ( mod == 'M' )
  962. {
  963. os << "\t</Modified>" << std::endl;
  964. }
  965. else
  966. {
  967. os << "\t</Updated>" << std::endl;
  968. }
  969. cmCTestUpdateHandler::UpdateFiles *u = &authors_files_map[sauthor1];
  970. cmCTestUpdateHandler::StringPair p;
  971. p.first = path;
  972. p.second = fname;
  973. u->push_back(p);
  974. current_path = path;
  975. }
  976. file_count ++;
  977. }
  978. }
  979. if ( file_count )
  980. {
  981. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
  982. }
  983. if ( numUpdated )
  984. {
  985. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Found " << numUpdated
  986. << " updated files" << std::endl);
  987. }
  988. if ( numModiefied )
  989. {
  990. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Found " << numModiefied
  991. << " locally modified files"
  992. << std::endl);
  993. }
  994. if ( numConflicting )
  995. {
  996. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Found " << numConflicting
  997. << " conflicting files"
  998. << std::endl);
  999. }
  1000. if ( numModiefied == 0 && numConflicting == 0 && numUpdated == 0 )
  1001. {
  1002. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Project is up-to-date"
  1003. << std::endl);
  1004. }
  1005. if ( !first_file )
  1006. {
  1007. os << "\t</Directory>" << std::endl;
  1008. }
  1009. cmCTestUpdateHandler::AuthorsToUpdatesMap::iterator it;
  1010. for ( it = authors_files_map.begin();
  1011. it != authors_files_map.end();
  1012. it ++ )
  1013. {
  1014. os << "\t<Author>\n"
  1015. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  1016. cmCTestUpdateHandler::UpdateFiles *u = &(it->second);
  1017. for ( cc = 0; cc < u->size(); cc ++ )
  1018. {
  1019. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  1020. << (*u)[cc].second << "</File>" << std::endl;
  1021. }
  1022. os << "\t</Author>" << std::endl;
  1023. }
  1024. cmCTestLog(this->CTest, DEBUG, "End" << std::endl);
  1025. std::string end_time = this->CTest->CurrentTime();
  1026. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  1027. << "\t<EndTime>" << static_cast<unsigned int>(cmSystemTools::GetTime())
  1028. << "</EndTime>\n"
  1029. << "<ElapsedMinutes>" <<
  1030. static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  1031. << "</ElapsedMinutes>\n"
  1032. << "\t<UpdateReturnStatus>";
  1033. if ( numModiefied > 0 || numConflicting > 0 )
  1034. {
  1035. os << "Update error: There are modified or conflicting files in the "
  1036. "repository";
  1037. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1038. " There are modified or conflicting files in the repository"
  1039. << std::endl);
  1040. }
  1041. if ( updateProducedError )
  1042. {
  1043. os << "Update error: ";
  1044. os << this->CTest->MakeXMLSafe(checkoutErrorMessages);
  1045. cmCTestLog(this->CTest, ERROR_MESSAGE, " Update with command: "
  1046. << command << " failed" << std::endl);
  1047. }
  1048. os << "</UpdateReturnStatus>" << std::endl;
  1049. os << "</Update>" << std::endl;
  1050. if (! res )
  1051. {
  1052. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1053. "Error(s) when updating the project" << std::endl);
  1054. cmCTestLog(this->CTest, ERROR_MESSAGE, "Output: "
  1055. << goutput << std::endl);
  1056. return -1;
  1057. }
  1058. return count;
  1059. }