summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-08-19 12:36:58 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-08-19 12:37:08 (GMT)
commit32226fa84bf58115e03df86da90713bfa3d4f9f9 (patch)
tree200c770e0bfa3f0c742e98574b358a67530aa44a
parenta69c783749f769f41875ff818c68ead277fd24f9 (diff)
parent45ed175f0898fb407dbc327b660449e1d773c197 (diff)
downloadCMake-32226fa84bf58115e03df86da90713bfa3d4f9f9.zip
CMake-32226fa84bf58115e03df86da90713bfa3d4f9f9.tar.gz
CMake-32226fa84bf58115e03df86da90713bfa3d4f9f9.tar.bz2
Merge topic 'cmList-INSERT-regression' into release-3.27
45ed175f08 list(INSERT): restore old behavior Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !8732
-rw-r--r--Source/cmGeneratorExpressionNode.cxx4
-rw-r--r--Source/cmList.h15
-rw-r--r--Source/cmListCommand.cxx3
-rw-r--r--Tests/CMakeTests/ListTest.cmake.in21
-rw-r--r--Tests/RunCMake/GenEx-LIST/INSERT.cmake.in47
5 files changed, 86 insertions, 4 deletions
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx
index 7fe814a..4c80d4b 100644
--- a/Source/cmGeneratorExpressionNode.cxx
+++ b/Source/cmGeneratorExpressionNode.cxx
@@ -1360,7 +1360,9 @@ static const struct ListNode : public cmGeneratorExpressionNode
try {
auto list = GetList(args.front());
args.advance(2);
- list.insert_items(index, args.begin(), args.end());
+ list.insert_items(index, args.begin(), args.end(),
+ cmList::ExpandElements::No,
+ cmList::EmptyElements::Yes);
return list.to_string();
} catch (std::out_of_range& e) {
reportError(ctx, cnt->GetOriginalExpression(), e.what());
diff --git a/Source/cmList.h b/Source/cmList.h
index 798b984..df450fd 100644
--- a/Source/cmList.h
+++ b/Source/cmList.h
@@ -740,9 +740,20 @@ public:
// Throw std::out_of_range if index is invalid
template <typename InputIterator>
cmList& insert_items(index_type index, InputIterator first,
- InputIterator last)
+ InputIterator last,
+ ExpandElements expandElements = ExpandElements::Yes,
+ EmptyElements emptyElements = EmptyElements::No)
{
- this->insert(this->begin() + this->ComputeInsertIndex(index), first, last);
+ this->insert(this->begin() + this->ComputeInsertIndex(index), first, last,
+ expandElements, emptyElements);
+ return *this;
+ }
+ template <typename InputIterator>
+ cmList& insert_items(index_type index, InputIterator first,
+ InputIterator last, EmptyElements emptyElements)
+ {
+ this->insert(this->begin() + this->ComputeInsertIndex(index), first, last,
+ ExpandElements::Yes, emptyElements);
return *this;
}
cmList& insert_items(index_type index,
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index acffa2e..ebf5841 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -375,7 +375,8 @@ bool HandleInsertCommand(std::vector<std::string> const& args,
}
try {
- list->insert_items(index, args.begin() + 3, args.end());
+ list->insert_items(index, args.begin() + 3, args.end(),
+ cmList::ExpandElements::No, cmList::EmptyElements::Yes);
status.GetMakefile().AddDefinition(listName, list->to_string());
return true;
} catch (std::out_of_range& e) {
diff --git a/Tests/CMakeTests/ListTest.cmake.in b/Tests/CMakeTests/ListTest.cmake.in
index 76737e5..0120c84 100644
--- a/Tests/CMakeTests/ListTest.cmake.in
+++ b/Tests/CMakeTests/ListTest.cmake.in
@@ -161,3 +161,24 @@ foreach (_pol ${thelist})
message(SEND_ERROR "returned element '${thevalue}', but expected '${_pol}'")
endif()
endforeach (_pol)
+
+block(SCOPE_FOR POLICIES)
+ cmake_policy(SET CMP0007 NEW)
+ set(result andy bill brad ken bob)
+ list(INSERT result 1 "")
+ TEST("INSERT result 1 \"\"" "andy;;bill;brad;ken;bob")
+ list(INSERT result 4 ";")
+ TEST("INSERT result 1 ;" "andy;;bill;brad;;;ken;bob")
+ list(INSERT result 0 "x")
+ TEST("INSERT result 1 x" "x;andy;;bill;brad;;;ken;bob")
+endblock()
+block(SCOPE_FOR POLICIES)
+ cmake_policy(SET CMP0007 OLD)
+ set(result andy bill brad ken bob)
+ list(INSERT result 1 "")
+ TEST("INSERT result 1 \"\"" "andy;;bill;brad;ken;bob")
+ list(INSERT result 4 ";")
+ TEST("INSERT result 1 ;" "andy;bill;brad;ken;;;bob")
+ list(INSERT result 0 "x")
+ TEST("INSERT result 1 x" "x;andy;bill;brad;ken;bob")
+endblock()
diff --git a/Tests/RunCMake/GenEx-LIST/INSERT.cmake.in b/Tests/RunCMake/GenEx-LIST/INSERT.cmake.in
index d3bb9b9..48add61 100644
--- a/Tests/RunCMake/GenEx-LIST/INSERT.cmake.in
+++ b/Tests/RunCMake/GenEx-LIST/INSERT.cmake.in
@@ -46,5 +46,52 @@ if (NOT output STREQUAL listvar)
list (APPEND errors "returns bad value: ${output}")
endif()
+block(SCOPE_FOR POLICIES)
+ cmake_policy(SET CMP0007 NEW)
+
+ set(listvar "0;1;2;3;4")
+ list(INSERT listvar 1 "")
+ set (output "$<LIST:INSERT,0;1;2;3;4,1,>")
+ if (NOT output STREQUAL listvar)
+ list (APPEND errors "returns bad value: ${output}")
+ endif()
+
+ list(INSERT listvar 4 ";")
+ set (output "$<LIST:INSERT,0;;1;2;3;4,4,;>")
+ if (NOT output STREQUAL listvar)
+ list (APPEND errors "returns bad value: ${output}")
+ endif()
+
+ list(INSERT listvar 0 "x")
+ set (output "$<LIST:INSERT,0;;1;2;;;3;4,0,x>")
+ if (NOT output STREQUAL listvar)
+ list (APPEND errors "returns bad value: ${output}")
+ endif()
+endblock()
+block(SCOPE_FOR POLICIES)
+ set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "")
+ cmake_policy(SET CMP0007 OLD)
+
+ set(listvar "0;1;2;3;4")
+ list(INSERT listvar 1 "")
+ set (output "$<LIST:INSERT,0;1;2;3;4,1,>")
+ if (NOT output STREQUAL listvar)
+ list (APPEND errors "returns bad value: ${output}")
+ endif()
+
+ list(INSERT listvar 4 ";")
+ set (output "$<LIST:INSERT,0;1;2;3;4,4,;>")
+ if (NOT output STREQUAL listvar)
+ list (APPEND errors "returns bad value: ${output}")
+ endif()
+
+ list(INSERT listvar 0 "x")
+ set (output "$<LIST:INSERT,0;1;2;3;4,0,x>")
+ if (NOT output STREQUAL listvar)
+ list (APPEND errors "returns bad value: ${output}")
+ endif()
+
+ unset(CMAKE_WARN_DEPRECATED CACHE)
+endblock()
check_errors("LIST:INSERT..." ${errors})