cmCTestGlobalVC.cxx 3.5 KB

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