From 0be5020bf814efd040f7dcd35cc3a9f07d113458 Mon Sep 17 00:00:00 2001 From: Bartosz Kosiorek Date: Thu, 3 Dec 2015 00:43:37 +0100 Subject: cmake: Improve '-E' help message formatting --- Help/manual/cmake.1.rst | 4 ++-- Source/cmcmd.cxx | 12 ++++++------ Tests/RunCMake/CommandLine/E-no-arg-stderr.txt | 2 +- .../RunCMake/CommandLine/E_create_symlink-no-arg-stderr.txt | 2 +- Tests/RunCMake/CommandLine/E_rename-no-arg-stderr.txt | 2 +- .../RunCMake/CommandLine/E_touch_nocreate-no-arg-stderr.txt | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index dac16bf..3bfab7b 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -193,10 +193,10 @@ Available commands are: ``make_directory `` Create a directory. -``md5sum [...]`` +``md5sum ...`` Compute md5sum of files. -``remove [-f] [...]`` +``remove [-f] ...`` Remove the file(s), use ``-f`` to force it. ``remove_directory `` diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 21b126b..70107eb 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -52,7 +52,7 @@ void CMakeCommandUsage(const char* program) // If you add new commands, change here, // and in cmakemain.cxx in the options table errorStream - << "Usage: " << program << " -E [command] [arguments ...]\n" + << "Usage: " << program << " -E [arguments...]\n" << "Available commands: \n" << " chdir dir cmd [args]... - run command in a given directory\n" << " compare_files file1 file2 - check if file1 is same as file2\n" @@ -62,15 +62,15 @@ void CMakeCommandUsage(const char* program) "content to directory 'destination'\n" << " copy_if_different in-file out-file - copy file if input has " "changed\n" - << " echo [string]... - displays arguments as text\n" - << " echo_append [string]... - displays arguments as text but no new " + << " echo [...] - displays arguments as text\n" + << " echo_append [...] - displays arguments as text but no new " "line\n" << " env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...\n" << " - run command in a modified environment\n" << " environment - display the current environment\n" << " make_directory dir - create a directory\n" - << " md5sum file1 [...] - compute md5sum of files\n" - << " remove [-f] file1 file2 ... - remove the file(s), use -f to force " + << " md5sum ... - compute md5sum 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" << " rename oldname newname - rename a file or directory " @@ -78,7 +78,7 @@ void CMakeCommandUsage(const char* program) << " tar [cxt][vf][zjJ] file.tar [file/dir1 file/dir2 ...]\n" << " - create or extract a tar or zip archive\n" << " sleep ... - sleep for given number of seconds\n" - << " time command [args] ... - run command and return elapsed time\n" + << " time command [args...] - run command and return elapsed time\n" << " touch file - touch a file.\n" << " touch_nocreate file - touch a file but do not create it.\n" #if defined(_WIN32) && !defined(__CYGWIN__) diff --git a/Tests/RunCMake/CommandLine/E-no-arg-stderr.txt b/Tests/RunCMake/CommandLine/E-no-arg-stderr.txt index 056ce05..50d9b03 100644 --- a/Tests/RunCMake/CommandLine/E-no-arg-stderr.txt +++ b/Tests/RunCMake/CommandLine/E-no-arg-stderr.txt @@ -1,3 +1,3 @@ ^CMake Error: cmake version .* -Usage: .* -E \[command\] \[arguments ...\] +Usage: .* -E \[arguments\.\.\.\] Available commands: diff --git a/Tests/RunCMake/CommandLine/E_create_symlink-no-arg-stderr.txt b/Tests/RunCMake/CommandLine/E_create_symlink-no-arg-stderr.txt index 056ce05..50d9b03 100644 --- a/Tests/RunCMake/CommandLine/E_create_symlink-no-arg-stderr.txt +++ b/Tests/RunCMake/CommandLine/E_create_symlink-no-arg-stderr.txt @@ -1,3 +1,3 @@ ^CMake Error: cmake version .* -Usage: .* -E \[command\] \[arguments ...\] +Usage: .* -E \[arguments\.\.\.\] Available commands: diff --git a/Tests/RunCMake/CommandLine/E_rename-no-arg-stderr.txt b/Tests/RunCMake/CommandLine/E_rename-no-arg-stderr.txt index 056ce05..50d9b03 100644 --- a/Tests/RunCMake/CommandLine/E_rename-no-arg-stderr.txt +++ b/Tests/RunCMake/CommandLine/E_rename-no-arg-stderr.txt @@ -1,3 +1,3 @@ ^CMake Error: cmake version .* -Usage: .* -E \[command\] \[arguments ...\] +Usage: .* -E \[arguments\.\.\.\] Available commands: diff --git a/Tests/RunCMake/CommandLine/E_touch_nocreate-no-arg-stderr.txt b/Tests/RunCMake/CommandLine/E_touch_nocreate-no-arg-stderr.txt index 056ce05..50d9b03 100644 --- a/Tests/RunCMake/CommandLine/E_touch_nocreate-no-arg-stderr.txt +++ b/Tests/RunCMake/CommandLine/E_touch_nocreate-no-arg-stderr.txt @@ -1,3 +1,3 @@ ^CMake Error: cmake version .* -Usage: .* -E \[command\] \[arguments ...\] +Usage: .* -E \[arguments\.\.\.\] Available commands: -- cgit v0.12 From 384ae5514e423fccb02e48a4da25e1549556d898 Mon Sep 17 00:00:00 2001 From: Bartosz Kosiorek Date: Thu, 3 Dec 2015 21:29:30 +0100 Subject: cmake: Teach -E copy[_if_different] to support multiple files (#15703) If multiple input files are provided then the destination must be a directory. If only one input file is provided then destination may be either a file or directory. --- Help/manual/cmake.1.rst | 8 +-- Help/release/dev/cmake-E-copy-multiple-inputs.rst | 5 ++ Source/cmcmd.cxx | 61 ++++++++++++++++------ ...source-directory-target-is-directory-result.txt | 1 + ...source-directory-target-is-directory-stderr.txt | 0 .../CommandLine/E_copy-one-source-file-result.txt | 1 + .../CommandLine/E_copy-one-source-file-stderr.txt | 1 + ...ree-source-files-target-is-directory-result.txt | 1 + ...ree-source-files-target-is-directory-stderr.txt | 0 ...py-three-source-files-target-is-file-result.txt | 1 + ...py-three-source-files-target-is-file-stderr.txt | 1 + ...bad-source-files-target-is-directory-result.txt | 1 + ...bad-source-files-target-is-directory-stderr.txt | 1 + ...source-directory-target-is-directory-result.txt | 1 + ...source-directory-target-is-directory-stderr.txt | 0 ...ree-source-files-target-is-directory-result.txt | 1 + ...ree-source-files-target-is-directory-stderr.txt | 0 ...nt-three-source-files-target-is-file-result.txt | 1 + ...nt-three-source-files-target-is-file-stderr.txt | 1 + Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 23 ++++++++ Tests/RunCMake/CommandLine/copy_input/f1.txt | 0 Tests/RunCMake/CommandLine/copy_input/f2.txt | 0 Tests/RunCMake/CommandLine/copy_input/f3.txt | 0 23 files changed, 90 insertions(+), 19 deletions(-) create mode 100644 Help/release/dev/cmake-E-copy-multiple-inputs.rst create mode 100644 Tests/RunCMake/CommandLine/E_copy-one-source-directory-target-is-directory-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy-one-source-directory-target-is-directory-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy-one-source-file-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy-one-source-file-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-directory-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-directory-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy_if_different-one-source-directory-target-is-directory-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy_if_different-one-source-directory-target-is-directory-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-directory-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-directory-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/copy_input/f1.txt create mode 100644 Tests/RunCMake/CommandLine/copy_input/f2.txt create mode 100644 Tests/RunCMake/CommandLine/copy_input/f3.txt diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 3bfab7b..086f259 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -169,14 +169,14 @@ Available commands are: ``compare_files `` Check if file1 is same as file2. -``copy `` - Copy file to destination (either file or directory). +``copy ... `` + Copy files to 'destination' (either file or directory). ``copy_directory `` Copy directory 'source' content to directory 'destination'. -``copy_if_different `` - Copy file if input has changed. +``copy_if_different ... `` + Copy files if input has changed. Destination could be file or directory. ``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 new file mode 100644 index 0000000..798af53 --- /dev/null +++ b/Help/release/dev/cmake-E-copy-multiple-inputs.rst @@ -0,0 +1,5 @@ +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. diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 70107eb..0dc5a9a 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -56,11 +56,11 @@ void CMakeCommandUsage(const char* program) << "Available commands: \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 file destination - copy file to destination (either file " - "or directory)\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_if_different in-file out-file - copy file if input has " + << " copy_if_different ... destination - copy files if it has " "changed\n" << " echo [...] - displays arguments as text\n" << " echo_append [...] - displays arguments as text but no new " @@ -149,29 +149,60 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) if (args.size() > 1) { // Copy file - if (args[1] == "copy" && args.size() == 4) + if (args[1] == "copy" && args.size() > 3) { - if(!cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str())) + // If multiple source files specified, + // then destination must be directory + if ((args.size() > 4) && + (!cmSystemTools::FileIsDirectory(args[args.size() - 1]))) { - std::cerr << "Error copying file \"" << args[2] - << "\" to \"" << args[3] << "\".\n"; + std::cerr << "Error: Target (for copy command) \"" + << args[args.size() - 1] + << "\" is not a directory.\n"; return 1; } - return 0; + // 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 ++) + { + if(!cmSystemTools::cmCopyFile(args[cc].c_str(), + args[args.size() - 1].c_str())) + { + std::cerr << "Error copying file \"" << args[cc] + << "\" to \"" << args[args.size() - 1] << "\".\n"; + return_value = 1; + } + } + return return_value; } // Copy file if different. - if (args[1] == "copy_if_different" && args.size() == 4) + if (args[1] == "copy_if_different" && args.size() > 3) { - if(!cmSystemTools::CopyFileIfDifferent(args[2].c_str(), - args[3].c_str())) + // If multiple source files specified, + // then destination must be directory + if ((args.size() > 4) && + (!cmSystemTools::FileIsDirectory(args[args.size() - 1]))) { - std::cerr << "Error copying file (if different) from \"" - << args[2] << "\" to \"" << args[3] - << "\".\n"; + std::cerr << "Error: Target (for copy_if_different command) \"" + << args[args.size() - 1] + << "\" is not a directory.\n"; return 1; } - return 0; + // 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 ++) + { + if(!cmSystemTools::CopyFileIfDifferent(args[cc].c_str(), + args[args.size() - 1].c_str())) + { + std::cerr << "Error copying file (if different) from \"" + << args[cc] << "\" to \"" << args[args.size() - 1] + << "\".\n"; + return_value = 1; + } + } + return return_value; } // Copy directory content diff --git a/Tests/RunCMake/CommandLine/E_copy-one-source-directory-target-is-directory-result.txt b/Tests/RunCMake/CommandLine/E_copy-one-source-directory-target-is-directory-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy-one-source-directory-target-is-directory-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_copy-one-source-directory-target-is-directory-stderr.txt b/Tests/RunCMake/CommandLine/E_copy-one-source-directory-target-is-directory-stderr.txt new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CommandLine/E_copy-one-source-file-result.txt b/Tests/RunCMake/CommandLine/E_copy-one-source-file-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy-one-source-file-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_copy-one-source-file-stderr.txt b/Tests/RunCMake/CommandLine/E_copy-one-source-file-stderr.txt new file mode 100644 index 0000000..9a9301d --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy-one-source-file-stderr.txt @@ -0,0 +1 @@ +^CMake Error: .* diff --git a/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-directory-result.txt b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-directory-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-directory-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-directory-stderr.txt b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-directory-stderr.txt new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-result.txt b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-stderr.txt b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-stderr.txt new file mode 100644 index 0000000..9504216 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy-three-source-files-target-is-file-stderr.txt @@ -0,0 +1 @@ +^Error: Target \(for copy command\).* is not a directory.$ diff --git a/Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-result.txt b/Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-stderr.txt b/Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-stderr.txt new file mode 100644 index 0000000..2d0d986 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy-two-good-and-one-bad-source-files-target-is-directory-stderr.txt @@ -0,0 +1 @@ +^Error copying file .*not_existing_file.bad\" to .* diff --git a/Tests/RunCMake/CommandLine/E_copy_if_different-one-source-directory-target-is-directory-result.txt b/Tests/RunCMake/CommandLine/E_copy_if_different-one-source-directory-target-is-directory-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy_if_different-one-source-directory-target-is-directory-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_copy_if_different-one-source-directory-target-is-directory-stderr.txt b/Tests/RunCMake/CommandLine/E_copy_if_different-one-source-directory-target-is-directory-stderr.txt new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-directory-result.txt b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-directory-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-directory-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-directory-stderr.txt b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-directory-stderr.txt new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-result.txt b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-stderr.txt b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-stderr.txt new file mode 100644 index 0000000..64b7b1b --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_copy_if_different-three-source-files-target-is-file-stderr.txt @@ -0,0 +1 @@ +^Error: Target \(for copy_if_different command\).* is not a directory.$ diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 6b4b384..dbc235d 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -101,6 +101,29 @@ if(UNIX) ) endif() +set(in ${RunCMake_SOURCE_DIR}/copy_input) +set(out ${RunCMake_BINARY_DIR}/copy_output) +file(REMOVE_RECURSE "${out}") +file(MAKE_DIRECTORY ${out}) +run_cmake_command(E_copy-one-source-file + ${CMAKE_COMMAND} -E copy ${out}/f1.txt) +run_cmake_command(E_copy-one-source-directory-target-is-directory + ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${out}) +run_cmake_command(E_copy-three-source-files-target-is-directory + ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out}) +run_cmake_command(E_copy-three-source-files-target-is-file + ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out}/f1.txt) +run_cmake_command(E_copy-two-good-and-one-bad-source-files-target-is-directory + ${CMAKE_COMMAND} -E copy ${in}/f1.txt ${in}/not_existing_file.bad ${in}/f3.txt ${out}) +run_cmake_command(E_copy_if_different-one-source-directory-target-is-directory + ${CMAKE_COMMAND} -E copy_if_different ${in}/f1.txt ${out}) +run_cmake_command(E_copy_if_different-three-source-files-target-is-directory + ${CMAKE_COMMAND} -E copy_if_different ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out}) +run_cmake_command(E_copy_if_different-three-source-files-target-is-file + ${CMAKE_COMMAND} -E copy_if_different ${in}/f1.txt ${in}/f2.txt ${in}/f3.txt ${out}/f1.txt) +unset(in) +unset(out) + 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/f1.txt b/Tests/RunCMake/CommandLine/copy_input/f1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CommandLine/copy_input/f2.txt b/Tests/RunCMake/CommandLine/copy_input/f2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CommandLine/copy_input/f3.txt b/Tests/RunCMake/CommandLine/copy_input/f3.txt new file mode 100644 index 0000000..e69de29 -- cgit v0.12