cmCTestVC.h 4.0 KB

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