diff options
author | Daniel Pfeifer <daniel@pfeifer-mail.de> | 2017-01-06 22:13:44 (GMT) |
---|---|---|
committer | Regina Pfeifer <regina@mailbox.org> | 2019-07-18 15:35:43 (GMT) |
commit | fbee46e262044ac71170552adc4eb656ef0b030b (patch) | |
tree | f985f370b4128f9af895db4e3995e6c2e166bb87 /Source/cmVariableWatchCommand.cxx | |
parent | 360d4155920b851f114843e91234bb0ae33afef3 (diff) | |
download | CMake-fbee46e262044ac71170552adc4eb656ef0b030b.zip CMake-fbee46e262044ac71170552adc4eb656ef0b030b.tar.gz CMake-fbee46e262044ac71170552adc4eb656ef0b030b.tar.bz2 |
cmVariableWatchCommand: Port away from FinalPass
Diffstat (limited to 'Source/cmVariableWatchCommand.cxx')
-rw-r--r-- | Source/cmVariableWatchCommand.cxx | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/Source/cmVariableWatchCommand.cxx b/Source/cmVariableWatchCommand.cxx index 5fe55bd..afc0b76 100644 --- a/Source/cmVariableWatchCommand.cxx +++ b/Source/cmVariableWatchCommand.cxx @@ -3,6 +3,7 @@ #include "cmVariableWatchCommand.h" #include <sstream> +#include <utility> #include "cmExecutionStatus.h" #include "cmListFileCache.h" @@ -84,15 +85,39 @@ static void deleteVariableWatchCallbackData(void* client_data) delete data; } -cmVariableWatchCommand::cmVariableWatchCommand() = default; - -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 { - for (std::string const& wv : this->WatchedVariables) { - this->Makefile->GetCMakeInstance()->GetVariableWatch()->RemoveWatch( - wv, cmVariableWatchCommandVariableAccessed); +public: + FinalAction(cmMakefile* makefile, std::string variable) + : Action(std::make_shared<Impl>(makefile, std::move(variable))) + { } -} + + void operator()(cmMakefile&) const {} + +private: + struct Impl + { + Impl(cmMakefile* makefile, std::string variable) + : Makefile(makefile) + , Variable(std::move(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&) @@ -118,7 +143,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)) { @@ -126,5 +150,6 @@ bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args, return false; } + this->Makefile->AddFinalAction(FinalAction(this->Makefile, variable)); return true; } |