cmake/Source/CTest/cmCTestVC.h

147 lines
4.0 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2009-10-04 10:30:41 +03:00
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
#include <iosfwd>
#include <string>
2017-04-14 19:02:05 +02:00
#include "cmProcessOutput.h"
#include "cmProcessTools.h"
2009-10-04 10:30:41 +03:00
class cmCTest;
2015-08-17 11:37:30 +02:00
class cmXMLWriter;
2009-10-04 10:30:41 +03:00
/** \class cmCTestVC
* \brief Base class for version control system handlers
*
*/
2016-07-09 11:21:54 +02:00
class cmCTestVC : public cmProcessTools
2009-10-04 10:30:41 +03:00
{
public:
/** Construct with a CTest instance and update log stream. */
cmCTestVC(cmCTest* ctest, std::ostream& log);
virtual ~cmCTestVC();
/** Command line tool to invoke. */
void SetCommandLineTool(std::string const& tool);
/** Top-level source directory. */
void SetSourceDirectory(std::string const& dir);
/** Get the date/time specification for the current nightly start time. */
std::string GetNightlyTime();
/** Prepare the work tree. */
2020-08-30 11:54:41 +02:00
bool InitialCheckout(const std::string& command);
2009-10-04 10:30:41 +03:00
/** Perform cleanup operations on the work tree. */
void Cleanup();
/** Update the working tree to the new revision. */
bool Update();
/** Get the command line used by the Update method. */
std::string const& GetUpdateCommandLine() const
2016-07-09 11:21:54 +02:00
{
return this->UpdateCommandLine;
}
2009-10-04 10:30:41 +03:00
/** Write Update.xml entries for the updates found. */
2015-08-17 11:37:30 +02:00
bool WriteXML(cmXMLWriter& xml);
2009-10-04 10:30:41 +03:00
/** Enumerate non-trivial working tree states during update. */
2016-07-09 11:21:54 +02:00
enum PathStatus
{
PathUpdated,
PathModified,
PathConflicting
};
2009-10-04 10:30:41 +03:00
/** Get the number of working tree paths in each state after update. */
int GetPathCount(PathStatus s) const { return this->PathCount[s]; }
protected:
// Internal API to be implemented by subclasses.
virtual void CleanupImpl();
2017-07-20 19:35:53 +02:00
virtual bool NoteOldRevision();
2009-10-04 10:30:41 +03:00
virtual bool UpdateImpl();
2017-07-20 19:35:53 +02:00
virtual bool NoteNewRevision();
2019-11-11 23:01:05 +01:00
virtual void SetNewRevision(std::string const& revision);
2015-08-17 11:37:30 +02:00
virtual bool WriteXMLUpdates(cmXMLWriter& xml);
2009-10-04 10:30:41 +03:00
2013-03-16 19:13:01 +02:00
#if defined(__SUNPRO_CC) && __SUNPRO_CC <= 0x510
2016-07-09 11:21:54 +02:00
// Sun CC 5.1 needs help to allow cmCTestSVN::Revision to see this
public:
2013-03-16 19:13:01 +02:00
#endif
2009-10-04 10:30:41 +03:00
/** Basic information about one revision of a tree or file. */
struct Revision
{
std::string Rev;
std::string Date;
std::string Author;
2010-06-23 01:18:35 +03:00
std::string EMail;
2011-01-16 11:35:12 +01:00
std::string Committer;
std::string CommitterEMail;
std::string CommitDate;
2009-10-04 10:30:41 +03:00
std::string Log;
};
2013-03-16 19:13:01 +02:00
protected:
2009-10-04 10:30:41 +03:00
friend struct File;
/** Represent change to one file. */
struct File
{
2022-03-29 21:10:50 +02:00
PathStatus Status = PathUpdated;
Revision const* Rev = nullptr;
Revision const* PriorRev = nullptr;
File() = default;
2016-07-09 11:21:54 +02:00
File(PathStatus status, Revision const* rev, Revision const* priorRev)
: Status(status)
, Rev(rev)
, PriorRev(priorRev)
{
}
2009-10-04 10:30:41 +03:00
};
/** Convert a list of arguments to a human-readable command line. */
static std::string ComputeCommandLine(char const* const* cmd);
/** Run a command line and send output to given parsers. */
2016-07-09 11:21:54 +02:00
bool RunChild(char const* const* cmd, OutputParser* out, OutputParser* err,
2018-01-26 17:06:56 +01:00
const char* workDir = nullptr,
2017-04-14 19:02:05 +02:00
Encoding encoding = cmProcessOutput::Auto);
2009-10-04 10:30:41 +03:00
/** Run VC update command line and send output to given parsers. */
2016-07-09 11:21:54 +02:00
bool RunUpdateCommand(char const* const* cmd, OutputParser* out,
2018-01-26 17:06:56 +01:00
OutputParser* err = nullptr,
2017-04-14 19:02:05 +02:00
Encoding encoding = cmProcessOutput::Auto);
2009-10-04 10:30:41 +03:00
/** Write xml element for one file. */
2015-08-17 11:37:30 +02:00
void WriteXMLEntry(cmXMLWriter& xml, std::string const& path,
2009-10-04 10:30:41 +03:00
std::string const& name, std::string const& full,
File const& f);
// Instance of cmCTest running the script.
cmCTest* CTest;
// A stream to which we write log information.
std::ostream& Log;
// Basic information about the working tree.
std::string CommandLineTool;
std::string SourceDirectory;
// Record update command info.
std::string UpdateCommandLine;
// Placeholder for unknown revisions.
Revision Unknown;
// Count paths reported with each PathStatus value.
int PathCount[3];
};