cmCTestGlobalVC.cxx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc.
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTestGlobalVC.h"
  11. #include "cmCTest.h"
  12. #include "cmSystemTools.h"
  13. #include "cmXMLSafe.h"
  14. #include <cmsys/RegularExpression.hxx>
  15. //----------------------------------------------------------------------------
  16. cmCTestGlobalVC::cmCTestGlobalVC(cmCTest* ct, std::ostream& log):
  17. cmCTestVC(ct, log)
  18. {
  19. this->PriorRev = this->Unknown;
  20. }
  21. //----------------------------------------------------------------------------
  22. cmCTestGlobalVC::~cmCTestGlobalVC()
  23. {
  24. }
  25. //----------------------------------------------------------------------------
  26. const char* cmCTestGlobalVC::LocalPath(std::string const& path)
  27. {
  28. return path.c_str();
  29. }
  30. //----------------------------------------------------------------------------
  31. void cmCTestGlobalVC::DoRevision(Revision const& revision,
  32. std::vector<Change> const& changes)
  33. {
  34. // Ignore changes in the old revision.
  35. if(revision.Rev == this->OldRevision)
  36. {
  37. this->PriorRev = revision;
  38. return;
  39. }
  40. // Indicate we found a revision.
  41. cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
  42. // Store the revision.
  43. this->Revisions.push_back(revision);
  44. // Report this revision.
  45. Revision const& rev = this->Revisions.back();
  46. this->Log << "Found revision " << rev.Rev << "\n"
  47. << " author = " << rev.Author << "\n"
  48. << " date = " << rev.Date << "\n";
  49. // Update information about revisions of the changed files.
  50. for(std::vector<Change>::const_iterator ci = changes.begin();
  51. ci != changes.end(); ++ci)
  52. {
  53. if(const char* local = this->LocalPath(ci->Path))
  54. {
  55. std::string dir = cmSystemTools::GetFilenamePath(local);
  56. std::string name = cmSystemTools::GetFilenameName(local);
  57. File& file = this->Dirs[dir][name];
  58. file.PriorRev = file.Rev? file.Rev : &this->PriorRev;
  59. file.Rev = &rev;
  60. this->Log << " " << ci->Action << " " << local << " " << "\n";
  61. }
  62. }
  63. }
  64. //----------------------------------------------------------------------------
  65. void cmCTestGlobalVC::DoModification(PathStatus status,
  66. std::string const& path)
  67. {
  68. std::string dir = cmSystemTools::GetFilenamePath(path);
  69. std::string name = cmSystemTools::GetFilenameName(path);
  70. File& file = this->Dirs[dir][name];
  71. file.Status = status;
  72. // For local modifications the current rev is unknown and the
  73. // prior rev is the latest from svn.
  74. if(!file.Rev && !file.PriorRev)
  75. {
  76. file.PriorRev = &this->PriorRev;
  77. }
  78. }
  79. //----------------------------------------------------------------------------
  80. void cmCTestGlobalVC::WriteXMLDirectory(std::ostream& xml,
  81. std::string const& path,
  82. Directory const& dir)
  83. {
  84. const char* slash = path.empty()? "":"/";
  85. xml << "\t<Directory>\n"
  86. << "\t\t<Name>" << cmXMLSafe(path) << "</Name>\n";
  87. for(Directory::const_iterator fi = dir.begin(); fi != dir.end(); ++fi)
  88. {
  89. std::string full = path + slash + fi->first;
  90. this->WriteXMLEntry(xml, path, fi->first, full, fi->second);
  91. }
  92. xml << "\t</Directory>\n";
  93. }
  94. //----------------------------------------------------------------------------
  95. void cmCTestGlobalVC::WriteXMLGlobal(std::ostream& xml)
  96. {
  97. if(!this->NewRevision.empty())
  98. {
  99. xml << "\t<Revision>" << this->NewRevision << "</Revision>\n";
  100. }
  101. if(!this->OldRevision.empty() && this->OldRevision != this->NewRevision)
  102. {
  103. xml << "\t<PriorRevision>" << this->OldRevision << "</PriorRevision>\n";
  104. }
  105. }
  106. //----------------------------------------------------------------------------
  107. bool cmCTestGlobalVC::WriteXMLUpdates(std::ostream& xml)
  108. {
  109. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  110. " Gathering version information (one . per revision):\n"
  111. " " << std::flush);
  112. this->LoadRevisions();
  113. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
  114. this->LoadModifications();
  115. this->WriteXMLGlobal(xml);
  116. for(std::map<std::string, Directory>::const_iterator
  117. di = this->Dirs.begin(); di != this->Dirs.end(); ++di)
  118. {
  119. this->WriteXMLDirectory(xml, di->first, di->second);
  120. }
  121. return true;
  122. }