cmCTestGlobalVC.cxx 3.6 KB

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