This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, master has been updated
       via  ad32282a3e6e7ca648f2e4a40410f08f95023df1 (commit)
       via  a1eb03569d0e82fb6eaf9a11da1960cfa456f5ef (commit)
      from  f01e18eb4699df530e310d376e66752fa6c1dedf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ad32282a3e6e7ca648f2e4a40410f08f95023df1
commit ad32282a3e6e7ca648f2e4a40410f08f95023df1
Merge: f01e18e a1eb035
Author:     Craig Scott <craig.sc...@crascit.com>
AuthorDate: Wed May 22 12:57:15 2019 +0000
Commit:     Kitware Robot <kwro...@kitware.com>
CommitDate: Wed May 22 08:57:29 2019 -0400

    Merge topic 'file-remove-no-empty'
    
    a1eb03569d file: Change REMOVE to ignore empty names
    
    Acked-by: Kitware Robot <kwro...@kitware.com>
    Merge-request: !3349


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a1eb03569d0e82fb6eaf9a11da1960cfa456f5ef
commit a1eb03569d0e82fb6eaf9a11da1960cfa456f5ef
Author:     Brad King <brad.k...@kitware.com>
AuthorDate: Tue May 21 09:20:01 2019 -0400
Commit:     Brad King <brad.k...@kitware.com>
CommitDate: Tue May 21 09:25:32 2019 -0400

    file: Change REMOVE to ignore empty names
    
    Previously code like
    
        file(REMOVE_RECURSE "${accidentally_missing_variable}")
    
    treated the empty string as a relative path with respect to the
    current directory and removed its contents.  Change this behavior
    to ignore the empty string with a warning instead.
    
    Normally such behavior changes are done with a policy, but in this case
    such code is likely a real bug in project code that can delete data.
    
    Fixes: #19274

diff --git a/Help/command/file.rst b/Help/command/file.rst
index 0664e7c..f99021e 100644
--- a/Help/command/file.rst
+++ b/Help/command/file.rst
@@ -292,7 +292,8 @@ Move a file or directory within a filesystem from 
``<oldname>`` to
 
 Remove the given files.  The ``REMOVE_RECURSE`` mode will remove the given
 files and directories, also non-empty directories. No error is emitted if a
-given file does not exist.
+given file does not exist.  Relative input paths are evaluated with respect
+to the current source directory.  Empty input paths are ignored with a warning.
 
 .. _MAKE_DIRECTORY:
 
diff --git a/Help/release/dev/file-remove-no-empty.rst 
b/Help/release/dev/file-remove-no-empty.rst
new file mode 100644
index 0000000..0a68d67
--- /dev/null
+++ b/Help/release/dev/file-remove-no-empty.rst
@@ -0,0 +1,6 @@
+file-remove-no-empty
+--------------------
+
+* The :command:`file(REMOVE)` and :command:`file(REMOVE_RECURSE)` commands
+  were changed to ignore empty arguments with a warning instead of treating
+  them as a relative path and removing the contents of the current directory.
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index f5ec9fe..1349910 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -1405,6 +1405,12 @@ bool 
cmFileCommand::HandleRemove(std::vector<std::string> const& args,
        cmMakeRange(args).advance(1)) // Get rid of subcommand
   {
     std::string fileName = arg;
+    if (fileName.empty()) {
+      std::string const r = recurse ? "REMOVE_RECURSE" : "REMOVE";
+      this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING,
+                                   "Ignoring empty file name in " + r + ".");
+      continue;
+    }
     if (!cmsys::SystemTools::FileIsFullPath(fileName)) {
       fileName = this->Makefile->GetCurrentSourceDirectory();
       fileName += "/" + arg;
diff --git a/Tests/RunCMake/file/REMOVE-empty-stderr.txt 
b/Tests/RunCMake/file/REMOVE-empty-stderr.txt
new file mode 100644
index 0000000..898a6e1
--- /dev/null
+++ b/Tests/RunCMake/file/REMOVE-empty-stderr.txt
@@ -0,0 +1,11 @@
+^CMake Warning \(dev\) at REMOVE-empty.cmake:1 \(file\):
+  Ignoring empty file name in REMOVE.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:[0-9] \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
++
+CMake Warning \(dev\) at REMOVE-empty.cmake:2 \(file\):
+  Ignoring empty file name in REMOVE_RECURSE.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:[0-9] \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/file/REMOVE-empty.cmake 
b/Tests/RunCMake/file/REMOVE-empty.cmake
new file mode 100644
index 0000000..38046fb
--- /dev/null
+++ b/Tests/RunCMake/file/REMOVE-empty.cmake
@@ -0,0 +1,2 @@
+file(REMOVE "")
+file(REMOVE_RECURSE "")
diff --git a/Tests/RunCMake/file/RunCMakeTest.cmake 
b/Tests/RunCMake/file/RunCMakeTest.cmake
index 996d1c5..5db4b3b 100644
--- a/Tests/RunCMake/file/RunCMakeTest.cmake
+++ b/Tests/RunCMake/file/RunCMakeTest.cmake
@@ -43,6 +43,8 @@ run_cmake(GLOB_RECURSE-noexp-FOLLOW_SYMLINKS)
 run_cmake(SIZE)
 run_cmake(SIZE-error-does-not-exist)
 
+run_cmake(REMOVE-empty)
+
 # tests are valid both for GLOB and GLOB_RECURSE
 run_cmake(GLOB-sort-dedup)
 run_cmake(GLOB-error-LIST_DIRECTORIES-not-boolean)

-----------------------------------------------------------------------

Summary of changes:
 Help/command/file.rst                       |  3 ++-
 Help/release/dev/file-remove-no-empty.rst   |  6 ++++++
 Source/cmFileCommand.cxx                    |  6 ++++++
 Tests/RunCMake/file/REMOVE-empty-stderr.txt | 11 +++++++++++
 Tests/RunCMake/file/REMOVE-empty.cmake      |  2 ++
 Tests/RunCMake/file/RunCMakeTest.cmake      |  2 ++
 6 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 Help/release/dev/file-remove-no-empty.rst
 create mode 100644 Tests/RunCMake/file/REMOVE-empty-stderr.txt
 create mode 100644 Tests/RunCMake/file/REMOVE-empty.cmake


hooks/post-receive
-- 
CMake
_______________________________________________
Cmake-commits mailing list
Cmake-commits@cmake.org
https://cmake.org/mailman/listinfo/cmake-commits

Reply via email to