2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2007-04-11 23:13:05 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2007-04-11 23:13:05 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2007-04-11 23:13:05 +04:00
|
|
|
#include "cmVariableWatchCommand.h"
|
|
|
|
|
|
|
|
#include "cmVariableWatch.h"
|
|
|
|
|
2013-08-02 23:41:45 +04:00
|
|
|
struct cmVariableWatchCallbackData
|
2007-04-11 23:13:05 +04:00
|
|
|
{
|
2013-08-02 23:41:45 +04:00
|
|
|
bool InCallback;
|
|
|
|
std::string Command;
|
|
|
|
};
|
2007-04-11 23:13:05 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static void cmVariableWatchCommandVariableAccessed(const std::string& variable,
|
|
|
|
int access_type,
|
|
|
|
void* client_data,
|
|
|
|
const char* newValue,
|
|
|
|
const cmMakefile* mf)
|
2007-04-11 23:13:05 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmVariableWatchCallbackData* data =
|
|
|
|
static_cast<cmVariableWatchCallbackData*>(client_data);
|
2007-04-11 23:13:05 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (data->InCallback) {
|
2007-04-11 23:13:05 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-08-02 23:41:45 +04:00
|
|
|
data->InCallback = true;
|
2007-04-11 23:13:05 +04:00
|
|
|
|
|
|
|
cmListFileFunction newLFF;
|
|
|
|
cmListFileArgument arg;
|
|
|
|
bool processed = false;
|
|
|
|
const char* accessString = cmVariableWatch::GetAccessAsString(access_type);
|
|
|
|
const char* currentListFile = mf->GetDefinition("CMAKE_CURRENT_LIST_FILE");
|
|
|
|
|
|
|
|
/// Ultra bad!!
|
|
|
|
cmMakefile* makefile = const_cast<cmMakefile*>(mf);
|
|
|
|
|
|
|
|
std::string stack = makefile->GetProperty("LISTFILE_STACK");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!data->Command.empty()) {
|
2007-04-11 23:13:05 +04:00
|
|
|
newLFF.Arguments.clear();
|
2007-04-12 23:50:39 +04:00
|
|
|
newLFF.Arguments.push_back(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileArgument(variable, cmListFileArgument::Quoted, 9999));
|
2007-04-12 23:50:39 +04:00
|
|
|
newLFF.Arguments.push_back(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileArgument(accessString, cmListFileArgument::Quoted, 9999));
|
|
|
|
newLFF.Arguments.push_back(cmListFileArgument(
|
|
|
|
newValue ? newValue : "", cmListFileArgument::Quoted, 9999));
|
2007-04-12 23:50:39 +04:00
|
|
|
newLFF.Arguments.push_back(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileArgument(currentListFile, cmListFileArgument::Quoted, 9999));
|
2007-04-12 23:50:39 +04:00
|
|
|
newLFF.Arguments.push_back(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmListFileArgument(stack, cmListFileArgument::Quoted, 9999));
|
2013-08-02 23:41:45 +04:00
|
|
|
newLFF.Name = data->Command;
|
2007-04-11 23:13:05 +04:00
|
|
|
newLFF.Line = 9999;
|
2008-01-23 18:28:26 +03:00
|
|
|
cmExecutionStatus status;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!makefile->ExecuteCommand(newLFF, status)) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream error;
|
2015-05-23 21:30:37 +03:00
|
|
|
error << "Error in cmake code at\nUnknown:0:\n"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "A command failed during the invocation of callback \""
|
|
|
|
<< data->Command << "\".";
|
2007-04-11 23:13:05 +04:00
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2013-08-02 23:41:45 +04:00
|
|
|
data->InCallback = false;
|
2007-04-11 23:13:05 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
processed = true;
|
|
|
|
}
|
|
|
|
if (!processed) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream msg;
|
2014-03-11 16:35:32 +04:00
|
|
|
msg << "Variable \"" << variable << "\" was accessed using "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< accessString << " with value \"" << (newValue ? newValue : "")
|
|
|
|
<< "\".";
|
2013-06-03 21:19:15 +04:00
|
|
|
makefile->IssueMessage(cmake::LOG, msg.str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-08-02 23:41:45 +04:00
|
|
|
|
|
|
|
data->InCallback = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void deleteVariableWatchCallbackData(void* client_data)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmVariableWatchCallbackData* data =
|
|
|
|
static_cast<cmVariableWatchCallbackData*>(client_data);
|
2013-08-02 23:41:45 +04:00
|
|
|
delete data;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmVariableWatchCommand::cmVariableWatchCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cmVariableWatchCommand::~cmVariableWatchCommand()
|
|
|
|
{
|
|
|
|
std::set<std::string>::const_iterator it;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (it = this->WatchedVariables.begin(); it != this->WatchedVariables.end();
|
|
|
|
++it) {
|
2013-08-02 23:41:45 +04:00
|
|
|
this->Makefile->GetCMakeInstance()->GetVariableWatch()->RemoveWatch(
|
|
|
|
*it, cmVariableWatchCommandVariableAccessed);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-08-02 23:41:45 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2013-08-02 23:41:45 +04:00
|
|
|
{
|
2016-09-16 00:59:29 +03:00
|
|
|
if (args.empty()) {
|
2013-08-02 23:41:45 +04:00
|
|
|
this->SetError("must be called with at least one argument.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-08-02 23:41:45 +04:00
|
|
|
std::string variable = args[0];
|
|
|
|
std::string command;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() > 1) {
|
2013-08-02 23:41:45 +04:00
|
|
|
command = args[1];
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (variable == "CMAKE_CURRENT_LIST_FILE") {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream ostr;
|
2014-03-11 16:35:32 +04:00
|
|
|
ostr << "cannot be set on the variable: " << variable;
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(ostr.str());
|
2013-08-02 23:41:45 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-08-02 23:41:45 +04:00
|
|
|
|
|
|
|
cmVariableWatchCallbackData* data = new cmVariableWatchCallbackData;
|
|
|
|
|
|
|
|
data->InCallback = false;
|
|
|
|
data->Command = command;
|
|
|
|
|
|
|
|
this->WatchedVariables.insert(variable);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Makefile->GetCMakeInstance()->GetVariableWatch()->AddWatch(
|
|
|
|
variable, cmVariableWatchCommandVariableAccessed, data,
|
|
|
|
deleteVariableWatchCallbackData)) {
|
2013-08-02 23:41:45 +04:00
|
|
|
deleteVariableWatchCallbackData(data);
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-08-02 23:41:45 +04:00
|
|
|
|
|
|
|
return true;
|
2007-04-11 23:13:05 +04:00
|
|
|
}
|