diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 086f259a5..4cbe97678 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -170,13 +170,19 @@ Available commands are: Check if file1 is same as file2. ``copy ... `` - Copy files to 'destination' (either file or directory). + Copy files to ```` (either file or directory). + If multiple files are specified, the ```` must be + directory and it must exist. -``copy_directory `` - Copy directory 'source' content to directory 'destination'. +``copy_directory ... `` + Copy directories to ```` directory. + If ```` directory does not exist it will be created. ``copy_if_different ... `` - Copy files if input has changed. Destination could be file or directory. + Copy files to ```` (either file or directory) if + they have changed. + If multiple files are specified, the ```` must be + directory and it must exist. ``echo [...]`` Displays arguments as text. diff --git a/Help/release/dev/cmake-E-copy-multiple-inputs.rst b/Help/release/dev/cmake-E-copy-multiple-inputs.rst index 798af530d..eeb1fabc7 100644 --- a/Help/release/dev/cmake-E-copy-multiple-inputs.rst +++ b/Help/release/dev/cmake-E-copy-multiple-inputs.rst @@ -3,3 +3,6 @@ cmake-E-copy-multiple-inputs * The :manual:`cmake(1)` ``-E copy`` and ``-E copy_if_different`` command-line tools learned to support copying multiple input files to a directory. + +* The :manual:`cmake(1)` ``-E copy_directory`` command-line + tool learned to support copying multiple input directories to a directory. diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 0dc5a9a35..6a4234f09 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -54,12 +54,12 @@ void CMakeCommandUsage(const char* program) errorStream << "Usage: " << program << " -E [arguments...]\n" << "Available commands: \n" - << " chdir dir cmd [args]... - run command in a given directory\n" + << " chdir dir cmd [args...] - run command in a given directory\n" << " compare_files file1 file2 - check if file1 is same as file2\n" << " copy ... destination - copy files to destination " "(either file or directory)\n" - << " copy_directory source destination - copy directory 'source' " - "content to directory 'destination'\n" + << " copy_directory ... destination - copy content of ... " + "directories to 'destination' directory\n" << " copy_if_different ... destination - copy files if it has " "changed\n" << " echo [...] - displays arguments as text\n" @@ -197,8 +197,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) args[args.size() - 1].c_str())) { std::cerr << "Error copying file (if different) from \"" - << args[cc] << "\" to \"" << args[args.size() - 1] - << "\".\n"; + << args[cc] << "\" to \"" << args[args.size() - 1] + << "\".\n"; return_value = 1; } } @@ -206,16 +206,22 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) } // Copy directory content - if (args[1] == "copy_directory" && args.size() == 4) + if (args[1] == "copy_directory" && args.size() > 3) { - if(!cmSystemTools::CopyADirectory(args[2], args[3])) + // If error occurs we want to continue copying next files. + bool return_value = 0; + for (std::string::size_type cc = 2; cc < args.size() - 1; cc ++) { - std::cerr << "Error copying directory from \"" - << args[2] << "\" to \"" << args[3] - << "\".\n"; - return 1; + if(!cmSystemTools::CopyADirectory(args[cc].c_str(), + args[args.size() - 1].c_str())) + { + std::cerr << "Error copying directory from \"" + << args[cc] << "\" to \"" << args[args.size() - 1] + << "\".\n"; + return_value = 1; + } } - return 0; + return return_value; } // Rename a file or directory diff --git a/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-directory-result.txt b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-directory-result.txt new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-directory-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-directory-stderr.txt b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-directory-stderr.txt new file mode 100644 index 000000000..e69de29bb diff --git a/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-file-result.txt b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-file-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-file-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-file-stderr.txt b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-file-stderr.txt new file mode 100644 index 000000000..6ca367767 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-file-stderr.txt @@ -0,0 +1,3 @@ +^Error copying directory from .* to .*file_for_test.txt\".* +Error copying directory from .* to .*file_for_test.txt\".* +Error copying directory from .* to .*file_for_test.txt\".$ diff --git a/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-not-exist-result.txt b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-not-exist-result.txt new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-not-exist-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-not-exist-stderr.txt b/Tests/RunCMake/CommandLine/E_copy_directory-three-source-files-target-is-not-exist-stderr.txt new file mode 100644 index 000000000..e69de29bb diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index dbc235dfa..57036ba3d 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -124,6 +124,23 @@ run_cmake_command(E_copy_if_different-three-source-files-target-is-file unset(in) unset(out) +set(in ${RunCMake_SOURCE_DIR}/copy_input) +set(out ${RunCMake_BINARY_DIR}/copy_directory_output) +set(outfile ${out}/file_for_test.txt) +file(REMOVE_RECURSE "${out}") +file(MAKE_DIRECTORY ${out}) +file(WRITE ${outfile} "") +run_cmake_command(E_copy_directory-three-source-files-target-is-directory + ${CMAKE_COMMAND} -E copy_directory ${in}/d1 ${in}/d2 ${in}/d3 ${out}) +run_cmake_command(E_copy_directory-three-source-files-target-is-file + ${CMAKE_COMMAND} -E copy_directory ${in}/d1 ${in}/d2 ${in}/d3 ${outfile}) +run_cmake_command(E_copy_directory-three-source-files-target-is-not-exist + ${CMAKE_COMMAND} -E copy_directory ${in}/d1 ${in}/d2 ${in}/d3 ${out}/not_existing_directory) +unset(in) +unset(out) +unset(outfile) + + run_cmake_command(E_env-no-command0 ${CMAKE_COMMAND} -E env) run_cmake_command(E_env-no-command1 ${CMAKE_COMMAND} -E env TEST_ENV=1) run_cmake_command(E_env-bad-arg1 ${CMAKE_COMMAND} -E env -bad-arg1) diff --git a/Tests/RunCMake/CommandLine/copy_input/d1/d1.txt b/Tests/RunCMake/CommandLine/copy_input/d1/d1.txt new file mode 100644 index 000000000..e69de29bb diff --git a/Tests/RunCMake/CommandLine/copy_input/d2/d2.txt b/Tests/RunCMake/CommandLine/copy_input/d2/d2.txt new file mode 100644 index 000000000..e69de29bb diff --git a/Tests/RunCMake/CommandLine/copy_input/d3/d3.txt b/Tests/RunCMake/CommandLine/copy_input/d3/d3.txt new file mode 100644 index 000000000..e69de29bb