From 7984ac5e58722295e71f6c2418e2a54d6f1a0cc1 Mon Sep 17 00:00:00 2001 From: Bartosz Kosiorek Date: Wed, 9 Dec 2015 15:59:43 +0100 Subject: [PATCH] cmake: Teach -E make_directory to support multiple input directories --- Help/manual/cmake.1.rst | 10 ++++++---- Help/release/dev/cmake-E-multiple-inputs.rst | 3 +++ Source/cmcmd.cxx | 19 ++++++++++++------- ...directory-directory-with-parent-result.txt | 1 + ...directory-directory-with-parent-stderr.txt | 0 ...tory-three-directories-and-file-result.txt | 1 + ...tory-three-directories-and-file-stderr.txt | 1 + ...ake_directory-three-directories-result.txt | 1 + ...ake_directory-three-directories-stderr.txt | 0 Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 14 ++++++++++++++ 10 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-three-directories-result.txt create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-three-directories-stderr.txt diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 4cbe97678..91af3e3db 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -167,7 +167,8 @@ Available commands are: Change the current working directory and run a command. ``compare_files `` - Check if file1 is same as file2. + Check if ```` is same as ````. If files are the same, + then returns 0, if not itreturns 1. ``copy ... `` Copy files to ```` (either file or directory). @@ -194,10 +195,11 @@ Available commands are: Run command in a modified environment. ``environment`` - Display the current environment. + Display the current environment variables. -``make_directory `` - Create a directory. +``make_directory ...`` + Create ```` directories. If necessary, create parent + directories too. ``md5sum ...`` Compute md5sum of files. diff --git a/Help/release/dev/cmake-E-multiple-inputs.rst b/Help/release/dev/cmake-E-multiple-inputs.rst index aa52a9895..480261d87 100644 --- a/Help/release/dev/cmake-E-multiple-inputs.rst +++ b/Help/release/dev/cmake-E-multiple-inputs.rst @@ -6,3 +6,6 @@ cmake-E-multiple-inputs * The :manual:`cmake(1)` ``-E copy_directory`` command-line tool learned to support copying multiple input directories to a directory. + +* The :manual:`cmake(1)` ``-E make_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 6a4234f09..fb7b1f5ff 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -68,7 +68,7 @@ void CMakeCommandUsage(const char* program) << " 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" + << " make_directory ... - create parent and directories\n" << " md5sum ... - compute md5sum of files\n" << " remove [-f] ... - remove the file(s), use -f to force " "it\n" @@ -447,15 +447,20 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) } #endif - else if (args[1] == "make_directory" && args.size() == 3) + else if (args[1] == "make_directory" && args.size() > 2) { - if(!cmSystemTools::MakeDirectory(args[2].c_str())) + // If error occurs we want to continue copying next files. + bool return_value = 0; + for (std::string::size_type cc = 2; cc < args.size(); cc ++) { - std::cerr << "Error making directory \"" << args[2] - << "\".\n"; - return 1; + if(!cmSystemTools::MakeDirectory(args[cc].c_str())) + { + std::cerr << "Error creating directory \"" + << args[cc] << "\".\n"; + return_value = 1; + } } - return 0; + return return_value; } else if (args[1] == "remove_directory" && args.size() == 3) diff --git a/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-result.txt b/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-result.txt new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-stderr.txt b/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-stderr.txt new file mode 100644 index 000000000..e69de29bb 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 new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-result.txt @@ -0,0 +1 @@ +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 new file mode 100644 index 000000000..08a9428f4 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt @@ -0,0 +1 @@ +^Error creating directory .*file_for_test.txt\".$ diff --git a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-result.txt b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-result.txt new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-stderr.txt b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-stderr.txt new file mode 100644 index 000000000..e69de29bb diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 57036ba3d..5e2200f56 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -140,6 +140,20 @@ unset(in) unset(out) unset(outfile) +set(out ${RunCMake_BINARY_DIR}/make_directory_output) +set(outfile ${out}/file_for_test.txt) +file(REMOVE_RECURSE "${out}") +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_make_directory-directory-with-parent + ${CMAKE_COMMAND} -E make_directory ${out}/parent/child) +run_cmake_command(E_make_directory-three-directories-and-file + ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${outfile}) +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)