cmCTestUpdateHandler.cxx 35 KB

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