[Cmake-commits] CMake branch, master, updated. v3.14.0-473-gfac0938

Kitware Robot kwrobot at kitware.com
Thu Mar 21 10:53:08 EDT 2019


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  fac093802a85cad720efe9e42957014b3b5c5561 (commit)
       via  ea9a2c175929f8276ef80ee85f81675fccd9c757 (commit)
      from  e09c606eb47c13bd435892625943e95bb9452996 (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=fac093802a85cad720efe9e42957014b3b5c5561
commit fac093802a85cad720efe9e42957014b3b5c5561
Merge: e09c606 ea9a2c1
Author:     Kyle Edwards <kyle.edwards at kitware.com>
AuthorDate: Thu Mar 21 14:50:07 2019 +0000
Commit:     Kitware Robot <kwrobot at kitware.com>
CommitDate: Thu Mar 21 10:50:38 2019 -0400

    Merge topic 'tar-improve-error-handling'
    
    ea9a2c1759 cmake: tar: Parse 'cmake -E tar' arguments
    
    Acked-by: Kitware Robot <kwrobot at kitware.com>
    Merge-request: !3081


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ea9a2c175929f8276ef80ee85f81675fccd9c757
commit ea9a2c175929f8276ef80ee85f81675fccd9c757
Author:     Bartosz Kosiorek <gang65 at poczta.onet.pl>
AuthorDate: Fri Mar 8 23:20:52 2019 +0100
Commit:     Kyle Edwards <kyle.edwards at kitware.com>
CommitDate: Wed Mar 20 09:28:49 2019 -0400

    cmake: tar: Parse 'cmake -E tar' arguments

diff --git a/Help/release/dev/cmake-e-tar-error-handling.rst b/Help/release/dev/cmake-e-tar-error-handling.rst
new file mode 100644
index 0000000..d1f2c72
--- /dev/null
+++ b/Help/release/dev/cmake-e-tar-error-handling.rst
@@ -0,0 +1,8 @@
+cmake-e-tar-error-handling
+--------------------------
+
+* The :manual:`cmake(1)` ``-E tar`` tool now parses all flags, and if an
+  invalid flag was provided, a warning is issued.
+* The :manual:`cmake(1)` ``-E tar`` tool now displays an error if no action
+  flag was specified, along with a list of possible actions: ``t`` (list),
+  ``c`` (create) or ``x`` (extract).
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 60e8c18..352762c 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -412,6 +412,14 @@ public:
   /** Setup the environment to enable VS 8 IDE output.  */
   static void EnableVSConsoleOutput();
 
+  enum cmTarAction
+  {
+    TarActionCreate,
+    TarActionList,
+    TarActionExtract,
+    TarActionNone
+  };
+
   /** Create tar */
   enum cmTarCompression
   {
@@ -420,6 +428,7 @@ public:
     TarCompressXZ,
     TarCompressNone
   };
+
   static bool ListTar(const char* outFileName, bool verbose);
   static bool CreateTar(const char* outFileName,
                         const std::vector<std::string>& files,
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 0828a16..8d63971 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -1078,21 +1078,47 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
           files.push_back(arg);
         }
       }
+      cmSystemTools::cmTarAction action = cmSystemTools::TarActionNone;
       cmSystemTools::cmTarCompression compress =
         cmSystemTools::TarCompressNone;
       bool verbose = false;
       int nCompress = 0;
-      if (flags.find_first_of('j') != std::string::npos) {
-        compress = cmSystemTools::TarCompressBZip2;
-        ++nCompress;
-      }
-      if (flags.find_first_of('J') != std::string::npos) {
-        compress = cmSystemTools::TarCompressXZ;
-        ++nCompress;
-      }
-      if (flags.find_first_of('z') != std::string::npos) {
-        compress = cmSystemTools::TarCompressGZip;
-        ++nCompress;
+
+      for (auto flag : flags) {
+        switch (flag) {
+          case '-':
+          case 'f': {
+            // Keep for backward compatibility. Ignored
+          } break;
+          case 'j': {
+            compress = cmSystemTools::TarCompressBZip2;
+            ++nCompress;
+          } break;
+          case 'J': {
+            compress = cmSystemTools::TarCompressXZ;
+            ++nCompress;
+          } break;
+          case 'z': {
+            compress = cmSystemTools::TarCompressGZip;
+            ++nCompress;
+          } break;
+          case 'v': {
+            verbose = true;
+          } break;
+          case 't': {
+            action = cmSystemTools::TarActionList;
+          } break;
+          case 'c': {
+            action = cmSystemTools::TarActionCreate;
+          } break;
+          case 'x': {
+            action = cmSystemTools::TarActionExtract;
+          } break;
+          default: {
+            cmSystemTools::Message(
+              std::string("tar: Unknown argument: ") + flag, "Warning");
+          }
+        }
       }
       if ((format == "7zip" || format == "zip") && nCompress > 0) {
         cmSystemTools::Error("Can not use compression flags with format: " +
@@ -1104,16 +1130,12 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
                              "at most one flag of z, j, or J may be used");
         return 1;
       }
-      if (flags.find_first_of('v') != std::string::npos) {
-        verbose = true;
-      }
-
-      if (flags.find_first_of('t') != std::string::npos) {
+      if (action == cmSystemTools::TarActionList) {
         if (!cmSystemTools::ListTar(outFile.c_str(), verbose)) {
           cmSystemTools::Error("Problem listing tar: " + outFile);
           return 1;
         }
-      } else if (flags.find_first_of('c') != std::string::npos) {
+      } else if (action == cmSystemTools::TarActionCreate) {
         if (files.empty()) {
           cmSystemTools::Message("tar: No files or directories specified",
                                  "Warning");
@@ -1123,7 +1145,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
           cmSystemTools::Error("Problem creating tar: " + outFile);
           return 1;
         }
-      } else if (flags.find_first_of('x') != std::string::npos) {
+      } else if (action == cmSystemTools::TarActionExtract) {
         if (!cmSystemTools::ExtractTar(outFile.c_str(), verbose)) {
           cmSystemTools::Error("Problem extracting tar: " + outFile);
           return 1;
@@ -1144,6 +1166,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
           cmSystemTools::Delay(delay);
         }
 #endif
+      } else {
+        cmSystemTools::Error("tar: No action specified. Please choose: 't' "
+                             "(list), 'c' (create) or 'x' (extract)");
+        return 1;
       }
       return 0;
     }
diff --git a/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake b/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake
index c8a3de9..5deb110 100644
--- a/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake
@@ -4,21 +4,23 @@ function(external_command_test NAME)
   run_cmake_command(${NAME} ${CMAKE_COMMAND} -E ${ARGN})
 endfunction()
 
-external_command_test(without-files tar cvf bad.tar)
-external_command_test(bad-opt1   tar cvf bad.tar --bad)
-external_command_test(bad-mtime1 tar cvf bad.tar --mtime=bad .)
-external_command_test(bad-from1  tar cvf bad.tar --files-from=bad)
-external_command_test(bad-from2  tar cvf bad.tar --files-from=.)
-external_command_test(bad-from3  tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from3.txt)
-external_command_test(bad-from4  tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from4.txt)
-external_command_test(bad-from5  tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from5.txt)
-external_command_test(bad-file   tar cf  bad.tar badfile.txt ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
-external_command_test(end-opt1   tar cvf bad.tar -- --bad)
-external_command_test(end-opt2   tar cvf bad.tar --)
-external_command_test(mtime      tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
-external_command_test(bad-format tar cvf bad.tar "--format=bad-format" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
-external_command_test(zip-bz2    tar cvjf bad.tar "--format=zip" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
-external_command_test(7zip-gz    tar cvzf bad.tar "--format=7zip" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(without-files      tar cvf bad.tar)
+external_command_test(bad-opt1           tar cvf bad.tar --bad)
+external_command_test(bad-mtime1         tar cvf bad.tar --mtime=bad .)
+external_command_test(bad-from1          tar cvf bad.tar --files-from=bad)
+external_command_test(bad-from2          tar cvf bad.tar --files-from=.)
+external_command_test(bad-from3          tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from3.txt)
+external_command_test(bad-from4          tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from4.txt)
+external_command_test(bad-from5          tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from5.txt)
+external_command_test(bad-file           tar cf  bad.tar badfile.txt ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(bad-without-action tar f bad.tar ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(bad-wrong-flag     tar cvfq bad.tar ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(end-opt1           tar cvf bad.tar -- --bad)
+external_command_test(end-opt2           tar cvf bad.tar --)
+external_command_test(mtime              tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(bad-format         tar cvf bad.tar "--format=bad-format" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(zip-bz2            tar cvjf bad.tar "--format=zip" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(7zip-gz            tar cvzf bad.tar "--format=7zip" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
 
 run_cmake(7zip)
 run_cmake(gnutar)
diff --git a/Tests/RunCMake/CommandLineTar/bad-without-action-result.txt b/Tests/RunCMake/CommandLineTar/bad-without-action-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CommandLineTar/bad-without-action-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLineTar/bad-without-action-stderr.txt b/Tests/RunCMake/CommandLineTar/bad-without-action-stderr.txt
new file mode 100644
index 0000000..2fec254
--- /dev/null
+++ b/Tests/RunCMake/CommandLineTar/bad-without-action-stderr.txt
@@ -0,0 +1 @@
+^CMake Error: tar: No action specified. Please choose: 't' \(list\), 'c' \(create\) or 'x' \(extract\)$
diff --git a/Tests/RunCMake/CommandLineTar/bad-wrong-flag-stderr.txt b/Tests/RunCMake/CommandLineTar/bad-wrong-flag-stderr.txt
new file mode 100644
index 0000000..d5c1e01
--- /dev/null
+++ b/Tests/RunCMake/CommandLineTar/bad-wrong-flag-stderr.txt
@@ -0,0 +1 @@
+^tar: Unknown argument: q
diff --git a/Tests/RunCMake/CommandLineTar/gnutar-gz.cmake b/Tests/RunCMake/CommandLineTar/gnutar-gz.cmake
index 5f2674a..53ee961 100644
--- a/Tests/RunCMake/CommandLineTar/gnutar-gz.cmake
+++ b/Tests/RunCMake/CommandLineTar/gnutar-gz.cmake
@@ -1,9 +1,9 @@
 set(OUTPUT_NAME "test.tar.gz")
 
-set(COMPRESSION_FLAGS cvzf)
+set(COMPRESSION_FLAGS -cvzf)
 set(COMPRESSION_OPTIONS --format=gnutar)
 
-set(DECOMPRESSION_FLAGS xvzf)
+set(DECOMPRESSION_FLAGS -xvzf)
 
 include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
 
diff --git a/Tests/RunCMake/CommandLineTar/pax.cmake b/Tests/RunCMake/CommandLineTar/pax.cmake
index 60ed238..77f74d1 100644
--- a/Tests/RunCMake/CommandLineTar/pax.cmake
+++ b/Tests/RunCMake/CommandLineTar/pax.cmake
@@ -1,9 +1,9 @@
 set(OUTPUT_NAME "test.tar")
 
-set(COMPRESSION_FLAGS cvf)
+set(COMPRESSION_FLAGS -cvf)
 set(COMPRESSION_OPTIONS --format=pax)
 
-set(DECOMPRESSION_FLAGS xvf)
+set(DECOMPRESSION_FLAGS -xvf)
 
 include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
 

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

Summary of changes:
 Help/release/dev/cmake-e-tar-error-handling.rst    |  8 +++
 Source/cmSystemTools.h                             |  9 ++++
 Source/cmcmd.cxx                                   | 62 +++++++++++++++-------
 Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake   | 32 +++++------
 .../bad-without-action-result.txt}                 |  0
 .../CommandLineTar/bad-without-action-stderr.txt   |  1 +
 .../CommandLineTar/bad-wrong-flag-stderr.txt       |  1 +
 Tests/RunCMake/CommandLineTar/gnutar-gz.cmake      |  4 +-
 Tests/RunCMake/CommandLineTar/pax.cmake            |  4 +-
 9 files changed, 84 insertions(+), 37 deletions(-)
 create mode 100644 Help/release/dev/cmake-e-tar-error-handling.rst
 copy Tests/RunCMake/{while/MissingArgument-result.txt => CommandLineTar/bad-without-action-result.txt} (100%)
 create mode 100644 Tests/RunCMake/CommandLineTar/bad-without-action-stderr.txt
 create mode 100644 Tests/RunCMake/CommandLineTar/bad-wrong-flag-stderr.txt


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list