cmCTestVC.h 3.8 KB

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