cmCTestVC.h 4.2 KB

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