cmCTestVC.h 4.0 KB

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