mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-15 03:30:39 -06:00
Merge topic 'ctest-update-refactoring'
9c23f8ed26cmCTestUpdateCommand: Remove handler usage255b1af5afcmCTestUpdateHandler: Move class into cmCTestUpdateCommand.cxx Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !9980
This commit is contained in:
@@ -1112,7 +1112,6 @@ add_library(
|
||||
CTest/cmCTestTestMeasurementXMLParser.cxx
|
||||
CTest/cmCTestTypes.cxx
|
||||
CTest/cmCTestUpdateCommand.cxx
|
||||
CTest/cmCTestUpdateHandler.cxx
|
||||
CTest/cmCTestUploadCommand.cxx
|
||||
|
||||
CTest/cmCTestVC.cxx
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "cmCTest.h"
|
||||
#include "cmCTestVC.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmXMLParser.h"
|
||||
|
||||
@@ -70,8 +71,8 @@ static int cmBZRXMLParserUnknownEncodingHandler(void* /*unused*/,
|
||||
return 0;
|
||||
}
|
||||
|
||||
cmCTestBZR::cmCTestBZR(cmCTest* ct, std::ostream& log)
|
||||
: cmCTestGlobalVC(ct, log)
|
||||
cmCTestBZR::cmCTestBZR(cmCTest* ct, cmMakefile* mf, std::ostream& log)
|
||||
: cmCTestGlobalVC(ct, mf, log)
|
||||
{
|
||||
this->PriorRev = this->Unknown;
|
||||
// Even though it is specified in the documentation, with bzr 1.13
|
||||
@@ -363,9 +364,9 @@ private:
|
||||
bool cmCTestBZR::UpdateImpl()
|
||||
{
|
||||
// Get user-specified update options.
|
||||
std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
|
||||
std::string opts = this->Makefile->GetSafeDefinition("CTEST_UPDATE_OPTIONS");
|
||||
if (opts.empty()) {
|
||||
opts = this->CTest->GetCTestConfiguration("BZRUpdateOptions");
|
||||
opts = this->Makefile->GetSafeDefinition("CTEST_BZR_UPDATE_OPTIONS");
|
||||
}
|
||||
std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "cmCTestGlobalVC.h"
|
||||
|
||||
class cmCTest;
|
||||
class cmMakefile;
|
||||
|
||||
/** \class cmCTestBZR
|
||||
* \brief Interaction with bzr command-line tool
|
||||
@@ -19,7 +20,7 @@ class cmCTestBZR : public cmCTestGlobalVC
|
||||
{
|
||||
public:
|
||||
/** Construct with a CTest instance and update log stream. */
|
||||
cmCTestBZR(cmCTest* ctest, std::ostream& log);
|
||||
cmCTestBZR(cmCTest* ctest, cmMakefile* mf, std::ostream& log);
|
||||
|
||||
~cmCTestBZR() override;
|
||||
|
||||
|
||||
@@ -11,12 +11,13 @@
|
||||
#include "cmsys/RegularExpression.hxx"
|
||||
|
||||
#include "cmCTest.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmXMLWriter.h"
|
||||
|
||||
cmCTestCVS::cmCTestCVS(cmCTest* ct, std::ostream& log)
|
||||
: cmCTestVC(ct, log)
|
||||
cmCTestCVS::cmCTestCVS(cmCTest* ct, cmMakefile* mf, std::ostream& log)
|
||||
: cmCTestVC(ct, mf, log)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -75,9 +76,9 @@ private:
|
||||
bool cmCTestCVS::UpdateImpl()
|
||||
{
|
||||
// Get user-specified update options.
|
||||
std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
|
||||
std::string opts = this->Makefile->GetSafeDefinition("CTEST_UPDATE_OPTIONS");
|
||||
if (opts.empty()) {
|
||||
opts = this->CTest->GetCTestConfiguration("CVSUpdateOptions");
|
||||
opts = this->Makefile->GetSafeDefinition("CTEST_CVS_UPDATE_OPTIONS");
|
||||
if (opts.empty()) {
|
||||
opts = "-dP";
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "cmCTestVC.h"
|
||||
|
||||
class cmCTest;
|
||||
class cmMakefile;
|
||||
class cmXMLWriter;
|
||||
|
||||
/** \class cmCTestCVS
|
||||
@@ -22,7 +23,7 @@ class cmCTestCVS : public cmCTestVC
|
||||
{
|
||||
public:
|
||||
/** Construct with a CTest instance and update log stream. */
|
||||
cmCTestCVS(cmCTest* ctest, std::ostream& log);
|
||||
cmCTestCVS(cmCTest* ctest, cmMakefile* mf, std::ostream& log);
|
||||
|
||||
~cmCTestCVS() override;
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
#include "cmCTest.h"
|
||||
#include "cmCTestVC.h"
|
||||
#include "cmList.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmProcessOutput.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmUVProcessChain.h"
|
||||
#include "cmValue.h"
|
||||
|
||||
static unsigned int cmCTestGITVersion(unsigned int epic, unsigned int major,
|
||||
unsigned int minor, unsigned int fix)
|
||||
@@ -28,8 +28,8 @@ static unsigned int cmCTestGITVersion(unsigned int epic, unsigned int major,
|
||||
return epic * 10000000 + major * 100000 + minor * 1000 + fix;
|
||||
}
|
||||
|
||||
cmCTestGIT::cmCTestGIT(cmCTest* ct, std::ostream& log)
|
||||
: cmCTestGlobalVC(ct, log)
|
||||
cmCTestGIT::cmCTestGIT(cmCTest* ct, cmMakefile* mf, std::ostream& log)
|
||||
: cmCTestGlobalVC(ct, mf, log)
|
||||
{
|
||||
this->PriorRev = this->Unknown;
|
||||
this->CurrentGitVersion = 0;
|
||||
@@ -161,9 +161,9 @@ bool cmCTestGIT::UpdateByFetchAndReset()
|
||||
git_fetch.emplace_back("fetch");
|
||||
|
||||
// Add user-specified update options.
|
||||
std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
|
||||
std::string opts = this->Makefile->GetSafeDefinition("CTEST_UPDATE_OPTIONS");
|
||||
if (opts.empty()) {
|
||||
opts = this->CTest->GetCTestConfiguration("GITUpdateOptions");
|
||||
opts = this->Makefile->GetSafeDefinition("CTEST_GIT_UPDATE_OPTIONS");
|
||||
}
|
||||
std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
|
||||
cm::append(git_fetch, args);
|
||||
@@ -222,7 +222,8 @@ bool cmCTestGIT::UpdateByCustom(std::string const& custom)
|
||||
|
||||
bool cmCTestGIT::UpdateInternal()
|
||||
{
|
||||
std::string custom = this->CTest->GetCTestConfiguration("GITUpdateCustom");
|
||||
std::string custom =
|
||||
this->Makefile->GetSafeDefinition("CTEST_GIT_UPDATE_CUSTOM");
|
||||
if (!custom.empty()) {
|
||||
return this->UpdateByCustom(custom);
|
||||
}
|
||||
@@ -265,9 +266,7 @@ bool cmCTestGIT::UpdateImpl()
|
||||
|
||||
bool ret;
|
||||
|
||||
std::string init_submodules =
|
||||
this->CTest->GetCTestConfiguration("GITInitSubmodules");
|
||||
if (cmIsOn(init_submodules)) {
|
||||
if (this->Makefile->IsOn("CTEST_GIT_INIT_SUBMODULES")) {
|
||||
std::vector<std::string> git_submodule_init = { git, "submodule", "init" };
|
||||
ret = this->RunChild(git_submodule_init, &submodule_out, &submodule_err,
|
||||
top_dir);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "cmCTestGlobalVC.h"
|
||||
|
||||
class cmCTest;
|
||||
class cmMakefile;
|
||||
|
||||
/** \class cmCTestGIT
|
||||
* \brief Interaction with git command-line tool
|
||||
@@ -19,7 +20,7 @@ class cmCTestGIT : public cmCTestGlobalVC
|
||||
{
|
||||
public:
|
||||
/** Construct with a CTest instance and update log stream. */
|
||||
cmCTestGIT(cmCTest* ctest, std::ostream& log);
|
||||
cmCTestGIT(cmCTest* ctest, cmMakefile* mf, std::ostream& log);
|
||||
|
||||
~cmCTestGIT() override;
|
||||
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmXMLWriter.h"
|
||||
|
||||
cmCTestGlobalVC::cmCTestGlobalVC(cmCTest* ct, std::ostream& log)
|
||||
: cmCTestVC(ct, log)
|
||||
cmCTestGlobalVC::cmCTestGlobalVC(cmCTest* ct, cmMakefile* mf,
|
||||
std::ostream& log)
|
||||
: cmCTestVC(ct, mf, log)
|
||||
{
|
||||
this->PriorRev = this->Unknown;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "cmCTestVC.h"
|
||||
|
||||
class cmCTest;
|
||||
class cmMakefile;
|
||||
class cmXMLWriter;
|
||||
|
||||
/** \class cmCTestGlobalVC
|
||||
@@ -23,7 +24,7 @@ class cmCTestGlobalVC : public cmCTestVC
|
||||
{
|
||||
public:
|
||||
/** Construct with a CTest instance and update log stream. */
|
||||
cmCTestGlobalVC(cmCTest* ctest, std::ostream& log);
|
||||
cmCTestGlobalVC(cmCTest* ctest, cmMakefile* mf, std::ostream& log);
|
||||
|
||||
~cmCTestGlobalVC() override;
|
||||
|
||||
|
||||
@@ -11,11 +11,12 @@
|
||||
|
||||
#include "cmCTest.h"
|
||||
#include "cmCTestVC.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmXMLParser.h"
|
||||
|
||||
cmCTestHG::cmCTestHG(cmCTest* ct, std::ostream& log)
|
||||
: cmCTestGlobalVC(ct, log)
|
||||
cmCTestHG::cmCTestHG(cmCTest* ct, cmMakefile* mf, std::ostream& log)
|
||||
: cmCTestGlobalVC(ct, mf, log)
|
||||
{
|
||||
this->PriorRev = this->Unknown;
|
||||
}
|
||||
@@ -142,9 +143,9 @@ bool cmCTestHG::UpdateImpl()
|
||||
hg_update.emplace_back("-v");
|
||||
|
||||
// Add user-specified update options.
|
||||
std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
|
||||
std::string opts = this->Makefile->GetSafeDefinition("CTEST_UPDATE_OPTIONS");
|
||||
if (opts.empty()) {
|
||||
opts = this->CTest->GetCTestConfiguration("HGUpdateOptions");
|
||||
opts = this->Makefile->GetSafeDefinition("CTEST_HG_UPDATE_OPTIONS");
|
||||
}
|
||||
std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
|
||||
cm::append(hg_update, args);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "cmCTestGlobalVC.h"
|
||||
|
||||
class cmCTest;
|
||||
class cmMakefile;
|
||||
|
||||
/** \class cmCTestHG
|
||||
* \brief Interaction with Mercurial command-line tool
|
||||
@@ -19,7 +20,7 @@ class cmCTestHG : public cmCTestGlobalVC
|
||||
{
|
||||
public:
|
||||
/** Construct with a CTest instance and update log stream. */
|
||||
cmCTestHG(cmCTest* ctest, std::ostream& log);
|
||||
cmCTestHG(cmCTest* ctest, cmMakefile* mf, std::ostream& log);
|
||||
|
||||
~cmCTestHG() override;
|
||||
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
#include "cmCTest.h"
|
||||
#include "cmCTestVC.h"
|
||||
#include "cmList.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmRange.h"
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
cmCTestP4::cmCTestP4(cmCTest* ct, std::ostream& log)
|
||||
: cmCTestGlobalVC(ct, log)
|
||||
cmCTestP4::cmCTestP4(cmCTest* ct, cmMakefile* mf, std::ostream& log)
|
||||
: cmCTestGlobalVC(ct, mf, log)
|
||||
{
|
||||
this->PriorRev = this->Unknown;
|
||||
}
|
||||
@@ -310,7 +311,7 @@ void cmCTestP4::SetP4Options(std::vector<std::string>& CommandOptions)
|
||||
|
||||
// The CTEST_P4_CLIENT variable sets the P4 client used when issuing
|
||||
// Perforce commands, if it's different from the default one.
|
||||
std::string client = this->CTest->GetCTestConfiguration("P4Client");
|
||||
std::string client = this->Makefile->GetSafeDefinition("CTEST_P4_CLIENT");
|
||||
if (!client.empty()) {
|
||||
this->P4Options.emplace_back("-c");
|
||||
this->P4Options.push_back(client);
|
||||
@@ -323,7 +324,7 @@ void cmCTestP4::SetP4Options(std::vector<std::string>& CommandOptions)
|
||||
|
||||
// The CTEST_P4_OPTIONS variable adds additional Perforce command line
|
||||
// options before the main command
|
||||
std::string opts = this->CTest->GetCTestConfiguration("P4Options");
|
||||
std::string opts = this->Makefile->GetSafeDefinition("CTEST_P4_OPTIONS");
|
||||
cm::append(this->P4Options, cmSystemTools::ParseArguments(opts));
|
||||
}
|
||||
|
||||
@@ -465,7 +466,8 @@ bool cmCTestP4::UpdateCustom(const std::string& custom)
|
||||
|
||||
bool cmCTestP4::UpdateImpl()
|
||||
{
|
||||
std::string custom = this->CTest->GetCTestConfiguration("P4UpdateCustom");
|
||||
std::string custom =
|
||||
this->Makefile->GetSafeDefinition("CTEST_P4_UPDATE_CUSTOM");
|
||||
if (!custom.empty()) {
|
||||
return this->UpdateCustom(custom);
|
||||
}
|
||||
@@ -483,9 +485,9 @@ bool cmCTestP4::UpdateImpl()
|
||||
p4_sync.emplace_back("sync");
|
||||
|
||||
// Get user-specified update options.
|
||||
std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
|
||||
std::string opts = this->Makefile->GetSafeDefinition("CTEST_UPDATE_OPTIONS");
|
||||
if (opts.empty()) {
|
||||
opts = this->CTest->GetCTestConfiguration("P4UpdateOptions");
|
||||
opts = this->Makefile->GetSafeDefinition("CTEST_P4_UPDATE_OPTIONS");
|
||||
}
|
||||
std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
|
||||
cm::append(p4_sync, args);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "cmCTestGlobalVC.h"
|
||||
|
||||
class cmCTest;
|
||||
class cmMakefile;
|
||||
|
||||
/** \class cmCTestP4
|
||||
* \brief Interaction with the Perforce command-line tool
|
||||
@@ -21,7 +22,7 @@ class cmCTestP4 : public cmCTestGlobalVC
|
||||
{
|
||||
public:
|
||||
/** Construct with a CTest instance and update log stream. */
|
||||
cmCTestP4(cmCTest* ctest, std::ostream& log);
|
||||
cmCTestP4(cmCTest* ctest, cmMakefile* mf, std::ostream& log);
|
||||
|
||||
~cmCTestP4() override;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "cmCTest.h"
|
||||
#include "cmCTestVC.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmXMLParser.h"
|
||||
@@ -23,8 +24,8 @@ struct cmCTestSVN::Revision : public cmCTestVC::Revision
|
||||
cmCTestSVN::SVNInfo* SVNInfo;
|
||||
};
|
||||
|
||||
cmCTestSVN::cmCTestSVN(cmCTest* ct, std::ostream& log)
|
||||
: cmCTestGlobalVC(ct, log)
|
||||
cmCTestSVN::cmCTestSVN(cmCTest* ct, cmMakefile* mf, std::ostream& log)
|
||||
: cmCTestGlobalVC(ct, mf, log)
|
||||
{
|
||||
this->PriorRev = this->Unknown;
|
||||
}
|
||||
@@ -240,9 +241,9 @@ private:
|
||||
bool cmCTestSVN::UpdateImpl()
|
||||
{
|
||||
// Get user-specified update options.
|
||||
std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
|
||||
std::string opts = this->Makefile->GetSafeDefinition("CTEST_UPDATE_OPTIONS");
|
||||
if (opts.empty()) {
|
||||
opts = this->CTest->GetCTestConfiguration("SVNUpdateOptions");
|
||||
opts = this->Makefile->GetSafeDefinition("CTEST_SVN_UPDATE_OPTIONS");
|
||||
}
|
||||
std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
|
||||
|
||||
@@ -272,7 +273,8 @@ bool cmCTestSVN::RunSVNCommand(std::vector<std::string> const& parameters,
|
||||
cm::append(args, parameters);
|
||||
args.emplace_back("--non-interactive");
|
||||
|
||||
std::string userOptions = this->CTest->GetCTestConfiguration("SVNOptions");
|
||||
std::string userOptions =
|
||||
this->Makefile->GetSafeDefinition("CTEST_SVN_OPTIONS");
|
||||
|
||||
std::vector<std::string> parsedUserOptions =
|
||||
cmSystemTools::ParseArguments(userOptions);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "cmCTestGlobalVC.h"
|
||||
|
||||
class cmCTest;
|
||||
class cmMakefile;
|
||||
class cmXMLWriter;
|
||||
|
||||
/** \class cmCTestSVN
|
||||
@@ -22,7 +23,7 @@ class cmCTestSVN : public cmCTestGlobalVC
|
||||
{
|
||||
public:
|
||||
/** Construct with a CTest instance and update log stream. */
|
||||
cmCTestSVN(cmCTest* ctest, std::ostream& log);
|
||||
cmCTestSVN(cmCTest* ctest, cmMakefile* mf, std::ostream& log);
|
||||
|
||||
~cmCTestSVN() override;
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ bool cmCTestStartCommand::InitialCheckout(std::ostream& ofs,
|
||||
}
|
||||
if (initialCheckoutCommand) {
|
||||
// Use a generic VC object to run and log the command.
|
||||
cmCTestVC vc(this->CTest, ofs);
|
||||
cmCTestVC vc(this->CTest, &mf, ofs);
|
||||
vc.SetSourceDirectory(sourceDir);
|
||||
if (!vc.InitialCheckout(*initialCheckoutCommand)) {
|
||||
return false;
|
||||
|
||||
@@ -2,94 +2,329 @@
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#include "cmCTestUpdateCommand.h"
|
||||
|
||||
#include <utility>
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/memory>
|
||||
#include <cmext/string_view>
|
||||
|
||||
#include "cmArgumentParser.h"
|
||||
#include "cmCLocaleEnvironmentScope.h"
|
||||
#include "cmCTest.h"
|
||||
#include "cmCTestGenericHandler.h"
|
||||
#include "cmCTestUpdateHandler.h"
|
||||
#include "cmCTestBZR.h"
|
||||
#include "cmCTestCVS.h"
|
||||
#include "cmCTestGIT.h"
|
||||
#include "cmCTestHG.h"
|
||||
#include "cmCTestP4.h"
|
||||
#include "cmCTestSVN.h"
|
||||
#include "cmCTestVC.h"
|
||||
#include "cmExecutionStatus.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmVersion.h"
|
||||
#include "cmXMLWriter.h"
|
||||
|
||||
std::unique_ptr<cmCTestGenericHandler> cmCTestUpdateCommand::InitializeHandler(
|
||||
HandlerArguments& args, cmExecutionStatus& status) const
|
||||
namespace {
|
||||
|
||||
enum
|
||||
{
|
||||
e_UNKNOWN = 0,
|
||||
e_CVS,
|
||||
e_SVN,
|
||||
e_BZR,
|
||||
e_GIT,
|
||||
e_HG,
|
||||
e_P4,
|
||||
e_LAST
|
||||
};
|
||||
|
||||
char const* TypeToString(int type)
|
||||
{
|
||||
// clang-format off
|
||||
switch (type) {
|
||||
case e_CVS: return "CVS";
|
||||
case e_SVN: return "SVN";
|
||||
case e_BZR: return "BZR";
|
||||
case e_GIT: return "GIT";
|
||||
case e_HG: return "HG";
|
||||
case e_P4: return "P4";
|
||||
default: return "Unknown";
|
||||
}
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
char const* TypeToCommandKey(int type)
|
||||
{
|
||||
// clang-format off
|
||||
switch (type) {
|
||||
case e_CVS: return "CTEST_CVS_COMMAND";
|
||||
case e_SVN: return "CTEST_SVN_COMMAND";
|
||||
case e_BZR: return "CTEST_BZR_COMMAND";
|
||||
case e_GIT: return "CTEST_GIT_COMMAND";
|
||||
case e_HG: return "CTEST_HG_COMMAND";
|
||||
case e_P4: return "CTEST_P4_COMMAND";
|
||||
default: return nullptr;
|
||||
}
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
int DetermineType(std::string const& cmd)
|
||||
{
|
||||
std::string stype = cmSystemTools::LowerCase(cmd);
|
||||
if (stype.find("cvs") != std::string::npos) {
|
||||
return e_CVS;
|
||||
}
|
||||
if (stype.find("svn") != std::string::npos) {
|
||||
return e_SVN;
|
||||
}
|
||||
if (stype.find("bzr") != std::string::npos) {
|
||||
return e_BZR;
|
||||
}
|
||||
if (stype.find("git") != std::string::npos) {
|
||||
return e_GIT;
|
||||
}
|
||||
if (stype.find("hg") != std::string::npos) {
|
||||
return e_HG;
|
||||
}
|
||||
if (stype.find("p4") != std::string::npos) {
|
||||
return e_P4;
|
||||
}
|
||||
return e_UNKNOWN;
|
||||
}
|
||||
|
||||
int DetectVCS(std::string const& dir)
|
||||
{
|
||||
if (cmSystemTools::FileExists(cmStrCat(dir, "/CVS"))) {
|
||||
return e_CVS;
|
||||
}
|
||||
if (cmSystemTools::FileExists(cmStrCat(dir, "/.svn"))) {
|
||||
return e_SVN;
|
||||
}
|
||||
if (cmSystemTools::FileExists(cmStrCat(dir, "/.bzr"))) {
|
||||
return e_BZR;
|
||||
}
|
||||
if (cmSystemTools::FileExists(cmStrCat(dir, "/.git"))) {
|
||||
return e_GIT;
|
||||
}
|
||||
if (cmSystemTools::FileExists(cmStrCat(dir, "/.hg"))) {
|
||||
return e_HG;
|
||||
}
|
||||
if (cmSystemTools::FileExists(cmStrCat(dir, "/.p4"))) {
|
||||
return e_P4;
|
||||
}
|
||||
if (cmSystemTools::FileExists(cmStrCat(dir, "/.p4config"))) {
|
||||
return e_P4;
|
||||
}
|
||||
return e_UNKNOWN;
|
||||
}
|
||||
|
||||
std::unique_ptr<cmCTestVC> MakeVC(int type, cmCTest* ctest, cmMakefile* mf,
|
||||
std::ostream& os)
|
||||
{
|
||||
// clang-format off
|
||||
switch (type) {
|
||||
case e_CVS: return cm::make_unique<cmCTestCVS>(ctest, mf, os);
|
||||
case e_SVN: return cm::make_unique<cmCTestSVN>(ctest, mf, os);
|
||||
case e_BZR: return cm::make_unique<cmCTestBZR>(ctest, mf, os);
|
||||
case e_GIT: return cm::make_unique<cmCTestGIT>(ctest, mf, os);
|
||||
case e_HG: return cm::make_unique<cmCTestHG> (ctest, mf, os);
|
||||
case e_P4: return cm::make_unique<cmCTestP4> (ctest, mf, os);
|
||||
default: return cm::make_unique<cmCTestVC> (ctest, mf, os);
|
||||
}
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool cmCTestUpdateCommand::ExecuteUpdate(UpdateArguments& args,
|
||||
cmExecutionStatus& status) const
|
||||
{
|
||||
cmMakefile& mf = status.GetMakefile();
|
||||
if (!args.Source.empty()) {
|
||||
this->CTest->SetCTestConfiguration(
|
||||
"SourceDirectory", cmSystemTools::CollapseFullPath(args.Source),
|
||||
args.Quiet);
|
||||
} else {
|
||||
this->CTest->SetCTestConfiguration(
|
||||
"SourceDirectory",
|
||||
cmSystemTools::CollapseFullPath(
|
||||
mf.GetSafeDefinition("CTEST_SOURCE_DIRECTORY")),
|
||||
args.Quiet);
|
||||
}
|
||||
std::string source_dir =
|
||||
this->CTest->GetCTestConfiguration("SourceDirectory");
|
||||
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "UpdateCommand", "CTEST_UPDATE_COMMAND", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "UpdateOptions", "CTEST_UPDATE_OPTIONS", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "CVSCommand", "CTEST_CVS_COMMAND", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "CVSUpdateOptions", "CTEST_CVS_UPDATE_OPTIONS", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "SVNCommand", "CTEST_SVN_COMMAND", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "SVNUpdateOptions", "CTEST_SVN_UPDATE_OPTIONS", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "SVNOptions", "CTEST_SVN_OPTIONS", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "BZRCommand", "CTEST_BZR_COMMAND", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "BZRUpdateOptions", "CTEST_BZR_UPDATE_OPTIONS", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "GITCommand", "CTEST_GIT_COMMAND", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "GITUpdateOptions", "CTEST_GIT_UPDATE_OPTIONS", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "GITInitSubmodules", "CTEST_GIT_INIT_SUBMODULES", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "GITUpdateCustom", "CTEST_GIT_UPDATE_CUSTOM", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "UpdateVersionOnly", "CTEST_UPDATE_VERSION_ONLY", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "UpdateVersionOverride", "CTEST_UPDATE_VERSION_OVERRIDE", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "HGCommand", "CTEST_HG_COMMAND", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "HGUpdateOptions", "CTEST_HG_UPDATE_OPTIONS", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "P4Command", "CTEST_P4_COMMAND", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "P4UpdateOptions", "CTEST_P4_UPDATE_OPTIONS", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "P4Client", "CTEST_P4_CLIENT", args.Quiet);
|
||||
this->CTest->SetCTestConfigurationFromCMakeVariable(
|
||||
&mf, "P4Options", "CTEST_P4_OPTIONS", args.Quiet);
|
||||
|
||||
auto handler = cm::make_unique<cmCTestUpdateHandler>(this->CTest);
|
||||
std::string const& source_dir = !args.Source.empty()
|
||||
? args.Source
|
||||
: mf.GetSafeDefinition("CTEST_SOURCE_DIRECTORY");
|
||||
if (source_dir.empty()) {
|
||||
status.SetError("source directory not specified. Please use SOURCE tag");
|
||||
return nullptr;
|
||||
status.SetError("called with no source directory specified. "
|
||||
"Use SOURCE argument or set CTEST_SOURCE_DIRECTORY.");
|
||||
return false;
|
||||
}
|
||||
handler->SourceDirectory = source_dir;
|
||||
handler->SetQuiet(args.Quiet);
|
||||
return std::unique_ptr<cmCTestGenericHandler>(std::move(handler));
|
||||
|
||||
std::string const currentTag = this->CTest->GetCurrentTag();
|
||||
if (currentTag.empty()) {
|
||||
status.SetError("called with no current tag.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Detect the VCS managing the source tree.
|
||||
int updateType = DetectVCS(source_dir);
|
||||
|
||||
// Get update command
|
||||
std::string updateCommand = mf.GetSafeDefinition("CTEST_UPDATE_COMMAND");
|
||||
|
||||
if (updateType == e_UNKNOWN && !updateCommand.empty()) {
|
||||
updateType = DetermineType(updateCommand);
|
||||
}
|
||||
if (updateType == e_UNKNOWN) {
|
||||
updateType = DetermineType(mf.GetSafeDefinition("CTEST_UPDATE_TYPE"));
|
||||
}
|
||||
|
||||
// If no update command was specified, lookup one for this VCS tool.
|
||||
if (updateCommand.empty()) {
|
||||
const char* key = TypeToCommandKey(updateType);
|
||||
if (key) {
|
||||
updateCommand = mf.GetSafeDefinition(key);
|
||||
}
|
||||
|
||||
if (updateCommand.empty()) {
|
||||
std::ostringstream e;
|
||||
e << "called with no update command specified. "
|
||||
"Please set CTEST_UPDATE_COMMAND";
|
||||
if (key) {
|
||||
e << " or " << key;
|
||||
}
|
||||
e << '.';
|
||||
status.SetError(e.str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
cmGeneratedFileStream ofs;
|
||||
if (!this->CTest->GetShowOnly()) {
|
||||
std::string logFile = cmStrCat("LastUpdate_", currentTag, ".log");
|
||||
if (!this->CTest->OpenOutputFile("Temporary", logFile, ofs)) {
|
||||
status.SetError(cmStrCat("cannot create log file: ", logFile));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
cmGeneratedFileStream os;
|
||||
if (!this->CTest->OpenOutputFile(currentTag, "Update.xml", os, true)) {
|
||||
status.SetError("cannot create resulting XML file: Update.xml");
|
||||
return false;
|
||||
}
|
||||
|
||||
this->CTest->AddSubmitFile(cmCTest::PartUpdate, "Update.xml");
|
||||
|
||||
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Updating " << TypeToString(updateType)
|
||||
<< " repository: " << source_dir << '\n',
|
||||
args.Quiet);
|
||||
|
||||
// Make sure VCS tool messages are in English so we can parse them.
|
||||
cmCLocaleEnvironmentScope fixLocale;
|
||||
static_cast<void>(fixLocale);
|
||||
|
||||
// Create an object to interact with the VCS tool.
|
||||
std::unique_ptr<cmCTestVC> vc = MakeVC(updateType, this->CTest, &mf, ofs);
|
||||
|
||||
vc->SetCommandLineTool(updateCommand);
|
||||
vc->SetSourceDirectory(source_dir);
|
||||
|
||||
// Cleanup the working tree.
|
||||
vc->Cleanup();
|
||||
|
||||
std::string start_time = this->CTest->CurrentTime();
|
||||
auto start_time_time = std::chrono::system_clock::now();
|
||||
auto elapsed_time_start = std::chrono::steady_clock::now();
|
||||
|
||||
bool updated = vc->Update();
|
||||
std::string buildname =
|
||||
cmCTest::SafeBuildIdField(mf.GetSafeDefinition("CTEST_BUILD_NAME"));
|
||||
|
||||
cmXMLWriter xml(os);
|
||||
xml.StartDocument();
|
||||
xml.StartElement("Update");
|
||||
xml.Attribute("mode", "Client");
|
||||
xml.Attribute("Generator",
|
||||
std::string("ctest-") + cmVersion::GetCMakeVersion());
|
||||
xml.Element("Site", mf.GetSafeDefinition("CTEST_SITE"));
|
||||
xml.Element("BuildName", buildname);
|
||||
xml.Element("BuildStamp",
|
||||
this->CTest->GetCurrentTag() + "-" +
|
||||
this->CTest->GetTestGroupString());
|
||||
xml.Element("StartDateTime", start_time);
|
||||
xml.Element("StartTime", start_time_time);
|
||||
xml.Element("UpdateCommand", vc->GetUpdateCommandLine());
|
||||
xml.Element("UpdateType", TypeToString(updateType));
|
||||
|
||||
std::string changeId = mf.GetSafeDefinition("CTEST_CHANGE_ID");
|
||||
if (!changeId.empty()) {
|
||||
xml.Element("ChangeId", changeId);
|
||||
}
|
||||
|
||||
bool loadedMods = vc->WriteXML(xml);
|
||||
|
||||
int localModifications = 0;
|
||||
int numUpdated = vc->GetPathCount(cmCTestVC::PathUpdated);
|
||||
if (numUpdated) {
|
||||
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Found " << numUpdated << " updated files\n",
|
||||
args.Quiet);
|
||||
}
|
||||
if (int numModified = vc->GetPathCount(cmCTestVC::PathModified)) {
|
||||
cmCTestOptionalLog(
|
||||
this->CTest, HANDLER_OUTPUT,
|
||||
" Found " << numModified << " locally modified files\n", args.Quiet);
|
||||
localModifications += numModified;
|
||||
}
|
||||
if (int numConflicting = vc->GetPathCount(cmCTestVC::PathConflicting)) {
|
||||
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Found " << numConflicting << " conflicting files\n",
|
||||
args.Quiet);
|
||||
localModifications += numConflicting;
|
||||
}
|
||||
|
||||
cmCTestOptionalLog(this->CTest, DEBUG, "End" << std::endl, args.Quiet);
|
||||
std::string end_time = this->CTest->CurrentTime();
|
||||
xml.Element("EndDateTime", end_time);
|
||||
xml.Element("EndTime", std::chrono::system_clock::now());
|
||||
xml.Element("ElapsedMinutes",
|
||||
std::chrono::duration_cast<std::chrono::minutes>(
|
||||
std::chrono::steady_clock::now() - elapsed_time_start)
|
||||
.count());
|
||||
|
||||
xml.StartElement("UpdateReturnStatus");
|
||||
if (localModifications) {
|
||||
xml.Content("Update error: "
|
||||
"There are modified or conflicting files in the repository");
|
||||
cmCTestLog(this->CTest, WARNING,
|
||||
" There are modified or conflicting files in the repository"
|
||||
<< std::endl);
|
||||
}
|
||||
if (!updated) {
|
||||
xml.Content("Update command failed:\n");
|
||||
xml.Content(vc->GetUpdateCommandLine());
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Update command failed: " << vc->GetUpdateCommandLine()
|
||||
<< "\n");
|
||||
}
|
||||
xml.EndElement(); // UpdateReturnStatus
|
||||
xml.EndElement(); // Update
|
||||
xml.EndDocument();
|
||||
|
||||
if (!args.ReturnValue.empty()) {
|
||||
mf.AddDefinition(args.ReturnValue,
|
||||
std::to_string(updated && loadedMods ? numUpdated : -1));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cmCTestUpdateCommand::InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) const
|
||||
{
|
||||
static auto const parser = MakeHandlerParser<HandlerArguments>();
|
||||
static auto const parser =
|
||||
cmArgumentParser<UpdateArguments>{ MakeBasicParser<UpdateArguments>() }
|
||||
.Bind("SOURCE"_s, &UpdateArguments::Source)
|
||||
.Bind("RETURN_VALUE"_s, &UpdateArguments::ReturnValue)
|
||||
.Bind("QUIET"_s, &UpdateArguments::Quiet);
|
||||
|
||||
return this->Invoke(parser, args, status, [&](HandlerArguments& a) {
|
||||
return this->ExecuteHandlerCommand(a, status);
|
||||
return this->Invoke(parser, args, status, [&](UpdateArguments& a) {
|
||||
return this->ExecuteUpdate(a, status);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,25 +4,30 @@
|
||||
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cmCTestHandlerCommand.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmCTestGenericHandler;
|
||||
|
||||
class cmCTestUpdateCommand : public cmCTestHandlerCommand
|
||||
{
|
||||
public:
|
||||
using cmCTestHandlerCommand::cmCTestHandlerCommand;
|
||||
|
||||
protected:
|
||||
struct UpdateArguments : BasicArguments
|
||||
{
|
||||
std::string Source;
|
||||
std::string ReturnValue;
|
||||
bool Quiet = false;
|
||||
};
|
||||
|
||||
private:
|
||||
std::string GetName() const override { return "ctest_update"; }
|
||||
|
||||
std::unique_ptr<cmCTestGenericHandler> InitializeHandler(
|
||||
HandlerArguments& args, cmExecutionStatus& status) const override;
|
||||
bool ExecuteUpdate(UpdateArguments& args, cmExecutionStatus& status) const;
|
||||
|
||||
bool InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) const override;
|
||||
|
||||
@@ -1,348 +0,0 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#include "cmCTestUpdateHandler.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
|
||||
#include <cm/memory>
|
||||
|
||||
#include "cmCLocaleEnvironmentScope.h"
|
||||
#include "cmCTest.h"
|
||||
#include "cmCTestBZR.h"
|
||||
#include "cmCTestCVS.h"
|
||||
#include "cmCTestGIT.h"
|
||||
#include "cmCTestHG.h"
|
||||
#include "cmCTestP4.h"
|
||||
#include "cmCTestSVN.h"
|
||||
#include "cmCTestVC.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmVersion.h"
|
||||
#include "cmXMLWriter.h"
|
||||
|
||||
static const char* cmCTestUpdateHandlerUpdateStrings[] = {
|
||||
"Unknown", "CVS", "SVN", "BZR", "GIT", "HG", "P4"
|
||||
};
|
||||
|
||||
static const char* cmCTestUpdateHandlerUpdateToString(int type)
|
||||
{
|
||||
if (type < cmCTestUpdateHandler::e_UNKNOWN ||
|
||||
type >= cmCTestUpdateHandler::e_LAST) {
|
||||
return cmCTestUpdateHandlerUpdateStrings[cmCTestUpdateHandler::e_UNKNOWN];
|
||||
}
|
||||
return cmCTestUpdateHandlerUpdateStrings[type];
|
||||
}
|
||||
|
||||
cmCTestUpdateHandler::cmCTestUpdateHandler(cmCTest* ctest)
|
||||
: Superclass(ctest)
|
||||
{
|
||||
}
|
||||
|
||||
int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
|
||||
{
|
||||
cmCTestOptionalLog(this->CTest, DEBUG,
|
||||
"Determine update type from command: "
|
||||
<< cmd << " and type: " << type << std::endl,
|
||||
this->Quiet);
|
||||
if (type && *type) {
|
||||
cmCTestOptionalLog(this->CTest, DEBUG,
|
||||
"Type specified: " << type << std::endl, this->Quiet);
|
||||
std::string stype = cmSystemTools::LowerCase(type);
|
||||
if (stype.find("cvs") != std::string::npos) {
|
||||
return cmCTestUpdateHandler::e_CVS;
|
||||
}
|
||||
if (stype.find("svn") != std::string::npos) {
|
||||
return cmCTestUpdateHandler::e_SVN;
|
||||
}
|
||||
if (stype.find("bzr") != std::string::npos) {
|
||||
return cmCTestUpdateHandler::e_BZR;
|
||||
}
|
||||
if (stype.find("git") != std::string::npos) {
|
||||
return cmCTestUpdateHandler::e_GIT;
|
||||
}
|
||||
if (stype.find("hg") != std::string::npos) {
|
||||
return cmCTestUpdateHandler::e_HG;
|
||||
}
|
||||
if (stype.find("p4") != std::string::npos) {
|
||||
return cmCTestUpdateHandler::e_P4;
|
||||
}
|
||||
} else {
|
||||
cmCTestOptionalLog(
|
||||
this->CTest, DEBUG,
|
||||
"Type not specified, check command: " << cmd << std::endl, this->Quiet);
|
||||
std::string stype = cmSystemTools::LowerCase(cmd);
|
||||
if (stype.find("cvs") != std::string::npos) {
|
||||
return cmCTestUpdateHandler::e_CVS;
|
||||
}
|
||||
if (stype.find("svn") != std::string::npos) {
|
||||
return cmCTestUpdateHandler::e_SVN;
|
||||
}
|
||||
if (stype.find("bzr") != std::string::npos) {
|
||||
return cmCTestUpdateHandler::e_BZR;
|
||||
}
|
||||
if (stype.find("git") != std::string::npos) {
|
||||
return cmCTestUpdateHandler::e_GIT;
|
||||
}
|
||||
if (stype.find("hg") != std::string::npos) {
|
||||
return cmCTestUpdateHandler::e_HG;
|
||||
}
|
||||
if (stype.find("p4") != std::string::npos) {
|
||||
return cmCTestUpdateHandler::e_P4;
|
||||
}
|
||||
}
|
||||
return cmCTestUpdateHandler::e_UNKNOWN;
|
||||
}
|
||||
|
||||
// clearly it would be nice if this were broken up into a few smaller
|
||||
// functions and commented...
|
||||
int cmCTestUpdateHandler::ProcessHandler()
|
||||
{
|
||||
// Make sure VCS tool messages are in English so we can parse them.
|
||||
cmCLocaleEnvironmentScope fixLocale;
|
||||
static_cast<void>(fixLocale);
|
||||
|
||||
// Get source dir
|
||||
if (this->SourceDirectory.empty()) {
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
||||
"Cannot find SourceDirectory key in the DartConfiguration.tcl"
|
||||
<< std::endl);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmGeneratedFileStream ofs;
|
||||
if (!this->CTest->GetShowOnly()) {
|
||||
this->StartLogFile("Update", ofs);
|
||||
}
|
||||
|
||||
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Updating the repository: " << this->SourceDirectory
|
||||
<< std::endl,
|
||||
this->Quiet);
|
||||
|
||||
if (!this->SelectVCS()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Use "
|
||||
<< cmCTestUpdateHandlerUpdateToString(this->UpdateType)
|
||||
<< " repository type" << std::endl;
|
||||
, this->Quiet);
|
||||
|
||||
// Create an object to interact with the VCS tool.
|
||||
std::unique_ptr<cmCTestVC> vc;
|
||||
switch (this->UpdateType) {
|
||||
case e_CVS:
|
||||
vc = cm::make_unique<cmCTestCVS>(this->CTest, ofs);
|
||||
break;
|
||||
case e_SVN:
|
||||
vc = cm::make_unique<cmCTestSVN>(this->CTest, ofs);
|
||||
break;
|
||||
case e_BZR:
|
||||
vc = cm::make_unique<cmCTestBZR>(this->CTest, ofs);
|
||||
break;
|
||||
case e_GIT:
|
||||
vc = cm::make_unique<cmCTestGIT>(this->CTest, ofs);
|
||||
break;
|
||||
case e_HG:
|
||||
vc = cm::make_unique<cmCTestHG>(this->CTest, ofs);
|
||||
break;
|
||||
case e_P4:
|
||||
vc = cm::make_unique<cmCTestP4>(this->CTest, ofs);
|
||||
break;
|
||||
default:
|
||||
vc = cm::make_unique<cmCTestVC>(this->CTest, ofs);
|
||||
break;
|
||||
}
|
||||
vc->SetCommandLineTool(this->UpdateCommand);
|
||||
vc->SetSourceDirectory(this->SourceDirectory);
|
||||
|
||||
// Cleanup the working tree.
|
||||
vc->Cleanup();
|
||||
|
||||
//
|
||||
// Now update repository and remember what files were updated
|
||||
//
|
||||
cmGeneratedFileStream os;
|
||||
if (!this->StartResultingXML(cmCTest::PartUpdate, "Update", os)) {
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
||||
"Cannot open log file" << std::endl);
|
||||
return -1;
|
||||
}
|
||||
std::string start_time = this->CTest->CurrentTime();
|
||||
auto start_time_time = std::chrono::system_clock::now();
|
||||
auto elapsed_time_start = std::chrono::steady_clock::now();
|
||||
|
||||
bool updated = vc->Update();
|
||||
std::string buildname =
|
||||
cmCTest::SafeBuildIdField(this->CTest->GetCTestConfiguration("BuildName"));
|
||||
|
||||
cmXMLWriter xml(os);
|
||||
xml.StartDocument();
|
||||
xml.StartElement("Update");
|
||||
xml.Attribute("mode", "Client");
|
||||
xml.Attribute("Generator",
|
||||
std::string("ctest-") + cmVersion::GetCMakeVersion());
|
||||
xml.Element("Site", this->CTest->GetCTestConfiguration("Site"));
|
||||
xml.Element("BuildName", buildname);
|
||||
xml.Element("BuildStamp",
|
||||
this->CTest->GetCurrentTag() + "-" +
|
||||
this->CTest->GetTestGroupString());
|
||||
xml.Element("StartDateTime", start_time);
|
||||
xml.Element("StartTime", start_time_time);
|
||||
xml.Element("UpdateCommand", vc->GetUpdateCommandLine());
|
||||
xml.Element("UpdateType",
|
||||
cmCTestUpdateHandlerUpdateToString(this->UpdateType));
|
||||
std::string changeId = this->CTest->GetCTestConfiguration("ChangeId");
|
||||
if (!changeId.empty()) {
|
||||
xml.Element("ChangeId", changeId);
|
||||
}
|
||||
|
||||
bool loadedMods = vc->WriteXML(xml);
|
||||
|
||||
int localModifications = 0;
|
||||
int numUpdated = vc->GetPathCount(cmCTestVC::PathUpdated);
|
||||
if (numUpdated) {
|
||||
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Found " << numUpdated << " updated files\n",
|
||||
this->Quiet);
|
||||
}
|
||||
if (int numModified = vc->GetPathCount(cmCTestVC::PathModified)) {
|
||||
cmCTestOptionalLog(
|
||||
this->CTest, HANDLER_OUTPUT,
|
||||
" Found " << numModified << " locally modified files\n", this->Quiet);
|
||||
localModifications += numModified;
|
||||
}
|
||||
if (int numConflicting = vc->GetPathCount(cmCTestVC::PathConflicting)) {
|
||||
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Found " << numConflicting << " conflicting files\n",
|
||||
this->Quiet);
|
||||
localModifications += numConflicting;
|
||||
}
|
||||
|
||||
cmCTestOptionalLog(this->CTest, DEBUG, "End" << std::endl, this->Quiet);
|
||||
std::string end_time = this->CTest->CurrentTime();
|
||||
xml.Element("EndDateTime", end_time);
|
||||
xml.Element("EndTime", std::chrono::system_clock::now());
|
||||
xml.Element("ElapsedMinutes",
|
||||
std::chrono::duration_cast<std::chrono::minutes>(
|
||||
std::chrono::steady_clock::now() - elapsed_time_start)
|
||||
.count());
|
||||
|
||||
xml.StartElement("UpdateReturnStatus");
|
||||
if (localModifications) {
|
||||
xml.Content("Update error: "
|
||||
"There are modified or conflicting files in the repository");
|
||||
cmCTestLog(this->CTest, WARNING,
|
||||
" There are modified or conflicting files in the repository"
|
||||
<< std::endl);
|
||||
}
|
||||
if (!updated) {
|
||||
xml.Content("Update command failed:\n");
|
||||
xml.Content(vc->GetUpdateCommandLine());
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Update command failed: " << vc->GetUpdateCommandLine()
|
||||
<< "\n");
|
||||
}
|
||||
xml.EndElement(); // UpdateReturnStatus
|
||||
xml.EndElement(); // Update
|
||||
xml.EndDocument();
|
||||
return updated && loadedMods ? numUpdated : -1;
|
||||
}
|
||||
|
||||
int cmCTestUpdateHandler::DetectVCS(const std::string& dir)
|
||||
{
|
||||
std::string sourceDirectory = dir;
|
||||
cmCTestOptionalLog(this->CTest, DEBUG,
|
||||
"Check directory: " << sourceDirectory << std::endl,
|
||||
this->Quiet);
|
||||
sourceDirectory += "/.svn";
|
||||
if (cmSystemTools::FileExists(sourceDirectory)) {
|
||||
return cmCTestUpdateHandler::e_SVN;
|
||||
}
|
||||
sourceDirectory = cmStrCat(dir, "/CVS");
|
||||
if (cmSystemTools::FileExists(sourceDirectory)) {
|
||||
return cmCTestUpdateHandler::e_CVS;
|
||||
}
|
||||
sourceDirectory = cmStrCat(dir, "/.bzr");
|
||||
if (cmSystemTools::FileExists(sourceDirectory)) {
|
||||
return cmCTestUpdateHandler::e_BZR;
|
||||
}
|
||||
sourceDirectory = cmStrCat(dir, "/.git");
|
||||
if (cmSystemTools::FileExists(sourceDirectory)) {
|
||||
return cmCTestUpdateHandler::e_GIT;
|
||||
}
|
||||
sourceDirectory = cmStrCat(dir, "/.hg");
|
||||
if (cmSystemTools::FileExists(sourceDirectory)) {
|
||||
return cmCTestUpdateHandler::e_HG;
|
||||
}
|
||||
sourceDirectory = cmStrCat(dir, "/.p4");
|
||||
if (cmSystemTools::FileExists(sourceDirectory)) {
|
||||
return cmCTestUpdateHandler::e_P4;
|
||||
}
|
||||
sourceDirectory = cmStrCat(dir, "/.p4config");
|
||||
if (cmSystemTools::FileExists(sourceDirectory)) {
|
||||
return cmCTestUpdateHandler::e_P4;
|
||||
}
|
||||
return cmCTestUpdateHandler::e_UNKNOWN;
|
||||
}
|
||||
|
||||
bool cmCTestUpdateHandler::SelectVCS()
|
||||
{
|
||||
// Get update command
|
||||
this->UpdateCommand = this->CTest->GetCTestConfiguration("UpdateCommand");
|
||||
|
||||
// Detect the VCS managing the source tree.
|
||||
this->UpdateType = this->DetectVCS(this->SourceDirectory);
|
||||
if (this->UpdateType == e_UNKNOWN) {
|
||||
// The source tree does not have a recognized VCS. Check the
|
||||
// configuration value or command name.
|
||||
this->UpdateType = this->DetermineType(
|
||||
this->UpdateCommand.c_str(),
|
||||
this->CTest->GetCTestConfiguration("UpdateType").c_str());
|
||||
}
|
||||
|
||||
// If no update command was specified, lookup one for this VCS tool.
|
||||
if (this->UpdateCommand.empty()) {
|
||||
const char* key = nullptr;
|
||||
switch (this->UpdateType) {
|
||||
case e_CVS:
|
||||
key = "CVSCommand";
|
||||
break;
|
||||
case e_SVN:
|
||||
key = "SVNCommand";
|
||||
break;
|
||||
case e_BZR:
|
||||
key = "BZRCommand";
|
||||
break;
|
||||
case e_GIT:
|
||||
key = "GITCommand";
|
||||
break;
|
||||
case e_HG:
|
||||
key = "HGCommand";
|
||||
break;
|
||||
case e_P4:
|
||||
key = "P4Command";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (key) {
|
||||
this->UpdateCommand = this->CTest->GetCTestConfiguration(key);
|
||||
}
|
||||
if (this->UpdateCommand.empty()) {
|
||||
std::ostringstream e;
|
||||
e << "Cannot find UpdateCommand ";
|
||||
if (key) {
|
||||
e << "or " << key;
|
||||
}
|
||||
e << " configuration key.";
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE, e.str() << std::endl);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#pragma once
|
||||
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "cmCTestGenericHandler.h"
|
||||
|
||||
class cmCTest;
|
||||
|
||||
/** \class cmCTestUpdateHandler
|
||||
* \brief A class that handles ctest -S invocations
|
||||
*
|
||||
*/
|
||||
class cmCTestUpdateHandler : public cmCTestGenericHandler
|
||||
{
|
||||
public:
|
||||
using Superclass = cmCTestGenericHandler;
|
||||
|
||||
/*
|
||||
* The main entry point for this class
|
||||
*/
|
||||
int ProcessHandler() override;
|
||||
|
||||
cmCTestUpdateHandler(cmCTest* ctest);
|
||||
|
||||
enum
|
||||
{
|
||||
e_UNKNOWN = 0,
|
||||
e_CVS,
|
||||
e_SVN,
|
||||
e_BZR,
|
||||
e_GIT,
|
||||
e_HG,
|
||||
e_P4,
|
||||
e_LAST
|
||||
};
|
||||
|
||||
private:
|
||||
// Some structures needed for update
|
||||
struct StringPair : public std::pair<std::string, std::string>
|
||||
{
|
||||
};
|
||||
struct UpdateFiles : public std::vector<StringPair>
|
||||
{
|
||||
};
|
||||
|
||||
// Determine the type of version control
|
||||
int DetermineType(const char* cmd, const char* type);
|
||||
|
||||
// The VCS command to update the working tree.
|
||||
std::string UpdateCommand;
|
||||
std::string SourceDirectory;
|
||||
int UpdateType = e_CVS;
|
||||
|
||||
int DetectVCS(const std::string& dir);
|
||||
bool SelectVCS();
|
||||
|
||||
friend class cmCTestUpdateCommand;
|
||||
};
|
||||
@@ -8,13 +8,14 @@
|
||||
#include <vector>
|
||||
|
||||
#include "cmCTest.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmUVProcessChain.h"
|
||||
#include "cmValue.h"
|
||||
#include "cmXMLWriter.h"
|
||||
|
||||
cmCTestVC::cmCTestVC(cmCTest* ct, std::ostream& log)
|
||||
cmCTestVC::cmCTestVC(cmCTest* ct, cmMakefile* mf, std::ostream& log)
|
||||
: CTest(ct)
|
||||
, Makefile(mf)
|
||||
, Log(log)
|
||||
{
|
||||
this->PathCount[PathUpdated] = 0;
|
||||
@@ -113,7 +114,7 @@ std::string cmCTestVC::GetNightlyTime()
|
||||
{
|
||||
// Get the nightly start time corresponding to the current dau.
|
||||
struct tm* t = this->CTest->GetNightlyTime(
|
||||
this->CTest->GetCTestConfiguration("NightlyStartTime"),
|
||||
this->Makefile->GetSafeDefinition("CTEST_NIGHTLY_START_TIME"),
|
||||
this->CTest->GetTomorrowTag());
|
||||
char current_time[1024];
|
||||
snprintf(current_time, sizeof(current_time), "%04d-%02d-%02d %02d:%02d:%02d",
|
||||
@@ -140,7 +141,7 @@ bool cmCTestVC::Update()
|
||||
|
||||
// Use the explicitly specified version.
|
||||
std::string versionOverride =
|
||||
this->CTest->GetCTestConfiguration("UpdateVersionOverride");
|
||||
this->Makefile->GetSafeDefinition("CTEST_UPDATE_VERSION_OVERRIDE");
|
||||
if (!versionOverride.empty()) {
|
||||
this->SetNewRevision(versionOverride);
|
||||
return true;
|
||||
@@ -148,7 +149,7 @@ bool cmCTestVC::Update()
|
||||
|
||||
// if update version only is on then do not actually update,
|
||||
// just note the current version and finish
|
||||
if (!cmIsOn(this->CTest->GetCTestConfiguration("UpdateVersionOnly"))) {
|
||||
if (!this->Makefile->IsOn("CTEST_UPDATE_VERSION_ONLY")) {
|
||||
result = this->NoteOldRevision() && result;
|
||||
this->Log << "--- Begin Update ---\n";
|
||||
result = this->UpdateImpl() && result;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
class cmCTest;
|
||||
class cmXMLWriter;
|
||||
class cmMakefile;
|
||||
|
||||
/** \class cmCTestVC
|
||||
* \brief Base class for version control system handlers
|
||||
@@ -22,7 +23,7 @@ class cmCTestVC : public cmProcessTools
|
||||
{
|
||||
public:
|
||||
/** Construct with a CTest instance and update log stream. */
|
||||
cmCTestVC(cmCTest* ctest, std::ostream& log);
|
||||
cmCTestVC(cmCTest* ctest, cmMakefile* mf, std::ostream& log);
|
||||
|
||||
virtual ~cmCTestVC();
|
||||
|
||||
@@ -128,6 +129,7 @@ protected:
|
||||
|
||||
// Instance of cmCTest running the script.
|
||||
cmCTest* CTest;
|
||||
cmMakefile* Makefile;
|
||||
|
||||
// A stream to which we write log information.
|
||||
std::ostream& Log;
|
||||
|
||||
@@ -3237,6 +3237,7 @@ void cmCTest::SetCMakeVariables(cmMakefile& mf)
|
||||
// CTest Update Step
|
||||
set("CTEST_UPDATE_COMMAND", "UpdateCommand");
|
||||
set("CTEST_UPDATE_OPTIONS", "UpdateOptions");
|
||||
set("CTEST_UPDATE_TYPE", "UpdateType");
|
||||
set("CTEST_CVS_COMMAND", "CVSCommand");
|
||||
set("CTEST_CVS_UPDATE_OPTIONS", "CVSUpdateOptions");
|
||||
set("CTEST_SVN_COMMAND", "SVNCommand");
|
||||
@@ -3253,6 +3254,7 @@ void cmCTest::SetCMakeVariables(cmMakefile& mf)
|
||||
set("CTEST_HG_COMMAND", "HGCommand");
|
||||
set("CTEST_HG_UPDATE_OPTIONS", "HGUpdateOptions");
|
||||
set("CTEST_P4_COMMAND", "P4Command");
|
||||
set("CTEST_P4_UPDATE_CUSTOM", "P4UpdateCustom");
|
||||
set("CTEST_P4_UPDATE_OPTIONS", "P4UpdateOptions");
|
||||
set("CTEST_P4_CLIENT", "P4Client");
|
||||
set("CTEST_P4_OPTIONS", "P4Options");
|
||||
|
||||
Reference in New Issue
Block a user