From 95159b7dea20c65e3c1d9b112cd4c5f4646b6a97 Mon Sep 17 00:00:00 2001
From: Craig Scott <craig.scott@crascit.com>
Date: Sat, 27 Jun 2020 18:36:16 +1000
Subject: file(ARCHIVE_CREATE): Rename TYPE option to COMPRESSION

Fixes: #20883
---
 Help/command/file.rst                              | 26 ++++++++++++----------
 Source/cmFileCommand.cxx                           | 18 +++++++--------
 .../7zip-with-bad-compression-result.txt           |  1 +
 .../7zip-with-bad-compression-stderr.txt           |  5 +++++
 .../File_Archive/7zip-with-bad-compression.cmake   |  6 +++++
 Tests/RunCMake/File_Archive/7zip.cmake             |  2 +-
 Tests/RunCMake/File_Archive/RunCMakeTest.cmake     |  3 ++-
 Tests/RunCMake/File_Archive/gnutar-gz.cmake        |  2 +-
 Tests/RunCMake/File_Archive/gnutar.cmake           |  2 +-
 Tests/RunCMake/File_Archive/pax-xz.cmake           |  2 +-
 Tests/RunCMake/File_Archive/pax-zstd.cmake         |  2 +-
 Tests/RunCMake/File_Archive/pax.cmake              |  2 +-
 Tests/RunCMake/File_Archive/paxr-bz2.cmake         |  2 +-
 Tests/RunCMake/File_Archive/paxr.cmake             |  2 +-
 Tests/RunCMake/File_Archive/roundtrip.cmake        |  6 ++---
 .../RunCMake/File_Archive/unsupported-format.cmake |  2 +-
 Tests/RunCMake/File_Archive/zip-filtered.cmake     |  2 +-
 .../zip-with-bad-compression-result.txt            |  1 +
 .../zip-with-bad-compression-stderr.txt            |  5 +++++
 .../File_Archive/zip-with-bad-compression.cmake    |  6 +++++
 .../File_Archive/zip-with-bad-type-result.txt      |  1 -
 .../File_Archive/zip-with-bad-type-stderr.txt      |  5 -----
 .../RunCMake/File_Archive/zip-with-bad-type.cmake  |  6 -----
 Tests/RunCMake/File_Archive/zip.cmake              |  2 +-
 24 files changed, 63 insertions(+), 48 deletions(-)
 create mode 100644 Tests/RunCMake/File_Archive/7zip-with-bad-compression-result.txt
 create mode 100644 Tests/RunCMake/File_Archive/7zip-with-bad-compression-stderr.txt
 create mode 100644 Tests/RunCMake/File_Archive/7zip-with-bad-compression.cmake
 create mode 100644 Tests/RunCMake/File_Archive/zip-with-bad-compression-result.txt
 create mode 100644 Tests/RunCMake/File_Archive/zip-with-bad-compression-stderr.txt
 create mode 100644 Tests/RunCMake/File_Archive/zip-with-bad-compression.cmake
 delete mode 100644 Tests/RunCMake/File_Archive/zip-with-bad-type-result.txt
 delete mode 100644 Tests/RunCMake/File_Archive/zip-with-bad-type-stderr.txt
 delete mode 100644 Tests/RunCMake/File_Archive/zip-with-bad-type.cmake

diff --git a/Help/command/file.rst b/Help/command/file.rst
index 787a751..b109f9d 100644
--- a/Help/command/file.rst
+++ b/Help/command/file.rst
@@ -903,28 +903,30 @@ Archiving
     [FILES <files>]
     [DIRECTORY <dirs>]
     [FORMAT <format>]
-    [TYPE <type>]
+    [COMPRESSION <compression>]
     [MTIME <mtime>]
     [VERBOSE])
 
-Creates an archive specifed by ``OUTPUT`` with the content of ``FILES`` and
-``DIRECTORY``.
+Creates the specified ``<archive>`` file with the content of ``<files>`` and
+``<dirs>``.
 
-To specify the format of the archive set the ``FORMAT`` option.
-Supported formats are: ``7zip``, ``gnutar``, ``pax``, ``paxr``, ``raw``,
-(restricted pax, default), and ``zip``.
+Use the ``FORMAT`` option to specify the archive format.  Supported values
+for ``<format>`` are ``7zip``, ``gnutar``, ``pax``, ``paxr``, ``raw`` and
+``zip``.  If ``FORMAT`` is not given, the default format is ``paxr``.
 
-To specify the type of compression set the ``TYPE`` option.
-Supported compression types are: ``None``, ``BZip2``, ``GZip``, ``XZ``,
-and ``Zstd``.
+Some archive formats allow the type of compression to be specified.
+The ``7zip`` and ``zip`` archive formats already imply a specific type of
+compression.  The other formats use no compression by default, but can be
+directed to do so with the ``COMPRESSION`` option.  Valid values for
+``<compression>`` are ``None``, ``BZip2``, ``GZip``, ``XZ``, and ``Zstd``.
 
 .. note::
   With ``FORMAT`` set to ``raw`` only one file will be compressed with the
-  compression type specified by ``TYPE``.
+  compression type specified by ``COMPRESSION``.
 
-With ``VERBOSE`` the command will produce verbose output.
+The ``VERBOSE`` option enables verbose output for the archive operation.
 
-To specify the modification time recorded in tarball entries use
+To specify the modification time recorded in tarball entries, use
 the ``MTIME`` option.
 
 .. _ARCHIVE_EXTRACT:
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 268c5d1..3eea6f3 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -2941,7 +2941,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args,
   {
     std::string Output;
     std::string Format;
-    std::string Type;
+    std::string Compression;
     std::string MTime;
     bool Verbose = false;
     std::vector<std::string> Files;
@@ -2951,7 +2951,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args,
   static auto const parser = cmArgumentParser<Arguments>{}
                                .Bind("OUTPUT"_s, &Arguments::Output)
                                .Bind("FORMAT"_s, &Arguments::Format)
-                               .Bind("TYPE"_s, &Arguments::Type)
+                               .Bind("COMPRESSION"_s, &Arguments::Compression)
                                .Bind("MTIME"_s, &Arguments::MTime)
                                .Bind("VERBOSE"_s, &Arguments::Verbose)
                                .Bind("FILES"_s, &Arguments::Files)
@@ -2970,7 +2970,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args,
   }
 
   const std::vector<std::string> LIST_ARGS = {
-    "OUTPUT", "FORMAT", "TYPE", "MTIME", "FILES", "DIRECTORY",
+    "OUTPUT", "FORMAT", "COMPRESSION", "MTIME", "FILES", "DIRECTORY",
   };
   auto kwbegin = keywordsMissingValues.cbegin();
   auto kwend = cmRemoveMatching(keywordsMissingValues, LIST_ARGS);
@@ -2994,10 +2994,10 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args,
   }
 
   const char* zipFileFormats[] = { "7zip", "zip" };
-  if (!parsedArgs.Type.empty() &&
+  if (!parsedArgs.Compression.empty() &&
       cm::contains(zipFileFormats, parsedArgs.Format)) {
     status.SetError(cmStrCat("archive format ", parsedArgs.Format,
-                             " does not support TYPE arguments"));
+                             " does not support COMPRESSION arguments"));
     cmSystemTools::SetFatalErrorOccured();
     return false;
   }
@@ -3015,12 +3015,12 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args,
             std::back_inserter(files));
 
   cmSystemTools::cmTarCompression compress = cmSystemTools::TarCompressNone;
-  auto typeIt = compressionTypeMap.find(parsedArgs.Type);
+  auto typeIt = compressionTypeMap.find(parsedArgs.Compression);
   if (typeIt != compressionTypeMap.end()) {
     compress = typeIt->second;
-  } else if (!parsedArgs.Type.empty()) {
-    status.SetError(
-      cmStrCat("compression type ", parsedArgs.Type, " is not supported"));
+  } else if (!parsedArgs.Compression.empty()) {
+    status.SetError(cmStrCat("compression type ", parsedArgs.Compression,
+                             " is not supported"));
     cmSystemTools::SetFatalErrorOccured();
     return false;
   }
diff --git a/Tests/RunCMake/File_Archive/7zip-with-bad-compression-result.txt b/Tests/RunCMake/File_Archive/7zip-with-bad-compression-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/7zip-with-bad-compression-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Archive/7zip-with-bad-compression-stderr.txt b/Tests/RunCMake/File_Archive/7zip-with-bad-compression-stderr.txt
new file mode 100644
index 0000000..f6bd1ab
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/7zip-with-bad-compression-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at roundtrip.cmake:38 \(file\):
+  file archive format 7zip does not support COMPRESSION arguments
+Call Stack \(most recent call first\):
+  7zip-with-bad-compression.cmake:6 \(include\)
+  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/File_Archive/7zip-with-bad-compression.cmake b/Tests/RunCMake/File_Archive/7zip-with-bad-compression.cmake
new file mode 100644
index 0000000..7461eb8
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/7zip-with-bad-compression.cmake
@@ -0,0 +1,6 @@
+set(OUTPUT_NAME "test.zip")
+
+set(ARCHIVE_FORMAT 7zip)
+set(COMPRESSION_TYPE XZ)
+
+include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
diff --git a/Tests/RunCMake/File_Archive/7zip.cmake b/Tests/RunCMake/File_Archive/7zip.cmake
index 7b0b9b7..530e940 100644
--- a/Tests/RunCMake/File_Archive/7zip.cmake
+++ b/Tests/RunCMake/File_Archive/7zip.cmake
@@ -1,6 +1,6 @@
 set(OUTPUT_NAME "test.7z")
 
-set(COMPRESSION_FORMAT 7zip)
+set(ARCHIVE_FORMAT 7zip)
 
 include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
 
diff --git a/Tests/RunCMake/File_Archive/RunCMakeTest.cmake b/Tests/RunCMake/File_Archive/RunCMakeTest.cmake
index 871cb6d..2bd0cd8 100644
--- a/Tests/RunCMake/File_Archive/RunCMakeTest.cmake
+++ b/Tests/RunCMake/File_Archive/RunCMakeTest.cmake
@@ -14,4 +14,5 @@ run_cmake(zip)
 run_cmake(zip-filtered)
 
 run_cmake(unsupported-format)
-run_cmake(zip-with-bad-type)
+run_cmake(zip-with-bad-compression)
+run_cmake(7zip-with-bad-compression)
diff --git a/Tests/RunCMake/File_Archive/gnutar-gz.cmake b/Tests/RunCMake/File_Archive/gnutar-gz.cmake
index f4e3975..829022b 100644
--- a/Tests/RunCMake/File_Archive/gnutar-gz.cmake
+++ b/Tests/RunCMake/File_Archive/gnutar-gz.cmake
@@ -1,6 +1,6 @@
 set(OUTPUT_NAME "test.tar.gz")
 
-set(COMPRESSION_FORMAT gnutar)
+set(ARCHIVE_FORMAT gnutar)
 set(COMPRESSION_TYPE GZip)
 
 include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
diff --git a/Tests/RunCMake/File_Archive/gnutar.cmake b/Tests/RunCMake/File_Archive/gnutar.cmake
index e5cbd35..17425c7 100644
--- a/Tests/RunCMake/File_Archive/gnutar.cmake
+++ b/Tests/RunCMake/File_Archive/gnutar.cmake
@@ -1,6 +1,6 @@
 set(OUTPUT_NAME "test.tar")
 
-set(COMPRESSION_FORMAT gnutar)
+set(ARCHIVE_FORMAT gnutar)
 
 include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
 
diff --git a/Tests/RunCMake/File_Archive/pax-xz.cmake b/Tests/RunCMake/File_Archive/pax-xz.cmake
index 47fb0fd..ae485fd 100644
--- a/Tests/RunCMake/File_Archive/pax-xz.cmake
+++ b/Tests/RunCMake/File_Archive/pax-xz.cmake
@@ -1,6 +1,6 @@
 set(OUTPUT_NAME "test.tar.xz")
 
-set(COMPRESSION_FORMAT pax)
+set(ARCHIVE_FORMAT pax)
 set(COMPRESSION_TYPE XZ)
 
 include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
diff --git a/Tests/RunCMake/File_Archive/pax-zstd.cmake b/Tests/RunCMake/File_Archive/pax-zstd.cmake
index 59e0443..ba3036e 100644
--- a/Tests/RunCMake/File_Archive/pax-zstd.cmake
+++ b/Tests/RunCMake/File_Archive/pax-zstd.cmake
@@ -1,6 +1,6 @@
 set(OUTPUT_NAME "test.tar.zstd")
 
-set(COMPRESSION_FORMAT pax)
+set(ARCHIVE_FORMAT pax)
 set(COMPRESSION_TYPE Zstd)
 
 include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
diff --git a/Tests/RunCMake/File_Archive/pax.cmake b/Tests/RunCMake/File_Archive/pax.cmake
index e50c74f..46002fb 100644
--- a/Tests/RunCMake/File_Archive/pax.cmake
+++ b/Tests/RunCMake/File_Archive/pax.cmake
@@ -1,6 +1,6 @@
 set(OUTPUT_NAME "test.tar")
 
-set(COMPRESSION_FORMAT pax)
+set(ARCHIVE_FORMAT pax)
 
 include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
 
diff --git a/Tests/RunCMake/File_Archive/paxr-bz2.cmake b/Tests/RunCMake/File_Archive/paxr-bz2.cmake
index 469a131..d38f8f3 100644
--- a/Tests/RunCMake/File_Archive/paxr-bz2.cmake
+++ b/Tests/RunCMake/File_Archive/paxr-bz2.cmake
@@ -1,6 +1,6 @@
 set(OUTPUT_NAME "test.tar.bz2")
 
-set(COMPRESSION_FORMAT paxr)
+set(ARCHIVE_FORMAT paxr)
 set(COMPRESSION_TYPE BZip2)
 
 include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
diff --git a/Tests/RunCMake/File_Archive/paxr.cmake b/Tests/RunCMake/File_Archive/paxr.cmake
index e3a4d5c..ce44f05 100644
--- a/Tests/RunCMake/File_Archive/paxr.cmake
+++ b/Tests/RunCMake/File_Archive/paxr.cmake
@@ -1,6 +1,6 @@
 set(OUTPUT_NAME "test.tar")
 
-set(COMPRESSION_FORMAT paxr)
+set(ARCHIVE_FORMAT paxr)
 
 include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
 
diff --git a/Tests/RunCMake/File_Archive/roundtrip.cmake b/Tests/RunCMake/File_Archive/roundtrip.cmake
index 9050400..f1b0de5 100644
--- a/Tests/RunCMake/File_Archive/roundtrip.cmake
+++ b/Tests/RunCMake/File_Archive/roundtrip.cmake
@@ -1,4 +1,4 @@
-foreach(parameter OUTPUT_NAME COMPRESSION_FORMAT)
+foreach(parameter OUTPUT_NAME ARCHIVE_FORMAT)
   if(NOT DEFINED ${parameter})
     message(FATAL_ERROR "missing required parameter ${parameter}")
   endif()
@@ -37,8 +37,8 @@ file(MAKE_DIRECTORY ${FULL_DECOMPRESS_DIR})
 
 file(ARCHIVE_CREATE
     OUTPUT ${FULL_OUTPUT_NAME}
-    FORMAT "${COMPRESSION_FORMAT}"
-    TYPE "${COMPRESSION_TYPE}"
+    FORMAT "${ARCHIVE_FORMAT}"
+    COMPRESSION "${COMPRESSION_TYPE}"
     VERBOSE
     DIRECTORY ${COMPRESS_DIR})
 
diff --git a/Tests/RunCMake/File_Archive/unsupported-format.cmake b/Tests/RunCMake/File_Archive/unsupported-format.cmake
index 61edc1b..4b41e65 100644
--- a/Tests/RunCMake/File_Archive/unsupported-format.cmake
+++ b/Tests/RunCMake/File_Archive/unsupported-format.cmake
@@ -1,5 +1,5 @@
 set(OUTPUT_NAME "test.rar")
 
-set(COMPRESSION_FORMAT rar)
+set(ARCHIVE_FORMAT rar)
 
 include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
diff --git a/Tests/RunCMake/File_Archive/zip-filtered.cmake b/Tests/RunCMake/File_Archive/zip-filtered.cmake
index 2d259bc..e6bdcce 100644
--- a/Tests/RunCMake/File_Archive/zip-filtered.cmake
+++ b/Tests/RunCMake/File_Archive/zip-filtered.cmake
@@ -1,6 +1,6 @@
 set(OUTPUT_NAME "test.zip")
 
-set(COMPRESSION_FORMAT zip)
+set(ARCHIVE_FORMAT zip)
 
 set(DECOMPRESSION_OPTIONS
   FILES
diff --git a/Tests/RunCMake/File_Archive/zip-with-bad-compression-result.txt b/Tests/RunCMake/File_Archive/zip-with-bad-compression-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/zip-with-bad-compression-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Archive/zip-with-bad-compression-stderr.txt b/Tests/RunCMake/File_Archive/zip-with-bad-compression-stderr.txt
new file mode 100644
index 0000000..72ad8c4
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/zip-with-bad-compression-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at roundtrip.cmake:38 \(file\):
+  file archive format zip does not support COMPRESSION arguments
+Call Stack \(most recent call first\):
+  zip-with-bad-compression.cmake:6 \(include\)
+  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/File_Archive/zip-with-bad-compression.cmake b/Tests/RunCMake/File_Archive/zip-with-bad-compression.cmake
new file mode 100644
index 0000000..2badd5b
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/zip-with-bad-compression.cmake
@@ -0,0 +1,6 @@
+set(OUTPUT_NAME "test.zip")
+
+set(ARCHIVE_FORMAT zip)
+set(COMPRESSION_TYPE BZip2)
+
+include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
diff --git a/Tests/RunCMake/File_Archive/zip-with-bad-type-result.txt b/Tests/RunCMake/File_Archive/zip-with-bad-type-result.txt
deleted file mode 100644
index d00491f..0000000
--- a/Tests/RunCMake/File_Archive/zip-with-bad-type-result.txt
+++ /dev/null
@@ -1 +0,0 @@
-1
diff --git a/Tests/RunCMake/File_Archive/zip-with-bad-type-stderr.txt b/Tests/RunCMake/File_Archive/zip-with-bad-type-stderr.txt
deleted file mode 100644
index fe12feb..0000000
--- a/Tests/RunCMake/File_Archive/zip-with-bad-type-stderr.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-CMake Error at roundtrip.cmake:38 \(file\):
-  file archive format zip does not support TYPE arguments
-Call Stack \(most recent call first\):
-  zip-with-bad-type.cmake:6 \(include\)
-  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/File_Archive/zip-with-bad-type.cmake b/Tests/RunCMake/File_Archive/zip-with-bad-type.cmake
deleted file mode 100644
index ebb97a3..0000000
--- a/Tests/RunCMake/File_Archive/zip-with-bad-type.cmake
+++ /dev/null
@@ -1,6 +0,0 @@
-set(OUTPUT_NAME "test.zip")
-
-set(COMPRESSION_FORMAT zip)
-set(COMPRESSION_TYPE BZip2)
-
-include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
diff --git a/Tests/RunCMake/File_Archive/zip.cmake b/Tests/RunCMake/File_Archive/zip.cmake
index 1b93058..09e84b0 100644
--- a/Tests/RunCMake/File_Archive/zip.cmake
+++ b/Tests/RunCMake/File_Archive/zip.cmake
@@ -1,6 +1,6 @@
 set(OUTPUT_NAME "test.zip")
 
-set(COMPRESSION_FORMAT zip)
+set(ARCHIVE_FORMAT zip)
 
 include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
 
-- 
cgit v0.12