cmCTestSVN.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. 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 "cmCTestSVN.h"
  14. #include "cmCTest.h"
  15. #include <cmsys/RegularExpression.hxx>
  16. //----------------------------------------------------------------------------
  17. cmCTestSVN::cmCTestSVN(cmCTest* ct, std::ostream& log): cmCTestVC(ct, log)
  18. {
  19. }
  20. //----------------------------------------------------------------------------
  21. cmCTestSVN::~cmCTestSVN()
  22. {
  23. }
  24. //----------------------------------------------------------------------------
  25. void cmCTestSVN::CleanupImpl()
  26. {
  27. const char* svn = this->CommandLineTool.c_str();
  28. const char* svn_cleanup[] = {svn, "cleanup", 0};
  29. OutputLogger out(this->Log, "cleanup-out> ");
  30. OutputLogger err(this->Log, "cleanup-err> ");
  31. this->RunChild(svn_cleanup, &out, &err);
  32. }
  33. //----------------------------------------------------------------------------
  34. class cmCTestSVN::InfoParser: public cmCTestVC::LineParser
  35. {
  36. public:
  37. InfoParser(cmCTestSVN* svn, const char* prefix, std::string& rev):
  38. SVN(svn), Rev(rev)
  39. {
  40. this->SetLog(&svn->Log, prefix);
  41. this->RegexRev.compile("^Revision: ([0-9]+)");
  42. this->RegexURL.compile("^URL: +([^ ]+) *$");
  43. this->RegexRoot.compile("^Repository Root: +([^ ]+) *$");
  44. }
  45. private:
  46. cmCTestSVN* SVN;
  47. std::string& Rev;
  48. cmsys::RegularExpression RegexRev;
  49. cmsys::RegularExpression RegexURL;
  50. cmsys::RegularExpression RegexRoot;
  51. virtual bool ProcessLine()
  52. {
  53. if(this->RegexRev.find(this->Line))
  54. {
  55. this->Rev = this->RegexRev.match(1);
  56. }
  57. else if(this->RegexURL.find(this->Line))
  58. {
  59. this->SVN->URL = this->RegexURL.match(1);
  60. }
  61. else if(this->RegexRoot.find(this->Line))
  62. {
  63. this->SVN->Root = this->RegexRoot.match(1);
  64. }
  65. return true;
  66. }
  67. };
  68. //----------------------------------------------------------------------------
  69. static bool cmCTestSVNPathStarts(std::string const& p1, std::string const& p2)
  70. {
  71. // Does path p1 start with path p2?
  72. if(p1.size() == p2.size())
  73. {
  74. return p1 == p2;
  75. }
  76. else if(p1.size() > p2.size() && p1[p2.size()] == '/')
  77. {
  78. return strncmp(p1.c_str(), p2.c_str(), p2.size()) == 0;
  79. }
  80. else
  81. {
  82. return false;
  83. }
  84. }
  85. //----------------------------------------------------------------------------
  86. std::string cmCTestSVN::LoadInfo()
  87. {
  88. // Run "svn info" to get the repository info from the work tree.
  89. const char* svn = this->CommandLineTool.c_str();
  90. const char* svn_info[] = {svn, "info", 0};
  91. std::string rev;
  92. InfoParser out(this, "info-out> ", rev);
  93. OutputLogger err(this->Log, "info-err> ");
  94. this->RunChild(svn_info, &out, &err);
  95. return rev;
  96. }
  97. //----------------------------------------------------------------------------
  98. void cmCTestSVN::NoteOldRevision()
  99. {
  100. this->OldRevision = this->LoadInfo();
  101. this->Log << "Revision before update: " << this->OldRevision << "\n";
  102. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Old revision of repository is: "
  103. << this->OldRevision << "\n");
  104. }
  105. //----------------------------------------------------------------------------
  106. void cmCTestSVN::NoteNewRevision()
  107. {
  108. this->NewRevision = this->LoadInfo();
  109. this->Log << "Revision after update: " << this->NewRevision << "\n";
  110. cmCTestLog(this->CTest, HANDLER_OUTPUT, " New revision of repository is: "
  111. << this->NewRevision << "\n");
  112. this->Log << "URL = " << this->URL << "\n";
  113. this->Log << "Root = " << this->Root << "\n";
  114. // Compute the base path the working tree has checked out under
  115. // the repository root.
  116. if(!this->Root.empty() && cmCTestSVNPathStarts(this->URL, this->Root))
  117. {
  118. this->Base = cmCTest::DecodeURL(this->URL.substr(this->Root.size()));
  119. this->Base += "/";
  120. }
  121. this->Log << "Base = " << this->Base << "\n";
  122. }