summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-03-03 16:54:35 -0500
committerBrad King <brad.king@kitware.com>2022-03-03 16:54:35 -0500
commit5419cc3b8bca4b99f0a7e06759f597b2b2068496 (patch)
tree75f8b09c48b8fd8f56ce3dd486f5700e419feb3a
parent4331f9711877d23e83f69c35d9e2c0304791e892 (diff)
parentda2361ffb35799319abca6f7c3138c916685fb2d (diff)
downloadcmake-5419cc3b8bca4b99f0a7e06759f597b2b2068496.tar.gz
Merge branch 'while-bug-compatibility' into release-3.22
Merge-request: !7041
-rw-r--r--Source/cmWhileCommand.cxx11
-rw-r--r--Tests/RunCMake/if/unbalanced-parenthesis-stderr.txt2
-rw-r--r--Tests/RunCMake/if/unbalanced-parenthesis.cmake11
-rw-r--r--Tests/RunCMake/while/unbalanced-parenthesis-result.txt1
-rw-r--r--Tests/RunCMake/while/unbalanced-parenthesis-stderr.txt8
-rw-r--r--Tests/RunCMake/while/unbalanced-parenthesis-stdout.txt1
-rw-r--r--Tests/RunCMake/while/unbalanced-parenthesis.cmake13
7 files changed, 20 insertions, 27 deletions
diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx
index b8297ce212..a93a81fda5 100644
--- a/Source/cmWhileCommand.cxx
+++ b/Source/cmWhileCommand.cxx
@@ -79,12 +79,17 @@ bool cmWhileFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
return out;
};
+ // FIXME(#23296): For compatibility with older versions of CMake, we
+ // tolerate condition errors that evaluate to false. We should add
+ // a policy to enforce such errors.
+ bool enforceError = true;
std::string errorString;
MessageType messageType;
for (cmConditionEvaluator conditionEvaluator(mf, whileBT);
- conditionEvaluator.IsTrue(expandArgs(this->Args, expandedArguments),
- errorString, messageType);) {
+ (enforceError = /* enforce condition errors that evaluate to true */
+ conditionEvaluator.IsTrue(expandArgs(this->Args, expandedArguments),
+ errorString, messageType));) {
// Invoke all the functions that were collected in the block.
for (cmListFileFunction const& fn : functions) {
cmExecutionStatus status(mf);
@@ -105,7 +110,7 @@ bool cmWhileFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
}
}
- if (!errorString.empty()) {
+ if (!errorString.empty() && enforceError) {
std::string err = "had incorrect arguments:\n ";
for (auto const& i : expandedArguments) {
err += " ";
diff --git a/Tests/RunCMake/if/unbalanced-parenthesis-stderr.txt b/Tests/RunCMake/if/unbalanced-parenthesis-stderr.txt
index 770ccb8f18..d2260a04b2 100644
--- a/Tests/RunCMake/if/unbalanced-parenthesis-stderr.txt
+++ b/Tests/RunCMake/if/unbalanced-parenthesis-stderr.txt
@@ -1,7 +1,7 @@
CMake Error at unbalanced-parenthesis\.cmake:[0-9]+ \(if\):
if given arguments:
- "NOT" "\(" "IN_LIST" "some_list"
+ "\("
mismatched parenthesis in condition
Call Stack \(most recent call first\):
diff --git a/Tests/RunCMake/if/unbalanced-parenthesis.cmake b/Tests/RunCMake/if/unbalanced-parenthesis.cmake
index c51c7557f8..45932f6624 100644
--- a/Tests/RunCMake/if/unbalanced-parenthesis.cmake
+++ b/Tests/RunCMake/if/unbalanced-parenthesis.cmake
@@ -1,8 +1,5 @@
-set(var_with_paren "(")
-set(some_list "")
-
-if(NOT ${var_with_paren} IN_LIST some_list)
- message(STATUS "Never prints")
-else()
- message(STATUS "Never prints")
+set(paren "(")
+if(${paren})
+ message(STATUS "Condition incorrectly true")
endif()
+message(STATUS "Code incorrectly accepted")
diff --git a/Tests/RunCMake/while/unbalanced-parenthesis-result.txt b/Tests/RunCMake/while/unbalanced-parenthesis-result.txt
deleted file mode 100644
index d00491fd7e..0000000000
--- a/Tests/RunCMake/while/unbalanced-parenthesis-result.txt
+++ /dev/null
@@ -1 +0,0 @@
-1
diff --git a/Tests/RunCMake/while/unbalanced-parenthesis-stderr.txt b/Tests/RunCMake/while/unbalanced-parenthesis-stderr.txt
deleted file mode 100644
index 9d4132c5a3..0000000000
--- a/Tests/RunCMake/while/unbalanced-parenthesis-stderr.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-CMake Error at unbalanced-parenthesis.cmake:[0-9]+ \(while\):
- had incorrect arguments:
-
- "NOT" "\(" "IN_LIST" "some_list"
-
- mismatched parenthesis in condition
-Call Stack \(most recent call first\):
- CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/while/unbalanced-parenthesis-stdout.txt b/Tests/RunCMake/while/unbalanced-parenthesis-stdout.txt
new file mode 100644
index 0000000000..d45e194a51
--- /dev/null
+++ b/Tests/RunCMake/while/unbalanced-parenthesis-stdout.txt
@@ -0,0 +1 @@
+-- Code incorrectly accepted
diff --git a/Tests/RunCMake/while/unbalanced-parenthesis.cmake b/Tests/RunCMake/while/unbalanced-parenthesis.cmake
index 7a12701e6c..39d736b259 100644
--- a/Tests/RunCMake/while/unbalanced-parenthesis.cmake
+++ b/Tests/RunCMake/while/unbalanced-parenthesis.cmake
@@ -1,8 +1,7 @@
-set(var_with_paren "(")
-set(some_list "")
-
-while(NOT ${var_with_paren} IN_LIST some_list)
- message(STATUS "Never prints")
+set(paren "(")
+while(${paren})
+ message(STATUS "Condition incorrectly true")
+ break()
endwhile()
-
-message(STATUS "Never prints")
+# FIXME(#23296): The above condition error is tolerated for compatibility.
+message(STATUS "Code incorrectly accepted")