cmCTestGlobalVC.cxx 3.7 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()
  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 (std::vector<Change>::const_iterator ci = changes.begin();
  42. ci != changes.end(); ++ci) {
  43. if (const char* local = this->LocalPath(ci->Path)) {
  44. std::string dir = cmSystemTools::GetFilenamePath(local);
  45. std::string name = cmSystemTools::GetFilenameName(local);
  46. File& file = this->Dirs[dir][name];
  47. file.PriorRev = file.Rev ? file.Rev : &this->PriorRev;
  48. file.Rev = &rev;
  49. this->Log << " " << ci->Action << " " << local << " "
  50. << "\n";
  51. }
  52. }
  53. }
  54. void cmCTestGlobalVC::DoModification(PathStatus status,
  55. std::string const& path)
  56. {
  57. std::string dir = cmSystemTools::GetFilenamePath(path);
  58. std::string name = cmSystemTools::GetFilenameName(path);
  59. File& file = this->Dirs[dir][name];
  60. file.Status = status;
  61. // For local modifications the current rev is unknown and the
  62. // prior rev is the latest from svn.
  63. if (!file.Rev && !file.PriorRev) {
  64. file.PriorRev = &this->PriorRev;
  65. }
  66. }
  67. void cmCTestGlobalVC::WriteXMLDirectory(cmXMLWriter& xml,
  68. std::string const& path,
  69. Directory const& dir)
  70. {
  71. const char* slash = path.empty() ? "" : "/";
  72. xml.StartElement("Directory");
  73. xml.Element("Name", path);
  74. for (Directory::const_iterator fi = dir.begin(); fi != dir.end(); ++fi) {
  75. std::string full = path + slash + fi->first;
  76. this->WriteXMLEntry(xml, path, fi->first, full, fi->second);
  77. }
  78. xml.EndElement(); // Directory
  79. }
  80. void cmCTestGlobalVC::WriteXMLGlobal(cmXMLWriter& xml)
  81. {
  82. if (!this->NewRevision.empty()) {
  83. xml.Element("Revision", this->NewRevision);
  84. }
  85. if (!this->OldRevision.empty() && this->OldRevision != this->NewRevision) {
  86. xml.Element("PriorRevision", this->OldRevision);
  87. }
  88. }
  89. bool cmCTestGlobalVC::WriteXMLUpdates(cmXMLWriter& xml)
  90. {
  91. bool result = true;
  92. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  93. " Gathering version information (one . per revision):\n"
  94. " "
  95. << std::flush);
  96. result = this->LoadRevisions() && result;
  97. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
  98. result = this->LoadModifications() && result;
  99. this->WriteXMLGlobal(xml);
  100. for (std::map<std::string, Directory>::const_iterator di =
  101. this->Dirs.begin();
  102. di != this->Dirs.end(); ++di) {
  103. this->WriteXMLDirectory(xml, di->first, di->second);
  104. }
  105. return result;
  106. }