cmCTestGlobalVC.cxx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 "cmXMLWriter.h"
  14. #include <cmsys/RegularExpression.hxx>
  15. cmCTestGlobalVC::cmCTestGlobalVC(cmCTest* ct, std::ostream& log)
  16. : cmCTestVC(ct, log)
  17. {
  18. this->PriorRev = this->Unknown;
  19. }
  20. cmCTestGlobalVC::~cmCTestGlobalVC()
  21. {
  22. }
  23. const char* cmCTestGlobalVC::LocalPath(std::string const& path)
  24. {
  25. return path.c_str();
  26. }
  27. void cmCTestGlobalVC::DoRevision(Revision const& revision,
  28. std::vector<Change> const& changes)
  29. {
  30. // Ignore changes in the old revision.
  31. if (revision.Rev == this->OldRevision) {
  32. this->PriorRev = revision;
  33. return;
  34. }
  35. // Indicate we found a revision.
  36. cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
  37. // Store the revision.
  38. this->Revisions.push_back(revision);
  39. // Report this revision.
  40. Revision const& rev = this->Revisions.back();
  41. /* clang-format off */
  42. this->Log << "Found revision " << rev.Rev << "\n"
  43. << " author = " << rev.Author << "\n"
  44. << " date = " << rev.Date << "\n";
  45. /* clang-format on */
  46. // Update information about revisions of the changed files.
  47. for (std::vector<Change>::const_iterator ci = changes.begin();
  48. ci != changes.end(); ++ci) {
  49. if (const char* local = this->LocalPath(ci->Path)) {
  50. std::string dir = cmSystemTools::GetFilenamePath(local);
  51. std::string name = cmSystemTools::GetFilenameName(local);
  52. File& file = this->Dirs[dir][name];
  53. file.PriorRev = file.Rev ? file.Rev : &this->PriorRev;
  54. file.Rev = &rev;
  55. this->Log << " " << ci->Action << " " << local << " "
  56. << "\n";
  57. }
  58. }
  59. }
  60. void cmCTestGlobalVC::DoModification(PathStatus status,
  61. std::string const& path)
  62. {
  63. std::string dir = cmSystemTools::GetFilenamePath(path);
  64. std::string name = cmSystemTools::GetFilenameName(path);
  65. File& file = this->Dirs[dir][name];
  66. file.Status = status;
  67. // For local modifications the current rev is unknown and the
  68. // prior rev is the latest from svn.
  69. if (!file.Rev && !file.PriorRev) {
  70. file.PriorRev = &this->PriorRev;
  71. }
  72. }
  73. void cmCTestGlobalVC::WriteXMLDirectory(cmXMLWriter& xml,
  74. std::string const& path,
  75. Directory const& dir)
  76. {
  77. const char* slash = path.empty() ? "" : "/";
  78. xml.StartElement("Directory");
  79. xml.Element("Name", path);
  80. for (Directory::const_iterator fi = dir.begin(); fi != dir.end(); ++fi) {
  81. std::string full = path + slash + fi->first;
  82. this->WriteXMLEntry(xml, path, fi->first, full, fi->second);
  83. }
  84. xml.EndElement(); // Directory
  85. }
  86. void cmCTestGlobalVC::WriteXMLGlobal(cmXMLWriter& xml)
  87. {
  88. if (!this->NewRevision.empty()) {
  89. xml.Element("Revision", this->NewRevision);
  90. }
  91. if (!this->OldRevision.empty() && this->OldRevision != this->NewRevision) {
  92. xml.Element("PriorRevision", this->OldRevision);
  93. }
  94. }
  95. bool cmCTestGlobalVC::WriteXMLUpdates(cmXMLWriter& xml)
  96. {
  97. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  98. " Gathering version information (one . per revision):\n"
  99. " "
  100. << std::flush);
  101. this->LoadRevisions();
  102. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
  103. this->LoadModifications();
  104. this->WriteXMLGlobal(xml);
  105. for (std::map<std::string, Directory>::const_iterator di =
  106. this->Dirs.begin();
  107. di != this->Dirs.end(); ++di) {
  108. this->WriteXMLDirectory(xml, di->first, di->second);
  109. }
  110. return true;
  111. }