ENH: Improve response to bad if or elseif

Previously bad arguments to an if() or elseif() would cause some
subsequent statements in the corresponding block to execute.  This
teaches CMake to stop processing commands with a fatal error.  It also
provides context to bad elseif() error messages.
This commit is contained in:
Brad King 2009-01-20 14:35:22 -05:00
parent 03c940aeb3
commit a541cac325
3 changed files with 28 additions and 22 deletions

View File

@ -76,6 +76,10 @@ IsFunctionBlocked(const cmListFileFunction& lff,
}
else
{
// Place this call on the call stack.
cmMakefileCall stack_manager(&mf, this->Functions[c], status);
static_cast<void>(stack_manager);
std::string errorString;
std::vector<std::string> expandedArguments;
@ -98,8 +102,10 @@ IsFunctionBlocked(const cmListFileFunction& lff,
err += "(";
err += errorString;
err += ").";
cmSystemTools::Error(err.c_str());
return false;
mf.IssueMessage(cmake::FATAL_ERROR, err);
cmSystemTools::SetFatalErrorOccured();
mf.RemoveFunctionBlocker(lff);
return true;
}
if (isTrue)
@ -204,6 +210,7 @@ bool cmIfCommand
err += errorString;
err += ").";
this->SetError(err.c_str());
cmSystemTools::SetFatalErrorOccured();
return false;
}

View File

@ -348,26 +348,6 @@ bool cmMakefile::GetBacktrace(cmListFileBacktrace& backtrace) const
return true;
}
//----------------------------------------------------------------------------
// Helper class to make sure the call stack is valid.
class cmMakefileCall
{
public:
cmMakefileCall(cmMakefile* mf,
cmListFileContext const& lfc,
cmExecutionStatus& status): Makefile(mf)
{
cmMakefile::CallStackEntry entry = {&lfc, &status};
this->Makefile->CallStack.push_back(entry);
}
~cmMakefileCall()
{
this->Makefile->CallStack.pop_back();
}
private:
cmMakefile* Makefile;
};
//----------------------------------------------------------------------------
bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
cmExecutionStatus &status)

View File

@ -921,5 +921,24 @@ private:
void EnforceDirectoryLevelRules();
};
//----------------------------------------------------------------------------
// Helper class to make sure the call stack is valid.
class cmMakefileCall
{
public:
cmMakefileCall(cmMakefile* mf,
cmListFileContext const& lfc,
cmExecutionStatus& status): Makefile(mf)
{
cmMakefile::CallStackEntry entry = {&lfc, &status};
this->Makefile->CallStack.push_back(entry);
}
~cmMakefileCall()
{
this->Makefile->CallStack.pop_back();
}
private:
cmMakefile* Makefile;
};
#endif