Commit 1591f138 authored by Marc Chevrier's avatar Marc Chevrier

modernize: manage cmCommand instances using unique_ptr.

parent d9b2c7da
......@@ -6,13 +6,16 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestHandlerCommand.h"
#include "cmCommand.h"
#include <string>
#include <utility>
#include <vector>
#include "cm_memory.hxx"
class cmCTestBuildHandler;
class cmCTestGenericHandler;
class cmCommand;
class cmExecutionStatus;
class cmGlobalGenerator;
......@@ -30,12 +33,12 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestBuildCommand* ni = new cmCTestBuildCommand;
auto ni = cm::make_unique<cmCTestBuildCommand>();
ni->CTest = this->CTest;
ni->CTestScriptHandler = this->CTestScriptHandler;
return ni;
return std::unique_ptr<cmCommand>(std::move(ni));
}
/**
......
......@@ -6,11 +6,14 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestHandlerCommand.h"
#include "cmCommand.h"
#include <string>
#include <utility>
#include "cm_memory.hxx"
class cmCTestGenericHandler;
class cmCommand;
/** \class cmCTestConfigure
* \brief Run a ctest script
......@@ -25,12 +28,12 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestConfigureCommand* ni = new cmCTestConfigureCommand;
auto ni = cm::make_unique<cmCTestConfigureCommand>();
ni->CTest = this->CTest;
ni->CTestScriptHandler = this->CTestScriptHandler;
return ni;
return std::unique_ptr<cmCommand>(std::move(ni));
}
/**
......
......@@ -6,12 +6,15 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestHandlerCommand.h"
#include "cmCommand.h"
#include <set>
#include <string>
#include <utility>
#include "cm_memory.hxx"
class cmCTestGenericHandler;
class cmCommand;
/** \class cmCTestCoverage
* \brief Run a ctest script
......@@ -26,12 +29,12 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestCoverageCommand* ni = new cmCTestCoverageCommand;
auto ni = cm::make_unique<cmCTestCoverageCommand>();
ni->CTest = this->CTest;
ni->CTestScriptHandler = this->CTestScriptHandler;
return ni;
return std::unique_ptr<cmCommand>(std::move(ni));
}
/**
......
......@@ -6,11 +6,14 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestCommand.h"
#include "cmCommand.h"
#include <string>
#include <utility>
#include <vector>
class cmCommand;
#include "cm_memory.hxx"
class cmExecutionStatus;
/** \class cmCTestEmptyBinaryDirectory
......@@ -27,13 +30,12 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestEmptyBinaryDirectoryCommand* ni =
new cmCTestEmptyBinaryDirectoryCommand;
auto ni = cm::make_unique<cmCTestEmptyBinaryDirectoryCommand>();
ni->CTest = this->CTest;
ni->CTestScriptHandler = this->CTestScriptHandler;
return ni;
return std::unique_ptr<cmCommand>(std::move(ni));
}
/**
......
......@@ -5,10 +5,14 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <utility>
#include "cm_memory.hxx"
#include "cmCTestTestCommand.h"
#include "cmCommand.h"
class cmCTestGenericHandler;
class cmCommand;
/** \class cmCTestMemCheck
* \brief Run a ctest script
......@@ -23,12 +27,12 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestMemCheckCommand* ni = new cmCTestMemCheckCommand;
auto ni = cm::make_unique<cmCTestMemCheckCommand>();
ni->CTest = this->CTest;
ni->CTestScriptHandler = this->CTestScriptHandler;
return ni;
return std::unique_ptr<cmCommand>(std::move(ni));
}
protected:
......
......@@ -6,11 +6,14 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestCommand.h"
#include "cmCommand.h"
#include <string>
#include <utility>
#include <vector>
class cmCommand;
#include "cm_memory.hxx"
class cmExecutionStatus;
/** \class cmCTestReadCustomFiles
......@@ -27,11 +30,11 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestReadCustomFilesCommand* ni = new cmCTestReadCustomFilesCommand;
auto ni = cm::make_unique<cmCTestReadCustomFilesCommand>();
ni->CTest = this->CTest;
return ni;
return std::unique_ptr<cmCommand>(std::move(ni));
}
/**
......
......@@ -6,11 +6,14 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestCommand.h"
#include "cmCommand.h"
#include <string>
#include <utility>
#include <vector>
class cmCommand;
#include "cm_memory.hxx"
class cmExecutionStatus;
/** \class cmCTestRunScript
......@@ -27,12 +30,12 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestRunScriptCommand* ni = new cmCTestRunScriptCommand;
auto ni = cm::make_unique<cmCTestRunScriptCommand>();
ni->CTest = this->CTest;
ni->CTestScriptHandler = this->CTestScriptHandler;
return ni;
return std::unique_ptr<cmCommand>(std::move(ni));
}
/**
......
......@@ -12,6 +12,8 @@
#include <string.h>
#include <utility>
#include "cm_memory.hxx"
#include "cmCTest.h"
#include "cmCTestBuildCommand.h"
#include "cmCTestCommand.h"
......@@ -27,6 +29,7 @@
#include "cmCTestTestCommand.h"
#include "cmCTestUpdateCommand.h"
#include "cmCTestUploadCommand.h"
#include "cmCommand.h"
#include "cmDuration.h"
#include "cmFunctionBlocker.h"
#include "cmGeneratedFileStream.h"
......@@ -167,12 +170,12 @@ void cmCTestScriptHandler::UpdateElapsedTime()
}
}
void cmCTestScriptHandler::AddCTestCommand(std::string const& name,
cmCTestCommand* command)
void cmCTestScriptHandler::AddCTestCommand(
std::string const& name, std::unique_ptr<cmCTestCommand> command)
{
command->CTest = this->CTest;
command->CTestScriptHandler = this;
this->CMake->GetState()->AddBuiltinCommand(name, command);
this->CMake->GetState()->AddBuiltinCommand(name, std::move(command));
}
int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg)
......@@ -295,21 +298,28 @@ void cmCTestScriptHandler::CreateCMake()
}
});
this->AddCTestCommand("ctest_build", new cmCTestBuildCommand);
this->AddCTestCommand("ctest_configure", new cmCTestConfigureCommand);
this->AddCTestCommand("ctest_coverage", new cmCTestCoverageCommand);
this->AddCTestCommand("ctest_build", cm::make_unique<cmCTestBuildCommand>());
this->AddCTestCommand("ctest_configure",
cm::make_unique<cmCTestConfigureCommand>());
this->AddCTestCommand("ctest_coverage",
cm::make_unique<cmCTestCoverageCommand>());
this->AddCTestCommand("ctest_empty_binary_directory",
new cmCTestEmptyBinaryDirectoryCommand);
this->AddCTestCommand("ctest_memcheck", new cmCTestMemCheckCommand);
cm::make_unique<cmCTestEmptyBinaryDirectoryCommand>());
this->AddCTestCommand("ctest_memcheck",
cm::make_unique<cmCTestMemCheckCommand>());
this->AddCTestCommand("ctest_read_custom_files",
new cmCTestReadCustomFilesCommand);
this->AddCTestCommand("ctest_run_script", new cmCTestRunScriptCommand);
this->AddCTestCommand("ctest_sleep", new cmCTestSleepCommand);
this->AddCTestCommand("ctest_start", new cmCTestStartCommand);
this->AddCTestCommand("ctest_submit", new cmCTestSubmitCommand);
this->AddCTestCommand("ctest_test", new cmCTestTestCommand);
this->AddCTestCommand("ctest_update", new cmCTestUpdateCommand);
this->AddCTestCommand("ctest_upload", new cmCTestUploadCommand);
cm::make_unique<cmCTestReadCustomFilesCommand>());
this->AddCTestCommand("ctest_run_script",
cm::make_unique<cmCTestRunScriptCommand>());
this->AddCTestCommand("ctest_sleep", cm::make_unique<cmCTestSleepCommand>());
this->AddCTestCommand("ctest_start", cm::make_unique<cmCTestStartCommand>());
this->AddCTestCommand("ctest_submit",
cm::make_unique<cmCTestSubmitCommand>());
this->AddCTestCommand("ctest_test", cm::make_unique<cmCTestTestCommand>());
this->AddCTestCommand("ctest_update",
cm::make_unique<cmCTestUpdateCommand>());
this->AddCTestCommand("ctest_upload",
cm::make_unique<cmCTestUploadCommand>());
}
// this sets up some variables for the script to use, creates the required
......
......@@ -9,6 +9,7 @@
#include "cmDuration.h"
#include <chrono>
#include <memory>
#include <string>
#include <vector>
......@@ -131,7 +132,8 @@ private:
int RunConfigurationDashboard();
// Add ctest command
void AddCTestCommand(std::string const& name, cmCTestCommand* command);
void AddCTestCommand(std::string const& name,
std::unique_ptr<cmCTestCommand> command);
// Try to remove the binary directory once
static bool TryToRemoveBinaryDirectoryOnce(const std::string& directoryPath);
......
......@@ -6,11 +6,14 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestCommand.h"
#include "cmCommand.h"
#include <string>
#include <utility>
#include <vector>
class cmCommand;
#include "cm_memory.hxx"
class cmExecutionStatus;
/** \class cmCTestSleep
......@@ -27,12 +30,12 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestSleepCommand* ni = new cmCTestSleepCommand;
auto ni = cm::make_unique<cmCTestSleepCommand>();
ni->CTest = this->CTest;
ni->CTestScriptHandler = this->CTestScriptHandler;
return ni;
return std::unique_ptr<cmCommand>(std::move(ni));
}
/**
......
......@@ -6,12 +6,15 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestCommand.h"
#include "cmCommand.h"
#include <iosfwd>
#include <string>
#include <utility>
#include <vector>
class cmCommand;
#include "cm_memory.hxx"
class cmExecutionStatus;
/** \class cmCTestStart
......@@ -27,14 +30,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestStartCommand* ni = new cmCTestStartCommand;
auto ni = cm::make_unique<cmCTestStartCommand>();
ni->CTest = this->CTest;
ni->CTestScriptHandler = this->CTestScriptHandler;
ni->CreateNewTag = this->CreateNewTag;
ni->Quiet = this->Quiet;
return ni;
return std::unique_ptr<cmCommand>(std::move(ni));
}
/**
......
......@@ -4,11 +4,15 @@
#include "cmCTest.h"
#include "cmCTestSubmitHandler.h"
#include "cmCommand.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmSystemTools.h"
#include <sstream>
#include <utility>
#include "cm_memory.hxx"
class cmExecutionStatus;
......@@ -27,12 +31,12 @@ cmCTestSubmitCommand::cmCTestSubmitCommand()
/**
* This is a virtual constructor for the command.
*/
cmCommand* cmCTestSubmitCommand::Clone()
std::unique_ptr<cmCommand> cmCTestSubmitCommand::Clone()
{
cmCTestSubmitCommand* ni = new cmCTestSubmitCommand;
auto ni = cm::make_unique<cmCTestSubmitCommand>();
ni->CTest = this->CTest;
ni->CTestScriptHandler = this->CTestScriptHandler;
return ni;
return std::unique_ptr<cmCommand>(std::move(ni));
}
cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
......
......@@ -8,12 +8,13 @@
#include "cmCTest.h"
#include "cmCTestHandlerCommand.h"
#include <memory>
#include <set>
#include <string>
#include <vector>
class cmCTestGenericHandler;
class cmCommand;
class cmCTestGenericHandler;
class cmExecutionStatus;
/** \class cmCTestSubmit
......@@ -26,7 +27,7 @@ class cmCTestSubmitCommand : public cmCTestHandlerCommand
{
public:
cmCTestSubmitCommand();
cmCommand* Clone() override;
std::unique_ptr<cmCommand> Clone() override;
bool InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status) override;
......
......@@ -6,11 +6,14 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestHandlerCommand.h"
#include "cmCommand.h"
#include <string>
#include <utility>
#include "cm_memory.hxx"
class cmCTestGenericHandler;
class cmCommand;
/** \class cmCTestTest
* \brief Run a ctest script
......@@ -25,12 +28,12 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestTestCommand* ni = new cmCTestTestCommand;
auto ni = cm::make_unique<cmCTestTestCommand>();
ni->CTest = this->CTest;
ni->CTestScriptHandler = this->CTestScriptHandler;
return ni;
return std::unique_ptr<cmCommand>(std::move(ni));
}
/**
......
......@@ -11,12 +11,14 @@
#include <functional>
#include <iomanip>
#include <iterator>
#include <memory>
#include <set>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <utility>
#include "cm_memory.hxx"
#include "cmAlgorithms.h"
#include "cmCTest.h"
......@@ -43,11 +45,11 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestSubdirCommand* c = new cmCTestSubdirCommand;
auto c = cm::make_unique<cmCTestSubdirCommand>();
c->TestHandler = this->TestHandler;
return c;
return std::unique_ptr<cmCommand>(std::move(c));
}
/**
......@@ -122,11 +124,11 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestAddSubdirectoryCommand* c = new cmCTestAddSubdirectoryCommand;
auto c = cm::make_unique<cmCTestAddSubdirectoryCommand>();
c->TestHandler = this->TestHandler;
return c;
return std::unique_ptr<cmCommand>(std::move(c));
}
/**
......@@ -187,11 +189,11 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestAddTestCommand* c = new cmCTestAddTestCommand;
auto c = cm::make_unique<cmCTestAddTestCommand>();
c->TestHandler = this->TestHandler;
return c;
return std::unique_ptr<cmCommand>(std::move(c));
}
/**
......@@ -220,11 +222,11 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestSetTestsPropertiesCommand* c = new cmCTestSetTestsPropertiesCommand;
auto c = cm::make_unique<cmCTestSetTestsPropertiesCommand>();
c->TestHandler = this->TestHandler;
return c;
return std::unique_ptr<cmCommand>(std::move(c));
}
/**
......@@ -249,12 +251,11 @@ public:
/**
* This is a virtual constructor for the command.
*/
cmCommand* Clone() override
std::unique_ptr<cmCommand> Clone() override
{
cmCTestSetDirectoryPropertiesCommand* c =
new cmCTestSetDirectoryPropertiesCommand;
auto c = cm::make_unique<cmCTestSetDirectoryPropertiesCommand>();
c->TestHandler = this->TestHandler;
return c;
return std::unique_ptr<cmCommand>(std::move(c));
}
/**
......@@ -1686,32 +1687,31 @@ void cmCTestTestHandler::GetListOfTests()
this->CTest->GetConfigType().c_str());
// Add handler for ADD_TEST
cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
auto newCom1 = cm::make_unique<cmCTestAddTestCommand>();
newCom1->TestHandler = this;
cm.GetState()->AddBuiltinCommand("add_test", newCom1);
cm.GetState()->AddBuiltinCommand("add_test", std::move(newCom1));
// Add handler for SUBDIRS
cmCTestSubdirCommand* newCom2 = new cmCTestSubdirCommand;
auto newCom2 = cm::make_unique<cmCTestSubdirCommand>();
newCom2->TestHandler = this;
cm.GetState()->AddBuiltinCommand("subdirs", newCom2);
cm.GetState()->AddBuiltinCommand("subdirs", std::move(newCom2));
// Add handler for ADD_SUBDIRECTORY
cmCTestAddSubdirectoryCommand* newCom3 = new cmCTestAddSubdirectoryCommand;