cmCTestUpdateHandler.cxx 32 KB

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