CMake/Source/cmVariableWatchCommand.cxx

129 lines
4.0 KiB
C++
Raw Normal View History

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
2016-09-27 22:01:08 +03:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2007-04-11 23:13:05 +04:00
#include "cmVariableWatchCommand.h"
#include "cmVariableWatch.h"
struct cmVariableWatchCallbackData
2007-04-11 23:13:05 +04:00
{
bool InCallback;
std::string Command;
};
2007-04-11 23:13:05 +04: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
{
cmVariableWatchCallbackData* data =
static_cast<cmVariableWatchCallbackData*>(client_data);
2007-04-11 23:13:05 +04:00
if (data->InCallback) {
2007-04-11 23:13:05 +04:00
return;
}
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");
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(
cmListFileArgument(variable, cmListFileArgument::Quoted, 9999));
2007-04-12 23:50:39 +04:00
newLFF.Arguments.push_back(
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(
cmListFileArgument(currentListFile, cmListFileArgument::Quoted, 9999));
2007-04-12 23:50:39 +04:00
newLFF.Arguments.push_back(
cmListFileArgument(stack, cmListFileArgument::Quoted, 9999));
newLFF.Name = data->Command;
2007-04-11 23:13:05 +04:00
newLFF.Line = 9999;
cmExecutionStatus status;
if (!makefile->ExecuteCommand(newLFF, status)) {
std::ostringstream error;
error << "Error in cmake code at\nUnknown:0:\n"
<< "A command failed during the invocation of callback \""
<< data->Command << "\".";
2007-04-11 23:13:05 +04:00
cmSystemTools::Error(error.str().c_str());
data->InCallback = false;
2007-04-11 23:13:05 +04:00
return;
}
processed = true;
}
if (!processed) {
std::ostringstream msg;
msg << "Variable \"" << variable << "\" was accessed using "
<< accessString << " with value \"" << (newValue ? newValue : "")
<< "\".";
makefile->IssueMessage(cmake::LOG, msg.str());
}
data->InCallback = false;
}
static void deleteVariableWatchCallbackData(void* client_data)
{
cmVariableWatchCallbackData* data =
static_cast<cmVariableWatchCallbackData*>(client_data);
delete data;
}
cmVariableWatchCommand::cmVariableWatchCommand()
{
}
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);
}
}
bool cmVariableWatchCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
if (args.empty()) {
this->SetError("must be called with at least one argument.");
return false;
}
std::string variable = args[0];
std::string command;
if (args.size() > 1) {
command = args[1];
}
if (variable == "CMAKE_CURRENT_LIST_FILE") {
std::ostringstream ostr;
ostr << "cannot be set on the variable: " << variable;
this->SetError(ostr.str());
return false;
}
cmVariableWatchCallbackData* data = new cmVariableWatchCallbackData;
data->InCallback = false;
data->Command = command;
this->WatchedVariables.insert(variable);
if (!this->Makefile->GetCMakeInstance()->GetVariableWatch()->AddWatch(
variable, cmVariableWatchCommandVariableAccessed, data,
deleteVariableWatchCallbackData)) {
deleteVariableWatchCallbackData(data);
return false;
}
return true;
2007-04-11 23:13:05 +04:00
}