cmCTestGlobalVC.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCTestGlobalVC.h"
  4. #include "cmCTest.h"
  5. #include "cmSystemTools.h"
  6. #include "cmXMLWriter.h"
  7. #include <ostream>
  8. #include <utility>
  9. cmCTestGlobalVC::cmCTestGlobalVC(cmCTest* ct, std::ostream& log)
  10. : cmCTestVC(ct, log)
  11. {
  12. this->PriorRev = this->Unknown;
  13. }
  14. cmCTestGlobalVC::~cmCTestGlobalVC() = default;
  15. const char* cmCTestGlobalVC::LocalPath(std::string const& path)
  16. {
  17. return path.c_str();
  18. }
  19. void cmCTestGlobalVC::DoRevision(Revision const& revision,
  20. std::vector<Change> const& changes)
  21. {
  22. // Ignore changes in the old revision.
  23. if (revision.Rev == this->OldRevision) {
  24. this->PriorRev = revision;
  25. return;
  26. }
  27. // Indicate we found a revision.
  28. cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush);
  29. // Store the revision.
  30. this->Revisions.push_back(revision);
  31. // Report this revision.
  32. Revision const& rev = this->Revisions.back();
  33. /* clang-format off */
  34. this->Log << "Found revision " << rev.Rev << "\n"
  35. << " author = " << rev.Author << "\n"
  36. << " date = " << rev.Date << "\n";
  37. /* clang-format on */
  38. // Update information about revisions of the changed files.
  39. for (Change const& c : changes) {
  40. if (const char* local = this->LocalPath(c.Path)) {
  41. std::string dir = cmSystemTools::GetFilenamePath(local);
  42. std::string name = cmSystemTools::GetFilenameName(local);
  43. File& file = this->Dirs[dir][name];
  44. file.PriorRev = file.Rev ? file.Rev : &this->PriorRev;
  45. file.Rev = &rev;
  46. this->Log << " " << c.Action << " " << local << " "
  47. << "\n";
  48. }
  49. }
  50. }
  51. void cmCTestGlobalVC::DoModification(PathStatus status,
  52. std::string const& path)
  53. {
  54. std::string dir = cmSystemTools::GetFilenamePath(path);
  55. std::string name = cmSystemTools::GetFilenameName(path);
  56. File& file = this->Dirs[dir][name];
  57. file.Status = status;
  58. // For local modifications the current rev is unknown and the
  59. // prior rev is the latest from svn.
  60. if (!file.Rev && !file.PriorRev) {
  61. file.PriorRev = &this->PriorRev;
  62. }
  63. }
  64. void cmCTestGlobalVC::WriteXMLDirectory(cmXMLWriter& xml,
  65. std::string const& path,
  66. Directory const& dir)
  67. {
  68. const char* slash = path.empty() ? "" : "/";
  69. xml.StartElement("Directory");
  70. xml.Element("Name", path);
  71. for (auto const& f : dir) {
  72. std::string const full = path + slash + f.first;
  73. this->WriteXMLEntry(xml, path, f.first, full, f.second);
  74. }
  75. xml.EndElement(); // Directory
  76. }
  77. void cmCTestGlobalVC::WriteXMLGlobal(cmXMLWriter& xml)
  78. {
  79. if (!this->NewRevision.empty()) {
  80. xml.Element("Revision", this->NewRevision);
  81. }
  82. if (!this->OldRevision.empty() && this->OldRevision != this->NewRevision) {
  83. xml.Element("PriorRevision", this->OldRevision);
  84. }
  85. }
  86. bool cmCTestGlobalVC::WriteXMLUpdates(cmXMLWriter& xml)
  87. {
  88. bool result = true;
  89. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  90. " Gathering version information (one . per revision):\n"
  91. " "
  92. << std::flush);
  93. result = this->LoadRevisions() && result;
  94. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
  95. result = this->LoadModifications() && result;
  96. this->WriteXMLGlobal(xml);
  97. for (auto const& d : this->Dirs) {
  98. this->WriteXMLDirectory(xml, d.first, d.second);
  99. }
  100. return result;
  101. }
  102. void cmCTestGlobalVC::SetNewRevision(std::string const& revision)
  103. {
  104. this->NewRevision = revision;
  105. }