list(INSERT): restore old behavior

Fixes: #25191
stage/master/nightly/2023/08/18
Marc Chevrier 2023-08-17 11:47:20 +02:00
parent a69c783749
commit 45ed175f08
5 changed files with 86 additions and 4 deletions

View File

@ -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());

View File

@ -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,

View File

@ -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) {

View File

@ -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()

View File

@ -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})