mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-31 02:39:48 -06:00
Fix: while() can silently ignore incorrect condition
When `conditionEvaluator.IsTrue(...)` returns `false` it just didn't print the error occured.
This commit is contained in:
@@ -75,24 +75,6 @@ bool cmWhileFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
|
||||
conditionEvaluator.IsTrue(expandedArguments, errorString, messageType);
|
||||
|
||||
while (isTrue) {
|
||||
if (!errorString.empty()) {
|
||||
std::string err = "had incorrect arguments: ";
|
||||
for (cmListFileArgument const& arg : this->Args) {
|
||||
err += (arg.Delim ? "\"" : "");
|
||||
err += arg.Value;
|
||||
err += (arg.Delim ? "\"" : "");
|
||||
err += " ";
|
||||
}
|
||||
err += "(";
|
||||
err += errorString;
|
||||
err += ").";
|
||||
mf.GetCMakeInstance()->IssueMessage(messageType, err, whileBT);
|
||||
if (messageType == MessageType::FATAL_ERROR) {
|
||||
cmSystemTools::SetFatalErrorOccured();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke all the functions that were collected in the block.
|
||||
for (cmListFileFunction const& fn : functions) {
|
||||
cmExecutionStatus status(mf);
|
||||
@@ -116,6 +98,24 @@ bool cmWhileFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
|
||||
isTrue =
|
||||
conditionEvaluator.IsTrue(expandedArguments, errorString, messageType);
|
||||
}
|
||||
|
||||
if (!isTrue && !errorString.empty()) {
|
||||
std::string err = "had incorrect arguments: ";
|
||||
for (cmListFileArgument const& arg : this->Args) {
|
||||
err += (arg.Delim ? "\"" : "");
|
||||
err += arg.Value;
|
||||
err += (arg.Delim ? "\"" : "");
|
||||
err += " ";
|
||||
}
|
||||
err += "(";
|
||||
err += errorString;
|
||||
err += ").";
|
||||
mf.GetCMakeInstance()->IssueMessage(messageType, err, whileBT);
|
||||
if (messageType == MessageType::FATAL_ERROR) {
|
||||
cmSystemTools::SetFatalErrorOccured();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
1
Tests/RunCMake/while/unbalanced-parenthesis-result.txt
Normal file
1
Tests/RunCMake/while/unbalanced-parenthesis-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
5
Tests/RunCMake/while/unbalanced-parenthesis-stderr.txt
Normal file
5
Tests/RunCMake/while/unbalanced-parenthesis-stderr.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
CMake Error at unbalanced-parenthesis.cmake:[0-9]+ \(while\):
|
||||
had incorrect arguments: NOT \$\{var_with_paren\} IN_LIST some_list
|
||||
\(mismatched parenthesis in condition\).
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists\.txt:[0-9]+ \(include\)
|
||||
@@ -5,4 +5,4 @@ while(NOT ${var_with_paren} IN_LIST some_list)
|
||||
message(STATUS "Never prints")
|
||||
endwhile()
|
||||
|
||||
message(STATUS "It prints but in fact `while()` have to fail")
|
||||
message(STATUS "Never prints")
|
||||
|
||||
Reference in New Issue
Block a user