summaryrefslogtreecommitdiffstats
path: root/Source/cmState.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2020-10-22 20:50:42 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2020-10-22 21:04:31 (GMT)
commit8aee7fdb32a7099e3e4efdf1bf0a00732ee1c46b (patch)
tree3854ce6ac00cc25aa55905af070f2b91d0569504 /Source/cmState.cxx
parent3a82ff6a11d643c4a5959f65ea538a3b60784a16 (diff)
downloadCMake-8aee7fdb32a7099e3e4efdf1bf0a00732ee1c46b.zip
CMake-8aee7fdb32a7099e3e4efdf1bf0a00732ee1c46b.tar.gz
CMake-8aee7fdb32a7099e3e4efdf1bf0a00732ee1c46b.tar.bz2
cmState: Prohibit override of flow control commands
Diffstat (limited to 'Source/cmState.cxx')
-rw-r--r--Source/cmState.cxx31
1 files changed, 28 insertions, 3 deletions
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index d5ac9ae..77665f1 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -436,6 +436,19 @@ void cmState::AddBuiltinCommand(std::string const& name,
});
}
+void cmState::AddFlowControlCommand(std::string const& name, Command command)
+{
+ this->FlowControlCommands.insert(name);
+ this->AddBuiltinCommand(name, std::move(command));
+}
+
+void cmState::AddFlowControlCommand(std::string const& name,
+ BuiltinCommand command)
+{
+ this->FlowControlCommands.insert(name);
+ this->AddBuiltinCommand(name, command);
+}
+
void cmState::AddDisallowedCommand(std::string const& name,
BuiltinCommand command,
cmPolicies::PolicyID policy,
@@ -465,7 +478,7 @@ void cmState::AddDisallowedCommand(std::string const& name,
void cmState::AddUnexpectedCommand(std::string const& name, const char* error)
{
- this->AddBuiltinCommand(
+ this->AddFlowControlCommand(
name,
[name, error](std::vector<cmListFileArgument> const&,
cmExecutionStatus& status) -> bool {
@@ -480,16 +493,28 @@ void cmState::AddUnexpectedCommand(std::string const& name, const char* error)
});
}
-void cmState::AddScriptedCommand(std::string const& name, Command command)
+bool cmState::AddScriptedCommand(std::string const& name, BT<Command> command,
+ cmMakefile& mf)
{
std::string sName = cmSystemTools::LowerCase(name);
+ if (this->FlowControlCommands.count(sName)) {
+ mf.GetCMakeInstance()->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Built-in flow control command \"", sName,
+ "\" cannot be overridden."),
+ command.Backtrace);
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+
// if the command already exists, give a new name to the old command.
if (Command oldCmd = this->GetCommandByExactName(sName)) {
this->ScriptedCommands["_" + sName] = oldCmd;
}
- this->ScriptedCommands[sName] = std::move(command);
+ this->ScriptedCommands[sName] = std::move(command.Value);
+ return true;
}
cmState::Command cmState::GetCommand(std::string const& name) const