cmCTestVC.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <iosfwd>
  6. #include <string>
  7. #include <vector>
  8. #include "cmProcessOutput.h"
  9. #include "cmProcessTools.h"
  10. class cmCTest;
  11. class cmXMLWriter;
  12. class cmMakefile;
  13. /** \class cmCTestVC
  14. * \brief Base class for version control system handlers
  15. *
  16. */
  17. class cmCTestVC : public cmProcessTools
  18. {
  19. public:
  20. /** Construct with a CTest instance and update log stream. */
  21. cmCTestVC(cmCTest* ctest, cmMakefile* mf, std::ostream& log);
  22. virtual ~cmCTestVC();
  23. /** Command line tool to invoke. */
  24. void SetCommandLineTool(std::string const& tool);
  25. /** Top-level source directory. */
  26. void SetSourceDirectory(std::string const& dir);
  27. /** Get the date/time specification for the current nightly start time. */
  28. std::string GetNightlyTime();
  29. /** Prepare the work tree. */
  30. bool InitialCheckout(std::string const& command);
  31. /** Perform cleanup operations on the work tree. */
  32. void Cleanup();
  33. /** Update the working tree to the new revision. */
  34. bool Update();
  35. /** Get the command line used by the Update method. */
  36. std::string const& GetUpdateCommandLine() const
  37. {
  38. return this->UpdateCommandLine;
  39. }
  40. /** Write Update.xml entries for the updates found. */
  41. bool WriteXML(cmXMLWriter& xml);
  42. /** Enumerate non-trivial working tree states during update. */
  43. enum PathStatus
  44. {
  45. PathUpdated,
  46. PathModified,
  47. PathConflicting
  48. };
  49. /** Get the number of working tree paths in each state after update. */
  50. int GetPathCount(PathStatus s) const { return this->PathCount[s]; }
  51. protected:
  52. // Internal API to be implemented by subclasses.
  53. virtual void CleanupImpl();
  54. virtual bool NoteOldRevision();
  55. virtual bool UpdateImpl();
  56. virtual bool NoteNewRevision();
  57. virtual void SetNewRevision(std::string const& revision);
  58. virtual bool WriteXMLUpdates(cmXMLWriter& xml);
  59. #if defined(__SUNPRO_CC) && __SUNPRO_CC <= 0x510
  60. // Sun CC 5.1 needs help to allow cmCTestSVN::Revision to see this
  61. public:
  62. #endif
  63. /** Basic information about one revision of a tree or file. */
  64. struct Revision
  65. {
  66. std::string Rev;
  67. std::string Date;
  68. std::string Author;
  69. std::string EMail;
  70. std::string Committer;
  71. std::string CommitterEMail;
  72. std::string CommitDate;
  73. std::string Log;
  74. };
  75. protected:
  76. friend struct File;
  77. /** Represent change to one file. */
  78. struct File
  79. {
  80. PathStatus Status = PathUpdated;
  81. Revision const* Rev = nullptr;
  82. Revision const* PriorRev = nullptr;
  83. File() = default;
  84. File(PathStatus status, Revision const* rev, Revision const* priorRev)
  85. : Status(status)
  86. , Rev(rev)
  87. , PriorRev(priorRev)
  88. {
  89. }
  90. };
  91. /** Convert a list of arguments to a human-readable command line. */
  92. static std::string ComputeCommandLine(std::vector<std::string> const& cmd);
  93. /** Run a command line and send output to given parsers. */
  94. bool RunChild(std::vector<std::string> const& cmd, OutputParser* out,
  95. OutputParser* err, std::string workDir = {},
  96. Encoding encoding = cmProcessOutput::Auto);
  97. /** Run VC update command line and send output to given parsers. */
  98. bool RunUpdateCommand(std::vector<std::string> const& cmd, OutputParser* out,
  99. OutputParser* err = nullptr,
  100. Encoding encoding = cmProcessOutput::Auto);
  101. /** Write xml element for one file. */
  102. void WriteXMLEntry(cmXMLWriter& xml, std::string const& path,
  103. std::string const& name, std::string const& full,
  104. File const& f);
  105. // Instance of cmCTest running the script.
  106. cmCTest* CTest;
  107. cmMakefile* Makefile;
  108. // A stream to which we write log information.
  109. std::ostream& Log;
  110. // Basic information about the working tree.
  111. std::string CommandLineTool;
  112. std::string SourceDirectory;
  113. // Record update command info.
  114. std::string UpdateCommandLine;
  115. // Placeholder for unknown revisions.
  116. Revision Unknown;
  117. // Count paths reported with each PathStatus value.
  118. int PathCount[3];
  119. };