Commit 1226f967 authored by Daniel Pfeifer's avatar Daniel Pfeifer
Browse files

cmVariableWatchCommand: Port away from FinalPass

parent 49b053a8
......@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmVariableWatchCommand.h"
#include <memory>
#include <sstream>
#include "cmExecutionStatus.h"
......@@ -85,19 +86,39 @@ static void deleteVariableWatchCallbackData(void* client_data)
delete data;
}
cmVariableWatchCommand::cmVariableWatchCommand()
/** This command does not really have a final pass but it needs to
stay alive since it owns variable watch callback information. */
class FinalAction
{
}
cmVariableWatchCommand::~cmVariableWatchCommand()
{
std::set<std::string>::const_iterator it;
for (it = this->WatchedVariables.begin(); it != this->WatchedVariables.end();
++it) {
this->Makefile->GetCMakeInstance()->GetVariableWatch()->RemoveWatch(
*it, cmVariableWatchCommandVariableAccessed);
public:
FinalAction(cmMakefile* makefile, std::string const& variable)
: Action(cm::make_shared<Impl>(makefile, variable))
{
}
}
void operator()(cmMakefile&) const {}
private:
struct Impl
{
Impl(cmMakefile* makefile, std::string const& variable)
: Makefile(makefile)
, Variable(variable)
{
}
~Impl()
{
this->Makefile->GetCMakeInstance()->GetVariableWatch()->RemoveWatch(
this->Variable, cmVariableWatchCommandVariableAccessed);
}
cmMakefile* Makefile;
std::string Variable;
};
std::shared_ptr<Impl const> Action;
};
bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
......@@ -123,7 +144,6 @@ bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args,
data->InCallback = false;
data->Command = command;
this->WatchedVariables.insert(variable);
if (!this->Makefile->GetCMakeInstance()->GetVariableWatch()->AddWatch(
variable, cmVariableWatchCommandVariableAccessed, data,
deleteVariableWatchCallbackData)) {
......@@ -131,5 +151,6 @@ bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args,
return false;
}
this->Makefile->AddFinalAction(FinalAction(this->Makefile, variable));
return true;
}
......@@ -25,25 +25,12 @@ public:
*/
cmCommand* Clone() CM_OVERRIDE { return new cmVariableWatchCommand; }
//! Default constructor
cmVariableWatchCommand();
//! Destructor.
~cmVariableWatchCommand() CM_OVERRIDE;
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status) CM_OVERRIDE;
/** This command does not really have a final pass but it needs to
stay alive since it owns variable watch callback information. */
bool HasFinalPass() const CM_OVERRIDE { return true; }
protected:
std::set<std::string> WatchedVariables;
};
#endif
Supports Markdown
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