cmCTestGlobalVC.cxx 4.0 KB

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