cmCTestVC.h 4.2 KB

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