cmCTestUpdateHandler.cxx 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  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 removed = false;
  540. if ( mod != 'D' )
  541. {
  542. removed = true;
  543. }
  544. bool modifiedOrConflict = false;
  545. if ( mod != 'M' && mod != 'C' && mod != 'G' )
  546. {
  547. count ++;
  548. modifiedOrConflict = true;
  549. }
  550. const char* file = upFile.c_str();
  551. cmCTestLog(m_CTest, DEBUG, "Line" << cc << ": " << mod << " - " << file << std::endl);
  552. std::string output;
  553. if ( modifiedOrConflict )
  554. {
  555. std::string logcommand;
  556. switch ( updateType )
  557. {
  558. case cmCTestUpdateHandler::e_CVS:
  559. logcommand = updateCommand + " -z3 log -N \"" + file + "\"";
  560. break;
  561. case cmCTestUpdateHandler::e_SVN:
  562. if ( svn_latest_revision > 0 && svn_latest_revision > svn_current_revision )
  563. {
  564. cmOStringStream logCommandStream;
  565. logCommandStream << updateCommand << " log -r " << svn_current_revision << ":" << svn_latest_revision
  566. << " --xml \"" << file << "\"";
  567. logcommand = logCommandStream.str();
  568. }
  569. else
  570. {
  571. logcommand = updateCommand + " status --verbose \"" + file + "\"";
  572. svn_use_status = 1;
  573. }
  574. break;
  575. }
  576. cmCTestLog(m_CTest, DEBUG, "Do log: " << logcommand << std::endl);
  577. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "* Get file update information: " << logcommand.c_str() << std::endl);
  578. ofs << "* Get log information for file: " << file << std::endl;
  579. ofs << " Command: " << logcommand.c_str() << std::endl;
  580. res = m_CTest->RunCommand(logcommand.c_str(), &output, &errors,
  581. &retVal, sourceDirectory, 0 /*m_TimeOut*/);
  582. ofs << " Output: " << output.c_str() << std::endl;
  583. ofs << " Errors: " << errors.c_str() << std::endl;
  584. if ( ofs )
  585. {
  586. ofs << output << std::endl;
  587. }
  588. }
  589. if ( res && retVal == 0)
  590. {
  591. cmCTestLog(m_CTest, DEBUG, output << std::endl);
  592. std::string::size_type sline = 0;
  593. std::string srevision1 = "Unknown";
  594. std::string sdate1 = "Unknown";
  595. std::string sauthor1 = "Unknown";
  596. std::string semail1 = "Unknown";
  597. std::string comment1 = "";
  598. std::string srevision2 = "Unknown";
  599. std::string sdate2 = "Unknown";
  600. std::string sauthor2 = "Unknown";
  601. std::string comment2 = "";
  602. std::string semail2 = "Unknown";
  603. if ( updateType == cmCTestUpdateHandler::e_CVS )
  604. {
  605. bool have_first = false;
  606. bool have_second = false;
  607. std::vector<cmStdString> ulines;
  608. cmSystemTools::Split(output.c_str(), ulines);
  609. for ( kk = 0; kk < ulines.size(); kk ++ )
  610. {
  611. const char* clp = ulines[kk].c_str();
  612. if ( !have_second && !sline && cvs_revision_regex.find(clp) )
  613. {
  614. if ( !have_first )
  615. {
  616. srevision1 = cvs_revision_regex.match(1);
  617. }
  618. else
  619. {
  620. srevision2 = cvs_revision_regex.match(1);
  621. }
  622. }
  623. else if ( !have_second && !sline && cvs_date_author_regex.find(clp) )
  624. {
  625. sline = kk + 1;
  626. if ( !have_first )
  627. {
  628. sdate1 = cvs_date_author_regex.match(1);
  629. sauthor1 = cvs_date_author_regex.match(2);
  630. }
  631. else
  632. {
  633. sdate2 = cvs_date_author_regex.match(1);
  634. sauthor2 = cvs_date_author_regex.match(2);
  635. }
  636. }
  637. else if ( sline && cvs_end_of_comment_regex.find(clp) || cvs_end_of_file_regex.find(clp))
  638. {
  639. if ( !have_first )
  640. {
  641. have_first = true;
  642. }
  643. else if ( !have_second )
  644. {
  645. have_second = true;
  646. }
  647. sline = 0;
  648. }
  649. else if ( sline )
  650. {
  651. if ( !have_first )
  652. {
  653. comment1 += clp;
  654. comment1 += "\n";
  655. }
  656. else
  657. {
  658. comment2 += clp;
  659. comment2 += "\n";
  660. }
  661. }
  662. }
  663. }
  664. else if ( updateType == cmCTestUpdateHandler::e_SVN )
  665. {
  666. if ( svn_use_status )
  667. {
  668. cmOStringStream str;
  669. str << svn_current_revision;
  670. srevision1 = str.str();
  671. if (!svn_status_line_regex.find(output))
  672. {
  673. cmCTestLog(m_CTest, ERROR_MESSAGE, "Bad output from SVN status command: " << output << std::endl);
  674. }
  675. else if ( svn_status_line_regex.match(4) != file )
  676. {
  677. 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);
  678. }
  679. else
  680. {
  681. srevision1 = svn_status_line_regex.match(2);
  682. int latest_revision = atoi(svn_status_line_regex.match(2).c_str());
  683. if ( svn_current_revision < latest_revision )
  684. {
  685. srevision2 = str.str();
  686. }
  687. sauthor1 = svn_status_line_regex.match(3);
  688. }
  689. }
  690. else
  691. {
  692. cmCTestUpdateHandlerSVNXMLParser parser(this);
  693. if ( parser.Parse(output.c_str()) )
  694. {
  695. int minrev = parser.GetMinRevision();
  696. int maxrev = parser.GetMaxRevision();
  697. cmCTestUpdateHandlerSVNXMLParser::t_VectorOfCommits::iterator it;
  698. for ( it = parser.GetCommits()->begin();
  699. it != parser.GetCommits()->end();
  700. ++ it )
  701. {
  702. if ( it->m_Revision == maxrev )
  703. {
  704. cmOStringStream mRevStream;
  705. mRevStream << maxrev;
  706. srevision1 = mRevStream.str();
  707. sauthor1 = it->m_Author;
  708. comment1 = it->m_Message;
  709. sdate1 = it->m_Date;
  710. }
  711. else if ( it->m_Revision == minrev )
  712. {
  713. cmOStringStream mRevStream;
  714. mRevStream << minrev;
  715. srevision2 = mRevStream.str();
  716. sauthor2 = it->m_Author;
  717. comment2 = it->m_Message;
  718. sdate2 = it->m_Date;
  719. }
  720. }
  721. }
  722. }
  723. }
  724. if ( mod == 'M' )
  725. {
  726. comment1 = "Locally modified file\n";
  727. sauthor1 = "Local User";
  728. }
  729. if ( mod == 'R' )
  730. {
  731. comment1 = "Removed file\n";
  732. }
  733. if ( mod == 'C' )
  734. {
  735. comment1 = "Conflict while updating\n";
  736. sauthor1 = "Local User";
  737. }
  738. std::string path = cmSystemTools::GetFilenamePath(file);
  739. std::string fname = cmSystemTools::GetFilenameName(file);
  740. if ( path != current_path )
  741. {
  742. if ( !first_file )
  743. {
  744. os << "\t</Directory>" << std::endl;
  745. }
  746. else
  747. {
  748. first_file = false;
  749. }
  750. os << "\t<Directory>\n"
  751. << "\t\t<Name>" << path << "</Name>" << std::endl;
  752. }
  753. if ( mod == 'C' )
  754. {
  755. num_conflicting ++;
  756. os << "\t<Conflicting>" << std::endl;
  757. }
  758. else if ( mod == 'G' )
  759. {
  760. num_conflicting ++;
  761. os << "\t<Conflicting>" << std::endl;
  762. }
  763. else if ( mod == 'M' )
  764. {
  765. num_modified ++;
  766. os << "\t<Modified>" << std::endl;
  767. }
  768. else
  769. {
  770. num_updated ++;
  771. os << "\t<Updated>" << std::endl;
  772. }
  773. if ( srevision2 == "Unknown" )
  774. {
  775. srevision2 = srevision1;
  776. }
  777. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "File: " << path.c_str() << " / " << fname.c_str() << " was updated by "
  778. << sauthor1.c_str() << " to revision: " << srevision1.c_str()
  779. << " from revision: " << srevision2.c_str() << std::endl);
  780. os << "\t\t<File Directory=\"" << cmCTest::MakeXMLSafe(path) << "\">" << cmCTest::MakeXMLSafe(fname)
  781. << "</File>\n"
  782. << "\t\t<Directory>" << cmCTest::MakeXMLSafe(path) << "</Directory>\n"
  783. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(file) << "</FullName>\n"
  784. << "\t\t<CheckinDate>" << cmCTest::MakeXMLSafe(sdate1) << "</CheckinDate>\n"
  785. << "\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1) << "</Author>\n"
  786. << "\t\t<Email>" << cmCTest::MakeXMLSafe(semail1) << "</Email>\n"
  787. << "\t\t<Log>" << cmCTest::MakeXMLSafe(comment1) << "</Log>\n"
  788. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  789. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  790. << std::endl;
  791. if ( srevision2 != srevision1 )
  792. {
  793. os
  794. << "\t\t<Revisions>\n"
  795. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  796. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  797. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1) << "</Author>\n"
  798. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate1) << "</Date>\n"
  799. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment1) << "</Comment>\n"
  800. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail1) << "</Email>\n"
  801. << "\t\t</Revisions>\n"
  802. << "\t\t<Revisions>\n"
  803. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  804. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  805. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor2) << "</Author>\n"
  806. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate2) << "</Date>\n"
  807. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment2) << "</Comment>\n"
  808. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail2) << "</Email>\n"
  809. << "\t\t</Revisions>" << std::endl;
  810. }
  811. if ( mod == 'C' )
  812. {
  813. os << "\t</Conflicting>" << std::endl;
  814. }
  815. else if ( mod == 'G' )
  816. {
  817. os << "\t</Conflicting>" << std::endl;
  818. }
  819. else if ( mod == 'M' )
  820. {
  821. os << "\t</Modified>" << std::endl;
  822. }
  823. else
  824. {
  825. os << "\t</Updated>" << std::endl;
  826. }
  827. cmCTestUpdateHandler::UpdateFiles *u = &authors_files_map[sauthor1];
  828. cmCTestUpdateHandler::StringPair p;
  829. p.first = path;
  830. p.second = fname;
  831. u->push_back(p);
  832. current_path = path;
  833. }
  834. file_count ++;
  835. }
  836. }
  837. if ( file_count )
  838. {
  839. cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl);
  840. }
  841. if ( num_updated )
  842. {
  843. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Found " << num_updated << " updated files" << std::endl);
  844. }
  845. if ( num_modified )
  846. {
  847. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Found " << num_modified << " locally modified files"
  848. << std::endl);
  849. }
  850. if ( num_conflicting )
  851. {
  852. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Found " << num_conflicting << " conflicting files"
  853. << std::endl);
  854. }
  855. if ( num_modified == 0 && num_conflicting == 0 && num_updated == 0 )
  856. {
  857. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Project is up-to-date" << std::endl);
  858. }
  859. if ( !first_file )
  860. {
  861. os << "\t</Directory>" << std::endl;
  862. }
  863. cmCTestUpdateHandler::AuthorsToUpdatesMap::iterator it;
  864. for ( it = authors_files_map.begin();
  865. it != authors_files_map.end();
  866. it ++ )
  867. {
  868. os << "\t<Author>\n"
  869. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  870. cmCTestUpdateHandler::UpdateFiles *u = &(it->second);
  871. for ( cc = 0; cc < u->size(); cc ++ )
  872. {
  873. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  874. << (*u)[cc].second << "</File>" << std::endl;
  875. }
  876. os << "\t</Author>" << std::endl;
  877. }
  878. cmCTestLog(m_CTest, DEBUG, "End" << std::endl);
  879. std::string end_time = m_CTest->CurrentTime();
  880. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  881. << "<ElapsedMinutes>" <<
  882. static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  883. << "</ElapsedMinutes>\n"
  884. << "\t<UpdateReturnStatus>";
  885. if ( num_modified > 0 || num_conflicting > 0 )
  886. {
  887. os << "Update error: There are modified or conflicting files in the repository";
  888. cmCTestLog(m_CTest, ERROR_MESSAGE, " There are modified or conflicting files in the repository" << std::endl);
  889. }
  890. if ( updateProducedError )
  891. {
  892. os << "Update error: ";
  893. os << m_CTest->MakeXMLSafe(checkoutErrorMessages);
  894. cmCTestLog(m_CTest, ERROR_MESSAGE, " Update with command: " << command << " failed" << std::endl);
  895. }
  896. os << "</UpdateReturnStatus>" << std::endl;
  897. os << "</Update>" << std::endl;
  898. if ( ofs )
  899. {
  900. ofs.close();
  901. }
  902. if (! res || retVal )
  903. {
  904. cmCTestLog(m_CTest, ERROR_MESSAGE, "Error(s) when updating the project" << std::endl);
  905. cmCTestLog(m_CTest, ERROR_MESSAGE, "Output: " << goutput << std::endl);
  906. return -1;
  907. }
  908. return count;
  909. }