Commit ca3b9186 authored by gaborbencze's avatar gaborbencze Committed by Brad King

cmCommand refactor: cmVariableWatchCommand

parent b1acc711
...@@ -203,8 +203,7 @@ void GetScriptingCommands(cmState* state) ...@@ -203,8 +203,7 @@ void GetScriptingCommands(cmState* state)
state->AddBuiltinCommand("cmake_host_system_information", state->AddBuiltinCommand("cmake_host_system_information",
cmCMakeHostSystemInformationCommand); cmCMakeHostSystemInformationCommand);
state->AddBuiltinCommand("remove", cmRemoveCommand); state->AddBuiltinCommand("remove", cmRemoveCommand);
state->AddBuiltinCommand("variable_watch", state->AddBuiltinCommand("variable_watch", cmVariableWatchCommand);
cm::make_unique<cmVariableWatchCommand>());
state->AddBuiltinCommand("write_file", state->AddBuiltinCommand("write_file",
cm::make_unique<cmWriteFileCommand>()); cm::make_unique<cmWriteFileCommand>());
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmVariableWatchCommand.h" #include "cmVariableWatchCommand.h"
#include <memory>
#include <sstream> #include <sstream>
#include <utility> #include <utility>
...@@ -119,11 +120,11 @@ private: ...@@ -119,11 +120,11 @@ private:
std::shared_ptr<Impl const> Action; std::shared_ptr<Impl const> Action;
}; };
bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args, bool cmVariableWatchCommand(std::vector<std::string> const& args,
cmExecutionStatus&) cmExecutionStatus& status)
{ {
if (args.empty()) { if (args.empty()) {
this->SetError("must be called with at least one argument."); status.SetError("must be called with at least one argument.");
return false; return false;
} }
std::string const& variable = args[0]; std::string const& variable = args[0];
...@@ -134,7 +135,7 @@ bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args, ...@@ -134,7 +135,7 @@ bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args,
if (variable == "CMAKE_CURRENT_LIST_FILE") { if (variable == "CMAKE_CURRENT_LIST_FILE") {
std::ostringstream ostr; std::ostringstream ostr;
ostr << "cannot be set on the variable: " << variable; ostr << "cannot be set on the variable: " << variable;
this->SetError(ostr.str()); status.SetError(ostr.str());
return false; return false;
} }
...@@ -143,13 +144,14 @@ bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args, ...@@ -143,13 +144,14 @@ bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args,
data->InCallback = false; data->InCallback = false;
data->Command = command; data->Command = command;
if (!this->Makefile->GetCMakeInstance()->GetVariableWatch()->AddWatch( if (!status.GetMakefile().GetCMakeInstance()->GetVariableWatch()->AddWatch(
variable, cmVariableWatchCommandVariableAccessed, data, variable, cmVariableWatchCommandVariableAccessed, data,
deleteVariableWatchCallbackData)) { deleteVariableWatchCallbackData)) {
deleteVariableWatchCallbackData(data); deleteVariableWatchCallbackData(data);
return false; return false;
} }
this->Makefile->AddFinalAction(FinalAction(this->Makefile, variable)); status.GetMakefile().AddFinalAction(
FinalAction(&status.GetMakefile(), variable));
return true; return true;
} }
...@@ -8,33 +8,13 @@ ...@@ -8,33 +8,13 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "cm_memory.hxx"
#include "cmCommand.h"
class cmExecutionStatus; class cmExecutionStatus;
/** \class cmVariableWatchCommand /**
* \brief Watch when the variable changes and invoke command * \brief Watch when the variable changes and invoke command
* *
*/ */
class cmVariableWatchCommand : public cmCommand bool cmVariableWatchCommand(std::vector<std::string> const& args,
{ cmExecutionStatus& status);
public:
/**
* This is a virtual constructor for the command.
*/
std::unique_ptr<cmCommand> Clone() override
{
return cm::make_unique<cmVariableWatchCommand>();
}
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status) override;
};
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment