From 3eb16de32733c7d3f61d22b16a893135267e7bbc Mon Sep 17 00:00:00 2001 From: John Freeman Date: Fri, 31 May 2019 16:35:41 -0500 Subject: Tests: Fix RunCMake.CommandLine make_directory test name --- .../CommandLine/E_make_directory-three-directories-and-file-result.txt | 1 - .../CommandLine/E_make_directory-three-directories-and-file-stderr.txt | 1 - .../CommandLine/E_make_directory-two-directories-and-file-result.txt | 1 + .../CommandLine/E_make_directory-two-directories-and-file-stderr.txt | 1 + Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 2 +- 5 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-result.txt delete mode 100644 Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-two-directories-and-file-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-two-directories-and-file-stderr.txt diff --git a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-result.txt b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt deleted file mode 100644 index 08a9428..0000000 --- a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt +++ /dev/null @@ -1 +0,0 @@ -^Error creating directory .*file_for_test.txt\".$ diff --git a/Tests/RunCMake/CommandLine/E_make_directory-two-directories-and-file-result.txt b/Tests/RunCMake/CommandLine/E_make_directory-two-directories-and-file-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_make_directory-two-directories-and-file-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_make_directory-two-directories-and-file-stderr.txt b/Tests/RunCMake/CommandLine/E_make_directory-two-directories-and-file-stderr.txt new file mode 100644 index 0000000..08a9428 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_make_directory-two-directories-and-file-stderr.txt @@ -0,0 +1 @@ +^Error creating directory .*file_for_test.txt\".$ diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index cee996c..25a6435 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -334,7 +334,7 @@ run_cmake_command(E_make_directory-three-directories ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${out}/d2) run_cmake_command(E_make_directory-directory-with-parent ${CMAKE_COMMAND} -E make_directory ${out}/parent/child) -run_cmake_command(E_make_directory-three-directories-and-file +run_cmake_command(E_make_directory-two-directories-and-file ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${outfile}) unset(out) unset(outfile) -- cgit v0.12 From 013bee698e8470169d99e90aa86d5d85693c6b12 Mon Sep 17 00:00:00 2001 From: John Freeman Date: Fri, 31 May 2019 16:35:41 -0500 Subject: Tests: Add RunCMake.CommandLine make_directory test checks --- .../CommandLine/E_make_directory-directory-with-parent-check.cmake | 3 +++ .../CommandLine/E_make_directory-three-directories-check.cmake | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-check.cmake create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-three-directories-check.cmake diff --git a/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-check.cmake b/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-check.cmake new file mode 100644 index 0000000..ea3d161 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-check.cmake @@ -0,0 +1,3 @@ +if(NOT IS_DIRECTORY ${out}/parent/child) + set(RunCMake_TEST_FAILED "child directory was not created") +endif() diff --git a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-check.cmake b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-check.cmake new file mode 100644 index 0000000..c1e8474 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-check.cmake @@ -0,0 +1,6 @@ +if(NOT IS_DIRECTORY ${out}/d1) + set(RunCMake_TEST_FAILED "directory d1 was not created") +endif() +if(NOT IS_DIRECTORY ${out}/d2) + set(RunCMake_TEST_FAILED "directory d2 was not created") +endif() -- cgit v0.12 From 07a80c70020e0e533db8d75d7fe7c4270cc25afb Mon Sep 17 00:00:00 2001 From: John Freeman Date: Fri, 31 May 2019 16:35:41 -0500 Subject: cmake: Teach -E remove_directory to remove multiple directories The `make_directory` command can make multiple directories in a single invocation. Make `remove_directory` mirror that behavior. --- Help/manual/cmake.1.rst | 4 ++-- Help/release/dev/remove_directories.rst | 5 +++++ Source/cmcmd.cxx | 20 ++++++++++++-------- ...emove_directory-directory-with-parent-check.cmake | 3 +++ ...remove_directory-directory-with-parent-stderr.txt | 0 .../E_remove_directory-three-directories-check.cmake | 6 ++++++ .../E_remove_directory-three-directories-stderr.txt | 0 ...ve_directory-two-directories-and-file-check.cmake | 3 +++ ...ove_directory-two-directories-and-file-stderr.txt | 0 Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 6 ++++++ Tests/StagingPrefix/CMakeLists.txt | 11 ++++++----- 11 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 Help/release/dev/remove_directories.rst create mode 100644 Tests/RunCMake/CommandLine/E_remove_directory-directory-with-parent-check.cmake create mode 100644 Tests/RunCMake/CommandLine/E_remove_directory-directory-with-parent-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/E_remove_directory-three-directories-check.cmake create mode 100644 Tests/RunCMake/CommandLine/E_remove_directory-three-directories-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/E_remove_directory-two-directories-and-file-check.cmake create mode 100644 Tests/RunCMake/CommandLine/E_remove_directory-two-directories-and-file-stderr.txt diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 107c2cb..f1d02eb 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -514,8 +514,8 @@ Available commands are: ``remove`` does not follow symlinks. That means it remove only symlinks and not files it point to. -``remove_directory `` - Remove a directory and its contents. If a directory does +``remove_directory ...`` + Remove ```` directories and their contents. If a directory does not exist it will be silently ignored. ``rename `` diff --git a/Help/release/dev/remove_directories.rst b/Help/release/dev/remove_directories.rst new file mode 100644 index 0000000..1b16df1 --- /dev/null +++ b/Help/release/dev/remove_directories.rst @@ -0,0 +1,5 @@ +remove_directories +------------------ + +* The :manual:`cmake(1)` ``-E remove_directory`` command learned to support + removing multiple directories. diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index f4ef45c..a983d30 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -103,7 +103,7 @@ void CMakeCommandUsage(const char* program) << " sha512sum ... - create SHA512 checksum of files\n" << " remove [-f] ... - remove the file(s), use -f to force " "it\n" - << " remove_directory dir - remove a directory and its contents\n" + << " remove_directory ... - remove directories and their contents\n" << " rename oldname newname - rename a file or directory " "(on one volume)\n" << " server - start cmake in server mode\n" @@ -661,7 +661,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector const& args) #endif if (args[1] == "make_directory" && args.size() > 2) { - // If error occurs we want to continue copying next files. + // If an error occurs, we want to continue making directories. bool return_value = false; for (auto const& arg : cmMakeRange(args).advance(2)) { if (!cmSystemTools::MakeDirectory(arg)) { @@ -672,13 +672,17 @@ int cmcmd::ExecuteCMakeCommand(std::vector const& args) return return_value; } - if (args[1] == "remove_directory" && args.size() == 3) { - if (cmSystemTools::FileIsDirectory(args[2]) && - !cmSystemTools::RemoveADirectory(args[2])) { - std::cerr << "Error removing directory \"" << args[2] << "\".\n"; - return 1; + if (args[1] == "remove_directory" && args.size() > 2) { + // If an error occurs, we want to continue removing directories. + bool return_value = false; + for (auto const& arg : cmMakeRange(args).advance(2)) { + if (cmSystemTools::FileIsDirectory(arg) && + !cmSystemTools::RemoveADirectory(arg)) { + std::cerr << "Error removing directory \"" << arg << "\".\n"; + return_value = true; + } } - return 0; + return return_value; } // Remove file diff --git a/Tests/RunCMake/CommandLine/E_remove_directory-directory-with-parent-check.cmake b/Tests/RunCMake/CommandLine/E_remove_directory-directory-with-parent-check.cmake new file mode 100644 index 0000000..fd6ea11 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_remove_directory-directory-with-parent-check.cmake @@ -0,0 +1,3 @@ +if(IS_DIRECTORY ${out}/parent/child) + set(RunCMake_TEST_FAILED "child directory was not removed") +endif() diff --git a/Tests/RunCMake/CommandLine/E_remove_directory-directory-with-parent-stderr.txt b/Tests/RunCMake/CommandLine/E_remove_directory-directory-with-parent-stderr.txt new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CommandLine/E_remove_directory-three-directories-check.cmake b/Tests/RunCMake/CommandLine/E_remove_directory-three-directories-check.cmake new file mode 100644 index 0000000..2b7202a --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_remove_directory-three-directories-check.cmake @@ -0,0 +1,6 @@ +if(IS_DIRECTORY ${out}/d1) + set(RunCMake_TEST_FAILED "directory d1 was not removed") +endif() +if(IS_DIRECTORY ${out}/d2) + set(RunCMake_TEST_FAILED "directory d2 was not removed") +endif() diff --git a/Tests/RunCMake/CommandLine/E_remove_directory-three-directories-stderr.txt b/Tests/RunCMake/CommandLine/E_remove_directory-three-directories-stderr.txt new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CommandLine/E_remove_directory-two-directories-and-file-check.cmake b/Tests/RunCMake/CommandLine/E_remove_directory-two-directories-and-file-check.cmake new file mode 100644 index 0000000..0aa4a52 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_remove_directory-two-directories-and-file-check.cmake @@ -0,0 +1,3 @@ +if(NOT EXISTS ${outfile}) + set(RunCMake_TEST_FAILED "removed non-directory ${outfile}") +endif() diff --git a/Tests/RunCMake/CommandLine/E_remove_directory-two-directories-and-file-stderr.txt b/Tests/RunCMake/CommandLine/E_remove_directory-two-directories-and-file-stderr.txt new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 25a6435..6c17a6a 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -332,10 +332,16 @@ file(MAKE_DIRECTORY ${out}) file(WRITE ${outfile} "") run_cmake_command(E_make_directory-three-directories ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${out}/d2) +run_cmake_command(E_remove_directory-three-directories + ${CMAKE_COMMAND} -E remove_directory ${out}/d1 ${out}/d2 ${out}/d2) run_cmake_command(E_make_directory-directory-with-parent ${CMAKE_COMMAND} -E make_directory ${out}/parent/child) +run_cmake_command(E_remove_directory-directory-with-parent + ${CMAKE_COMMAND} -E remove_directory ${out}/parent) run_cmake_command(E_make_directory-two-directories-and-file ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${outfile}) +run_cmake_command(E_remove_directory-two-directories-and-file + ${CMAKE_COMMAND} -E remove_directory ${out}/d1 ${out}/d2 ${outfile}) unset(out) unset(outfile) diff --git a/Tests/StagingPrefix/CMakeLists.txt b/Tests/StagingPrefix/CMakeLists.txt index 64a3cd2..8d2519e 100644 --- a/Tests/StagingPrefix/CMakeLists.txt +++ b/Tests/StagingPrefix/CMakeLists.txt @@ -5,11 +5,12 @@ project(StagingPrefix) # Wipe out the install tree add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/CleanupProject - COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/ConsumerBuild - COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/ProducerBuild - COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/stage - COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/prefix - COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/ignored + COMMAND ${CMAKE_COMMAND} -E remove_directory + ${CMAKE_BINARY_DIR}/ConsumerBuild + ${CMAKE_BINARY_DIR}/ProducerBuild + ${CMAKE_BINARY_DIR}/stage + ${CMAKE_BINARY_DIR}/prefix + ${CMAKE_BINARY_DIR}/ignored ) add_custom_target(CleanupTarget ALL DEPENDS ${CMAKE_BINARY_DIR}/CleanupProject) set_property( -- cgit v0.12