cmCTestUpdateHandler.cxx 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  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 || type >= cmCTestUpdateHandler::e_LAST )
  41. {
  42. return cmCTestUpdateHandlerUpdateStrings[cmCTestUpdateHandler::e_UNKNOWN];
  43. }
  44. return cmCTestUpdateHandlerUpdateStrings[type];
  45. }
  46. //----------------------------------------------------------------------
  47. //**********************************************************************
  48. class cmCTestUpdateHandlerSVNXMLParser : public cmXMLParser
  49. {
  50. public:
  51. struct t_CommitLog
  52. {
  53. int m_Revision;
  54. std::string m_Author;
  55. std::string m_Date;
  56. std::string m_Message;
  57. };
  58. cmCTestUpdateHandlerSVNXMLParser(cmCTestUpdateHandler* up)
  59. : cmXMLParser(), m_UpdateHandler(up), m_MinRevision(-1), m_MaxRevision(-1)
  60. {
  61. }
  62. int Parse(const char* str)
  63. {
  64. m_MinRevision = -1;
  65. m_MaxRevision = -1;
  66. int res = this->cmXMLParser::Parse(str);
  67. if ( m_MinRevision == -1 || m_MaxRevision == -1 )
  68. {
  69. return 0;
  70. }
  71. return res;
  72. }
  73. typedef std::vector<t_CommitLog> t_VectorOfCommits;
  74. t_VectorOfCommits* GetCommits() { return &m_Commits; }
  75. int GetMinRevision() { return m_MinRevision; }
  76. int GetMaxRevision() { return m_MaxRevision; }
  77. protected:
  78. void StartElement(const char* name, const char** atts)
  79. {
  80. if ( strcmp(name, "logentry") == 0 )
  81. {
  82. m_CommitLog = t_CommitLog();
  83. const char* rev = this->FindAttribute(atts, "revision");
  84. if ( rev)
  85. {
  86. m_CommitLog.m_Revision = atoi(rev);
  87. if ( m_MinRevision < 0 || m_MinRevision > m_CommitLog.m_Revision )
  88. {
  89. m_MinRevision = m_CommitLog.m_Revision;
  90. }
  91. if ( m_MaxRevision < 0 || m_MaxRevision < m_CommitLog.m_Revision )
  92. {
  93. m_MaxRevision = m_CommitLog.m_Revision;
  94. }
  95. }
  96. }
  97. m_CharacterData.erase(m_CharacterData.begin(), m_CharacterData.end());
  98. }
  99. void EndElement(const char* name)
  100. {
  101. if ( strcmp(name, "logentry") == 0 )
  102. {
  103. cmCTestLog(m_UpdateHandler->GetCTestInstance(), HANDLER_VERBOSE_OUTPUT, "\tRevision: " << m_CommitLog.m_Revision<< std::endl
  104. << "\tAuthor: " << m_CommitLog.m_Author.c_str() << std::endl
  105. << "\tDate: " << m_CommitLog.m_Date.c_str() << std::endl
  106. << "\tMessage: " << m_CommitLog.m_Message.c_str() << std::endl);
  107. m_Commits.push_back(m_CommitLog);
  108. }
  109. else if ( strcmp(name, "author") == 0 )
  110. {
  111. m_CommitLog.m_Author.assign(&(*(m_CharacterData.begin())), m_CharacterData.size());
  112. }
  113. else if ( strcmp(name, "date") == 0 )
  114. {
  115. m_CommitLog.m_Date.assign(&(*(m_CharacterData.begin())), m_CharacterData.size());
  116. }
  117. else if ( strcmp(name, "msg") == 0 )
  118. {
  119. m_CommitLog.m_Message.assign(&(*(m_CharacterData.begin())), m_CharacterData.size());
  120. }
  121. m_CharacterData.erase(m_CharacterData.begin(), m_CharacterData.end());
  122. }
  123. void CharacterDataHandler(const char* data, int length)
  124. {
  125. m_CharacterData.insert(m_CharacterData.end(), data, data+length);
  126. }
  127. const char* FindAttribute( const char** atts, const char* attribute )
  128. {
  129. if ( !atts || !attribute )
  130. {
  131. return 0;
  132. }
  133. const char **atr = atts;
  134. while ( *atr && **atr && **(atr+1) )
  135. {
  136. if ( strcmp(*atr, attribute) == 0 )
  137. {
  138. return *(atr+1);
  139. }
  140. atr+=2;
  141. }
  142. return 0;
  143. }
  144. private:
  145. std::vector<char> m_CharacterData;
  146. cmCTestUpdateHandler* m_UpdateHandler;
  147. t_CommitLog m_CommitLog;
  148. t_VectorOfCommits m_Commits;
  149. int m_MinRevision;
  150. int m_MaxRevision;
  151. };
  152. //**********************************************************************
  153. //----------------------------------------------------------------------
  154. //----------------------------------------------------------------------
  155. cmCTestUpdateHandler::cmCTestUpdateHandler()
  156. {
  157. }
  158. //----------------------------------------------------------------------
  159. void cmCTestUpdateHandler::Initialize()
  160. {
  161. this->Superclass::Initialize();
  162. }
  163. //----------------------------------------------------------------------
  164. int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
  165. {
  166. cmCTestLog(m_CTest, DEBUG, "Determine update type from command: " << cmd << " and type: " << type << std::endl);
  167. if ( type && *type )
  168. {
  169. cmCTestLog(m_CTest, DEBUG, "Type specified: " << type << std::endl);
  170. std::string stype = cmSystemTools::LowerCase(type);
  171. if ( stype.find("cvs") != std::string::npos )
  172. {
  173. return cmCTestUpdateHandler::e_CVS;
  174. }
  175. if ( stype.find("svn") != std::string::npos )
  176. {
  177. return cmCTestUpdateHandler::e_SVN;
  178. }
  179. }
  180. else
  181. {
  182. cmCTestLog(m_CTest, DEBUG, "Type not specified, check command: " << cmd << std::endl);
  183. std::string stype = cmSystemTools::LowerCase(cmd);
  184. if ( stype.find("cvs") != std::string::npos )
  185. {
  186. return cmCTestUpdateHandler::e_CVS;
  187. }
  188. if ( stype.find("svn") != std::string::npos )
  189. {
  190. return cmCTestUpdateHandler::e_SVN;
  191. }
  192. }
  193. std::string sourceDirectory = this->GetOption("SourceDirectory");
  194. cmCTestLog(m_CTest, DEBUG, "Check directory: " << sourceDirectory.c_str() << std::endl);
  195. sourceDirectory += "/.svn";
  196. if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
  197. {
  198. return cmCTestUpdateHandler::e_SVN;
  199. }
  200. sourceDirectory = this->GetOption("SourceDirectory");
  201. sourceDirectory += "/CVS";
  202. if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
  203. {
  204. return cmCTestUpdateHandler::e_CVS;
  205. }
  206. return cmCTestUpdateHandler::e_UNKNOWN;
  207. }
  208. //----------------------------------------------------------------------
  209. //clearly it would be nice if this were broken up into a few smaller
  210. //functions and commented...
  211. int cmCTestUpdateHandler::ProcessHandler()
  212. {
  213. int count = 0;
  214. int updateType = e_CVS;
  215. std::string::size_type cc, kk;
  216. bool updateProducedError = false;
  217. std::string goutput;
  218. std::string errors;
  219. std::string checkoutErrorMessages;
  220. int retVal = 0;
  221. // Get source dir
  222. const char* sourceDirectory = this->GetOption("SourceDirectory");
  223. if ( !sourceDirectory )
  224. {
  225. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl);
  226. return -1;
  227. }
  228. cmGeneratedFileStream ofs;
  229. if ( !m_CTest->GetShowOnly() )
  230. {
  231. this->StartLogFile("Update", ofs);
  232. }
  233. cmCTestLog(m_CTest, HANDLER_OUTPUT, "Updating the repository" << std::endl);
  234. const char* initialCheckoutCommand = this->GetOption("InitialCheckout");
  235. if ( initialCheckoutCommand )
  236. {
  237. cmCTestLog(m_CTest, HANDLER_OUTPUT, " First perform the initil checkout: " << initialCheckoutCommand << std::endl);
  238. cmStdString parent = cmSystemTools::GetParentDirectory(sourceDirectory);
  239. if ( parent.empty() )
  240. {
  241. cmCTestLog(m_CTest, ERROR_MESSAGE,
  242. "Something went wrong when trying to determine the parent directory of " << sourceDirectory << std::endl);
  243. return -1;
  244. }
  245. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Perform checkout in directory: " << parent.c_str() << std::endl);
  246. if ( !cmSystemTools::MakeDirectory(parent.c_str()) )
  247. {
  248. cmCTestLog(m_CTest, ERROR_MESSAGE,
  249. "Cannot create parent directory: " << parent.c_str() << " of the source directory: " << sourceDirectory << std::endl);
  250. return -1;
  251. }
  252. ofs << "* Run initial checkout" << std::endl;
  253. ofs << " Command: " << initialCheckoutCommand << std::endl;
  254. cmCTestLog(m_CTest, DEBUG, " Before: " << initialCheckoutCommand << std::endl);
  255. bool retic = m_CTest->RunCommand(initialCheckoutCommand, &goutput, &errors, &retVal, parent.c_str(), 0 /* Timeout */);
  256. cmCTestLog(m_CTest, DEBUG, " After: " << initialCheckoutCommand << std::endl);
  257. ofs << " Output: " << goutput.c_str() << std::endl;
  258. ofs << " Errors: " << errors.c_str() << std::endl;
  259. if ( !retic || retVal )
  260. {
  261. cmOStringStream ostr;
  262. ostr << "Problem running initial checkout Output [" << goutput << "] Errors [" << errors << "]";
  263. cmCTestLog(m_CTest, HANDLER_OUTPUT, ostr.str().c_str() << std::endl);
  264. checkoutErrorMessages += ostr.str();
  265. updateProducedError = true;
  266. }
  267. m_CTest->InitializeFromCommand(m_Command);
  268. }
  269. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Updating the repository: " << sourceDirectory << std::endl);
  270. // Get update command
  271. std::string updateCommand = m_CTest->GetCTestConfiguration("UpdateCommand");
  272. if ( updateCommand.empty() )
  273. {
  274. updateCommand = m_CTest->GetCTestConfiguration("CVSCommand");
  275. if ( updateCommand.empty() )
  276. {
  277. updateCommand = m_CTest->GetCTestConfiguration("SVNCommand");
  278. if ( updateCommand.empty() )
  279. {
  280. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot find CVSCommand, SVNCommand, or UpdateCommand key in the DartConfiguration.tcl" << std::endl);
  281. return -1;
  282. }
  283. else
  284. {
  285. updateType = e_SVN;
  286. }
  287. }
  288. else
  289. {
  290. updateType = e_CVS;
  291. }
  292. }
  293. else
  294. {
  295. updateType = this->DetermineType(updateCommand.c_str(), m_CTest->GetCTestConfiguration("UpdateType").c_str());
  296. }
  297. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Use " << cmCTestUpdateHandlerUpdateToString(updateType) << " repository type" << std::endl;);
  298. // And update options
  299. std::string updateOptions = m_CTest->GetCTestConfiguration("UpdateOptions");
  300. if ( updateOptions.empty() )
  301. {
  302. switch (updateType)
  303. {
  304. case cmCTestUpdateHandler::e_CVS:
  305. updateOptions = m_CTest->GetCTestConfiguration("CVSUpdateOptions");
  306. if ( updateOptions.empty() )
  307. {
  308. updateOptions = "-dP";
  309. }
  310. break;
  311. case cmCTestUpdateHandler::e_SVN:
  312. updateOptions = m_CTest->GetCTestConfiguration("SVNUpdateOptions");
  313. break;
  314. }
  315. }
  316. // Get update time
  317. std::string extra_update_opts;
  318. if ( m_CTest->GetTestModel() == cmCTest::NIGHTLY )
  319. {
  320. struct tm* t = m_CTest->GetNightlyTime(m_CTest->GetCTestConfiguration("NightlyStartTime"),
  321. m_CTest->GetTomorrowTag());
  322. char current_time[1024];
  323. sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d",
  324. t->tm_year + 1900,
  325. t->tm_mon + 1,
  326. t->tm_mday,
  327. t->tm_hour,
  328. t->tm_min,
  329. t->tm_sec);
  330. std::string today_update_date = current_time;
  331. // TODO: SVN
  332. switch ( updateType )
  333. {
  334. case cmCTestUpdateHandler::e_CVS:
  335. extra_update_opts += "-D \"" + today_update_date +" UTC\"";
  336. break;
  337. case cmCTestUpdateHandler::e_SVN:
  338. extra_update_opts += "-r \"{" + today_update_date +" +0000}\"";
  339. break;
  340. }
  341. }
  342. updateCommand = "\"" + updateCommand + "\"";
  343. // First, check what the current state of repository is
  344. std::string command = "";
  345. switch( updateType )
  346. {
  347. case cmCTestUpdateHandler::e_CVS:
  348. // TODO: CVS - for now just leave empty
  349. break;
  350. case cmCTestUpdateHandler::e_SVN:
  351. command = updateCommand + " info";
  352. break;
  353. }
  354. // CVS variables
  355. // SVN variables
  356. int svn_current_revision = 0;
  357. int svn_latest_revision = 0;
  358. int svn_use_status = 0;
  359. bool res = true;
  360. //
  361. // Get initial repository information if that is possible. With subversion, this will check the current revision.
  362. //
  363. if ( !command.empty() )
  364. {
  365. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "* Get repository information: " << command.c_str() << std::endl);
  366. if ( !m_CTest->GetShowOnly() )
  367. {
  368. ofs << "* Get repository information" << std::endl;
  369. ofs << " Command: " << command.c_str() << std::endl;
  370. res = m_CTest->RunCommand(command.c_str(), &goutput, &errors,
  371. &retVal, sourceDirectory, 0 /*m_TimeOut*/);
  372. ofs << " Output: " << goutput.c_str() << std::endl;
  373. ofs << " Errors: " << errors.c_str() << std::endl;
  374. if ( ofs )
  375. {
  376. ofs << "--- Update information ---" << std::endl;
  377. ofs << goutput << std::endl;
  378. }
  379. switch ( updateType )
  380. {
  381. case cmCTestUpdateHandler::e_CVS:
  382. // TODO: CVS - for now just leave empty
  383. break;
  384. case cmCTestUpdateHandler::e_SVN:
  385. {
  386. cmsys::RegularExpression current_revision_regex("Revision: ([0-9]+)");
  387. if ( current_revision_regex.find(goutput.c_str()) )
  388. {
  389. std::string currentRevisionString = current_revision_regex.match(1);
  390. svn_current_revision = atoi(currentRevisionString.c_str());
  391. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Old revision of repository is: " << svn_current_revision << std::endl);
  392. }
  393. }
  394. break;
  395. }
  396. }
  397. else
  398. {
  399. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Update with command: " << command << std::endl);
  400. }
  401. }
  402. //
  403. // Now update repository and remember what files were updated
  404. //
  405. cmGeneratedFileStream os;
  406. if ( !this->StartResultingXML("Update", os) )
  407. {
  408. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot open log file" << std::endl);
  409. }
  410. std::string start_time = m_CTest->CurrentTime();
  411. double elapsed_time_start = cmSystemTools::GetTime();
  412. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "* Update repository: " << command.c_str() << std::endl);
  413. if ( !m_CTest->GetShowOnly() )
  414. {
  415. command = "";
  416. switch( updateType )
  417. {
  418. case cmCTestUpdateHandler::e_CVS:
  419. command = updateCommand + " -z3 update " + updateOptions +
  420. " " + extra_update_opts;
  421. ofs << "* Update repository: " << std::endl;
  422. ofs << " Command: " << command.c_str() << std::endl;
  423. res = m_CTest->RunCommand(command.c_str(), &goutput, &errors,
  424. &retVal, sourceDirectory, 0 /*m_TimeOut*/);
  425. ofs << " Output: " << goutput.c_str() << std::endl;
  426. ofs << " Errors: " << errors.c_str() << std::endl;
  427. break;
  428. case cmCTestUpdateHandler::e_SVN:
  429. {
  430. std::string partialOutput;
  431. command = updateCommand + " update " + updateOptions +
  432. " " + extra_update_opts;
  433. ofs << "* Update repository: " << std::endl;
  434. ofs << " Command: " << command.c_str() << std::endl;
  435. bool res1 = m_CTest->RunCommand(command.c_str(), &partialOutput, &errors,
  436. &retVal, sourceDirectory, 0 /*m_TimeOut*/);
  437. ofs << " Output: " << partialOutput.c_str() << std::endl;
  438. ofs << " Errors: " << errors.c_str() << std::endl;
  439. goutput = partialOutput;
  440. command = updateCommand + " status";
  441. ofs << "* Status repository: " << std::endl;
  442. ofs << " Command: " << command.c_str() << std::endl;
  443. res = m_CTest->RunCommand(command.c_str(), &partialOutput, &errors,
  444. &retVal, sourceDirectory, 0 /*m_TimeOut*/);
  445. ofs << " Output: " << partialOutput.c_str() << std::endl;
  446. ofs << " Errors: " << errors.c_str() << std::endl;
  447. goutput += partialOutput;
  448. res = res && res1;
  449. ofs << " Total output of update: " << goutput.c_str() << std::endl;
  450. }
  451. }
  452. if ( ofs )
  453. {
  454. ofs << "--- Update repository ---" << std::endl;
  455. ofs << goutput << std::endl;;
  456. }
  457. }
  458. if ( !res || retVal )
  459. {
  460. updateProducedError = true;
  461. checkoutErrorMessages += " " + goutput;
  462. }
  463. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  464. << "<Update mode=\"Client\" Generator=\"ctest-"
  465. << cmVersion::GetCMakeVersion() << "\">\n"
  466. << "\t<Site>" << m_CTest->GetCTestConfiguration("Site") << "</Site>\n"
  467. << "\t<BuildName>" << m_CTest->GetCTestConfiguration("BuildName")
  468. << "</BuildName>\n"
  469. << "\t<BuildStamp>" << m_CTest->GetCurrentTag() << "-"
  470. << m_CTest->GetTestModelString() << "</BuildStamp>" << std::endl;
  471. os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
  472. << "\t<UpdateCommand>" << m_CTest->MakeXMLSafe(command)
  473. << "</UpdateCommand>\n"
  474. << "\t<UpdateType>" << m_CTest->MakeXMLSafe(cmCTestUpdateHandlerUpdateToString(updateType))
  475. << "</UpdateType>\n";
  476. // Even though it failed, we may have some useful information. Try to continue...
  477. std::vector<cmStdString> lines;
  478. cmSystemTools::Split(goutput.c_str(), lines);
  479. std::vector<cmStdString> errLines;
  480. cmSystemTools::Split(errors.c_str(), errLines);
  481. lines.insert(lines.end(), errLines.begin(), errLines.end());
  482. // CVS style regular expressions
  483. cmsys::RegularExpression cvs_date_author_regex("^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
  484. cmsys::RegularExpression cvs_revision_regex("^revision +([^ ]*) *$");
  485. cmsys::RegularExpression cvs_end_of_file_regex("^=============================================================================$");
  486. cmsys::RegularExpression cvs_end_of_comment_regex("^----------------------------$");
  487. // Subversion style regular expressions
  488. cmsys::RegularExpression svn_status_line_regex("^ *([0-9]+) *([0-9]+) *([^ ]+) *([^ ][^\t\r\n]*)[ \t\r\n]*$");
  489. cmsys::RegularExpression svn_latest_revision_regex("(Updated to|At) revision ([0-9]+)\\.");
  490. cmsys::RegularExpression file_removed_line("cvs update: `(.*)' is no longer in the repository");
  491. cmsys::RegularExpression file_update_line("([A-Z]) *(.*)");
  492. std::string current_path = "<no-path>";
  493. bool first_file = true;
  494. cmCTestUpdateHandler::AuthorsToUpdatesMap authors_files_map;
  495. int num_updated = 0;
  496. int num_modified = 0;
  497. int num_conflicting = 0;
  498. // In subversion, get the latest revision
  499. if ( updateType == cmCTestUpdateHandler::e_SVN )
  500. {
  501. for ( cc= 0 ; cc < lines.size(); cc ++ )
  502. {
  503. const char* line = lines[cc].c_str();
  504. if ( svn_latest_revision_regex.find(line) )
  505. {
  506. svn_latest_revision = atoi(svn_latest_revision_regex.match(2).c_str());
  507. }
  508. }
  509. if ( svn_latest_revision <= 0 )
  510. {
  511. cmCTestLog(m_CTest, ERROR_MESSAGE, "Problem determining the current revision of the repository from output:" << std::endl << goutput.c_str() << std::endl);
  512. }
  513. else
  514. {
  515. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Current revision of repository is: " << svn_latest_revision << std::endl);
  516. }
  517. }
  518. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Gathering version information (each . represents one updated file):" << std::endl);
  519. int file_count = 0;
  520. std::string removed_line;
  521. for ( cc= 0 ; cc < lines.size(); cc ++ )
  522. {
  523. const char* line = lines[cc].c_str();
  524. if ( file_removed_line.find(line) )
  525. {
  526. removed_line = "D " + file_removed_line.match(1);
  527. line = removed_line.c_str();
  528. }
  529. if ( file_update_line.find(line) )
  530. {
  531. if ( file_count == 0 )
  532. {
  533. cmCTestLog(m_CTest, HANDLER_OUTPUT, " " << std::flush);
  534. }
  535. cmCTestLog(m_CTest, HANDLER_OUTPUT, "." << std::flush);
  536. std::string upChar = file_update_line.match(1);
  537. std::string upFile = file_update_line.match(2);
  538. char mod = upChar[0];
  539. bool modifiedOrConflict = false;
  540. if ( mod != 'M' && mod != 'C' && mod != 'G' )
  541. {
  542. count ++;
  543. modifiedOrConflict = true;
  544. }
  545. const char* file = upFile.c_str();
  546. cmCTestLog(m_CTest, DEBUG, "Line" << cc << ": " << mod << " - " << file << std::endl);
  547. std::string output;
  548. if ( modifiedOrConflict )
  549. {
  550. std::string logcommand;
  551. switch ( updateType )
  552. {
  553. case cmCTestUpdateHandler::e_CVS:
  554. logcommand = updateCommand + " -z3 log -N \"" + file + "\"";
  555. break;
  556. case cmCTestUpdateHandler::e_SVN:
  557. if ( svn_latest_revision > 0 && svn_latest_revision > svn_current_revision )
  558. {
  559. cmOStringStream logCommandStream;
  560. logCommandStream << updateCommand << " log -r " << svn_current_revision << ":" << svn_latest_revision
  561. << " --xml \"" << file << "\"";
  562. logcommand = logCommandStream.str();
  563. }
  564. else
  565. {
  566. logcommand = updateCommand + " status --verbose \"" + file + "\"";
  567. svn_use_status = 1;
  568. }
  569. break;
  570. }
  571. cmCTestLog(m_CTest, DEBUG, "Do log: " << logcommand << std::endl);
  572. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "* Get file update information: " << logcommand.c_str() << std::endl);
  573. ofs << "* Get log information for file: " << file << std::endl;
  574. ofs << " Command: " << logcommand.c_str() << std::endl;
  575. res = m_CTest->RunCommand(logcommand.c_str(), &output, &errors,
  576. &retVal, sourceDirectory, 0 /*m_TimeOut*/);
  577. ofs << " Output: " << output.c_str() << std::endl;
  578. ofs << " Errors: " << errors.c_str() << std::endl;
  579. if ( ofs )
  580. {
  581. ofs << output << std::endl;
  582. }
  583. }
  584. if ( res && retVal == 0)
  585. {
  586. cmCTestLog(m_CTest, DEBUG, output << std::endl);
  587. std::string::size_type sline = 0;
  588. std::string srevision1 = "Unknown";
  589. std::string sdate1 = "Unknown";
  590. std::string sauthor1 = "Unknown";
  591. std::string semail1 = "Unknown";
  592. std::string comment1 = "";
  593. std::string srevision2 = "Unknown";
  594. std::string sdate2 = "Unknown";
  595. std::string sauthor2 = "Unknown";
  596. std::string comment2 = "";
  597. std::string semail2 = "Unknown";
  598. if ( updateType == cmCTestUpdateHandler::e_CVS )
  599. {
  600. bool have_first = false;
  601. bool have_second = false;
  602. std::vector<cmStdString> ulines;
  603. cmSystemTools::Split(output.c_str(), ulines);
  604. for ( kk = 0; kk < ulines.size(); kk ++ )
  605. {
  606. const char* clp = ulines[kk].c_str();
  607. if ( !have_second && !sline && cvs_revision_regex.find(clp) )
  608. {
  609. if ( !have_first )
  610. {
  611. srevision1 = cvs_revision_regex.match(1);
  612. }
  613. else
  614. {
  615. srevision2 = cvs_revision_regex.match(1);
  616. }
  617. }
  618. else if ( !have_second && !sline && cvs_date_author_regex.find(clp) )
  619. {
  620. sline = kk + 1;
  621. if ( !have_first )
  622. {
  623. sdate1 = cvs_date_author_regex.match(1);
  624. sauthor1 = cvs_date_author_regex.match(2);
  625. }
  626. else
  627. {
  628. sdate2 = cvs_date_author_regex.match(1);
  629. sauthor2 = cvs_date_author_regex.match(2);
  630. }
  631. }
  632. else if ( sline && cvs_end_of_comment_regex.find(clp) || cvs_end_of_file_regex.find(clp))
  633. {
  634. if ( !have_first )
  635. {
  636. have_first = true;
  637. }
  638. else if ( !have_second )
  639. {
  640. have_second = true;
  641. }
  642. sline = 0;
  643. }
  644. else if ( sline )
  645. {
  646. if ( !have_first )
  647. {
  648. comment1 += clp;
  649. comment1 += "\n";
  650. }
  651. else
  652. {
  653. comment2 += clp;
  654. comment2 += "\n";
  655. }
  656. }
  657. }
  658. }
  659. else if ( updateType == cmCTestUpdateHandler::e_SVN )
  660. {
  661. if ( svn_use_status )
  662. {
  663. cmOStringStream str;
  664. str << svn_current_revision;
  665. srevision1 = str.str();
  666. if (!svn_status_line_regex.find(output))
  667. {
  668. cmCTestLog(m_CTest, ERROR_MESSAGE, "Bad output from SVN status command: " << output << std::endl);
  669. }
  670. else if ( svn_status_line_regex.match(4) != file )
  671. {
  672. cmCTestLog(m_CTest, ERROR_MESSAGE, "Bad output from SVN status command. The file name returned: \"" << svn_status_line_regex.match(4) << "\" was different than the file specified: \"" << file << "\"" << std::endl);
  673. }
  674. else
  675. {
  676. srevision1 = svn_status_line_regex.match(2);
  677. int latest_revision = atoi(svn_status_line_regex.match(2).c_str());
  678. if ( svn_current_revision < latest_revision )
  679. {
  680. srevision2 = str.str();
  681. }
  682. sauthor1 = svn_status_line_regex.match(3);
  683. }
  684. }
  685. else
  686. {
  687. cmCTestUpdateHandlerSVNXMLParser parser(this);
  688. if ( parser.Parse(output.c_str()) )
  689. {
  690. int minrev = parser.GetMinRevision();
  691. int maxrev = parser.GetMaxRevision();
  692. cmCTestUpdateHandlerSVNXMLParser::t_VectorOfCommits::iterator it;
  693. for ( it = parser.GetCommits()->begin();
  694. it != parser.GetCommits()->end();
  695. ++ it )
  696. {
  697. if ( it->m_Revision == maxrev )
  698. {
  699. cmOStringStream mRevStream;
  700. mRevStream << maxrev;
  701. srevision1 = mRevStream.str();
  702. sauthor1 = it->m_Author;
  703. comment1 = it->m_Message;
  704. sdate1 = it->m_Date;
  705. }
  706. else if ( it->m_Revision == minrev )
  707. {
  708. cmOStringStream mRevStream;
  709. mRevStream << minrev;
  710. srevision2 = mRevStream.str();
  711. sauthor2 = it->m_Author;
  712. comment2 = it->m_Message;
  713. sdate2 = it->m_Date;
  714. }
  715. }
  716. }
  717. }
  718. }
  719. if ( mod == 'M' )
  720. {
  721. comment1 = "Locally modified file\n";
  722. sauthor1 = "Local User";
  723. }
  724. if ( mod == 'D' )
  725. {
  726. comment1 += " - Removed file\n";
  727. }
  728. if ( mod == 'C' )
  729. {
  730. comment1 = "Conflict while updating\n";
  731. sauthor1 = "Local User";
  732. }
  733. std::string path = cmSystemTools::GetFilenamePath(file);
  734. std::string fname = cmSystemTools::GetFilenameName(file);
  735. if ( path != current_path )
  736. {
  737. if ( !first_file )
  738. {
  739. os << "\t</Directory>" << std::endl;
  740. }
  741. else
  742. {
  743. first_file = false;
  744. }
  745. os << "\t<Directory>\n"
  746. << "\t\t<Name>" << path << "</Name>" << std::endl;
  747. }
  748. if ( mod == 'C' )
  749. {
  750. num_conflicting ++;
  751. os << "\t<Conflicting>" << std::endl;
  752. }
  753. else if ( mod == 'G' )
  754. {
  755. num_conflicting ++;
  756. os << "\t<Conflicting>" << std::endl;
  757. }
  758. else if ( mod == 'M' )
  759. {
  760. num_modified ++;
  761. os << "\t<Modified>" << std::endl;
  762. }
  763. else
  764. {
  765. num_updated ++;
  766. os << "\t<Updated>" << std::endl;
  767. }
  768. if ( srevision2 == "Unknown" )
  769. {
  770. srevision2 = srevision1;
  771. }
  772. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "File: " << path.c_str() << " / " << fname.c_str() << " was updated by "
  773. << sauthor1.c_str() << " to revision: " << srevision1.c_str()
  774. << " from revision: " << srevision2.c_str() << std::endl);
  775. os << "\t\t<File Directory=\"" << cmCTest::MakeXMLSafe(path) << "\">" << cmCTest::MakeXMLSafe(fname)
  776. << "</File>\n"
  777. << "\t\t<Directory>" << cmCTest::MakeXMLSafe(path) << "</Directory>\n"
  778. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(file) << "</FullName>\n"
  779. << "\t\t<CheckinDate>" << cmCTest::MakeXMLSafe(sdate1) << "</CheckinDate>\n"
  780. << "\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1) << "</Author>\n"
  781. << "\t\t<Email>" << cmCTest::MakeXMLSafe(semail1) << "</Email>\n"
  782. << "\t\t<Log>" << cmCTest::MakeXMLSafe(comment1) << "</Log>\n"
  783. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  784. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  785. << std::endl;
  786. if ( srevision2 != srevision1 )
  787. {
  788. os
  789. << "\t\t<Revisions>\n"
  790. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  791. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  792. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1) << "</Author>\n"
  793. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate1) << "</Date>\n"
  794. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment1) << "</Comment>\n"
  795. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail1) << "</Email>\n"
  796. << "\t\t</Revisions>\n"
  797. << "\t\t<Revisions>\n"
  798. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  799. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  800. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor2) << "</Author>\n"
  801. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate2) << "</Date>\n"
  802. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment2) << "</Comment>\n"
  803. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail2) << "</Email>\n"
  804. << "\t\t</Revisions>" << std::endl;
  805. }
  806. if ( mod == 'C' )
  807. {
  808. os << "\t</Conflicting>" << std::endl;
  809. }
  810. else if ( mod == 'G' )
  811. {
  812. os << "\t</Conflicting>" << std::endl;
  813. }
  814. else if ( mod == 'M' )
  815. {
  816. os << "\t</Modified>" << std::endl;
  817. }
  818. else
  819. {
  820. os << "\t</Updated>" << std::endl;
  821. }
  822. cmCTestUpdateHandler::UpdateFiles *u = &authors_files_map[sauthor1];
  823. cmCTestUpdateHandler::StringPair p;
  824. p.first = path;
  825. p.second = fname;
  826. u->push_back(p);
  827. current_path = path;
  828. }
  829. file_count ++;
  830. }
  831. }
  832. if ( file_count )
  833. {
  834. cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl);
  835. }
  836. if ( num_updated )
  837. {
  838. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Found " << num_updated << " updated files" << std::endl);
  839. }
  840. if ( num_modified )
  841. {
  842. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Found " << num_modified << " locally modified files"
  843. << std::endl);
  844. }
  845. if ( num_conflicting )
  846. {
  847. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Found " << num_conflicting << " conflicting files"
  848. << std::endl);
  849. }
  850. if ( num_modified == 0 && num_conflicting == 0 && num_updated == 0 )
  851. {
  852. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Project is up-to-date" << std::endl);
  853. }
  854. if ( !first_file )
  855. {
  856. os << "\t</Directory>" << std::endl;
  857. }
  858. cmCTestUpdateHandler::AuthorsToUpdatesMap::iterator it;
  859. for ( it = authors_files_map.begin();
  860. it != authors_files_map.end();
  861. it ++ )
  862. {
  863. os << "\t<Author>\n"
  864. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  865. cmCTestUpdateHandler::UpdateFiles *u = &(it->second);
  866. for ( cc = 0; cc < u->size(); cc ++ )
  867. {
  868. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  869. << (*u)[cc].second << "</File>" << std::endl;
  870. }
  871. os << "\t</Author>" << std::endl;
  872. }
  873. cmCTestLog(m_CTest, DEBUG, "End" << std::endl);
  874. std::string end_time = m_CTest->CurrentTime();
  875. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  876. << "<ElapsedMinutes>" <<
  877. static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  878. << "</ElapsedMinutes>\n"
  879. << "\t<UpdateReturnStatus>";
  880. if ( num_modified > 0 || num_conflicting > 0 )
  881. {
  882. os << "Update error: There are modified or conflicting files in the repository";
  883. cmCTestLog(m_CTest, ERROR_MESSAGE, " There are modified or conflicting files in the repository" << std::endl);
  884. }
  885. if ( updateProducedError )
  886. {
  887. os << "Update error: ";
  888. os << m_CTest->MakeXMLSafe(checkoutErrorMessages);
  889. cmCTestLog(m_CTest, ERROR_MESSAGE, " Update with command: " << command << " failed" << std::endl);
  890. }
  891. os << "</UpdateReturnStatus>" << std::endl;
  892. os << "</Update>" << std::endl;
  893. if ( ofs )
  894. {
  895. ofs.close();
  896. }
  897. if (! res || retVal )
  898. {
  899. cmCTestLog(m_CTest, ERROR_MESSAGE, "Error(s) when updating the project" << std::endl);
  900. cmCTestLog(m_CTest, ERROR_MESSAGE, "Output: " << goutput << std::endl);
  901. return -1;
  902. }
  903. return count;
  904. }