cmCTestUpdateHandler.cxx 35 KB

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