cmCTestUpdateHandler.cxx 32 KB

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