mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-12 22:17:06 +00:00
Merge topic 'sort_glob_output'
87a6816bafAdd test for sorting and deduping of file(GLOB) resultb688d4fd22file(GLOB): Ensure entire file list is sorted Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !1821
This commit is contained in:
@@ -757,8 +757,7 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
|
||||
}
|
||||
}
|
||||
|
||||
std::ostringstream outputStream;
|
||||
bool first = true;
|
||||
std::vector<std::string> files;
|
||||
bool warnFollowedSymlinks = false;
|
||||
while (i != args.end()) {
|
||||
if (*i == "LIST_DIRECTORIES") {
|
||||
@@ -848,15 +847,8 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
|
||||
warnFollowedSymlinks = true;
|
||||
}
|
||||
|
||||
std::vector<std::string>& files = g.GetFiles();
|
||||
std::sort(files.begin(), files.end());
|
||||
for (std::string const& file : files) {
|
||||
if (!first) {
|
||||
outputStream << ";";
|
||||
}
|
||||
outputStream << file;
|
||||
first = false;
|
||||
}
|
||||
std::vector<std::string>& foundFiles = g.GetFiles();
|
||||
files.insert(files.end(), foundFiles.begin(), foundFiles.end());
|
||||
++i;
|
||||
}
|
||||
}
|
||||
@@ -880,7 +872,10 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
|
||||
}
|
||||
break;
|
||||
}
|
||||
this->Makefile->AddDefinition(variable, outputStream.str().c_str());
|
||||
|
||||
std::sort(files.begin(), files.end());
|
||||
files.erase(std::unique(files.begin(), files.end()), files.end());
|
||||
this->Makefile->AddDefinition(variable, cmJoin(files, ";").c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
2
Tests/RunCMake/file/GLOB-sort-dedup-stderr.txt
Normal file
2
Tests/RunCMake/file/GLOB-sort-dedup-stderr.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
content: 7[ ]
|
||||
1aAb/\.hide;1aAb/1\.log;1aAb/1\.txt;1aAb/xkcd\.txt;a/1\.log;a/1\.txt;a/boot\.ini
|
||||
21
Tests/RunCMake/file/GLOB-sort-dedup.cmake
Normal file
21
Tests/RunCMake/file/GLOB-sort-dedup.cmake
Normal file
@@ -0,0 +1,21 @@
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test/a")
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test/1aAb")
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/a/1.log" "")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/a/1.txt" "")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/a/boot.ini" "")
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/1aAb/.hide" "")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/1aAb/1.txt" "")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/1aAb/1.log" "")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test/1aAb/xkcd.txt" "")
|
||||
|
||||
file(GLOB CONTENT_LIST
|
||||
LIST_DIRECTORIES false
|
||||
RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/test"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/test/a/*"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/test/*/*"
|
||||
)
|
||||
list(LENGTH CONTENT_LIST CONTENT_COUNT)
|
||||
message("content: ${CONTENT_COUNT} ")
|
||||
message("${CONTENT_LIST}")
|
||||
@@ -38,6 +38,7 @@ run_cmake(GLOB_RECURSE)
|
||||
run_cmake(GLOB_RECURSE-noexp-FOLLOW_SYMLINKS)
|
||||
|
||||
# tests are valid both for GLOB and GLOB_RECURSE
|
||||
run_cmake(GLOB-sort-dedup)
|
||||
run_cmake(GLOB-error-FOLLOW_SYMLINKS)
|
||||
run_cmake(GLOB-error-LIST_DIRECTORIES-not-boolean)
|
||||
run_cmake(GLOB-error-LIST_DIRECTORIES-no-arg)
|
||||
|
||||
Reference in New Issue
Block a user