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