cmCTestVC.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 void SetNewRevision(std::string const& revision);
  57. virtual bool WriteXMLUpdates(cmXMLWriter& xml);
  58. #if defined(__SUNPRO_CC) && __SUNPRO_CC <= 0x510
  59. // Sun CC 5.1 needs help to allow cmCTestSVN::Revision to see this
  60. public:
  61. #endif
  62. /** Basic information about one revision of a tree or file. */
  63. struct Revision
  64. {
  65. std::string Rev;
  66. std::string Date;
  67. std::string Author;
  68. std::string EMail;
  69. std::string Committer;
  70. std::string CommitterEMail;
  71. std::string CommitDate;
  72. std::string Log;
  73. };
  74. protected:
  75. friend struct File;
  76. /** Represent change to one file. */
  77. struct File
  78. {
  79. PathStatus Status;
  80. Revision const* Rev;
  81. Revision const* PriorRev;
  82. File()
  83. : Status(PathUpdated)
  84. , Rev(nullptr)
  85. , PriorRev(nullptr)
  86. {
  87. }
  88. File(PathStatus status, Revision const* rev, Revision const* priorRev)
  89. : Status(status)
  90. , Rev(rev)
  91. , PriorRev(priorRev)
  92. {
  93. }
  94. };
  95. /** Convert a list of arguments to a human-readable command line. */
  96. static std::string ComputeCommandLine(char const* const* cmd);
  97. /** Run a command line and send output to given parsers. */
  98. bool RunChild(char const* const* cmd, OutputParser* out, OutputParser* err,
  99. const char* workDir = nullptr,
  100. Encoding encoding = cmProcessOutput::Auto);
  101. /** Run VC update command line and send output to given parsers. */
  102. bool RunUpdateCommand(char const* const* cmd, OutputParser* out,
  103. OutputParser* err = nullptr,
  104. Encoding encoding = cmProcessOutput::Auto);
  105. /** Write xml element for one file. */
  106. void WriteXMLEntry(cmXMLWriter& xml, std::string const& path,
  107. std::string const& name, std::string const& full,
  108. File const& f);
  109. // Instance of cmCTest running the script.
  110. cmCTest* CTest;
  111. // A stream to which we write log information.
  112. std::ostream& Log;
  113. // Basic information about the working tree.
  114. std::string CommandLineTool;
  115. std::string SourceDirectory;
  116. // Record update command info.
  117. std::string UpdateCommandLine;
  118. // Placeholder for unknown revisions.
  119. Revision Unknown;
  120. // Count paths reported with each PathStatus value.
  121. int PathCount[3];
  122. };
  123. #endif