file(ARCHIVE_CREATE): Rename TYPE option to COMPRESSION

Fixes: #20883
This commit is contained in:
Craig Scott
2020-06-27 18:36:16 +10:00
parent bc45bdc819
commit 95159b7dea
21 changed files with 54 additions and 39 deletions

View File

@@ -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:

View File

@@ -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;
}

View File

@@ -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\)

View File

@@ -0,0 +1,6 @@
set(OUTPUT_NAME "test.zip")
set(ARCHIVE_FORMAT 7zip)
set(COMPRESSION_TYPE XZ)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)

View File

@@ -1,6 +1,6 @@
set(OUTPUT_NAME "test.7z")
set(COMPRESSION_FORMAT 7zip)
set(ARCHIVE_FORMAT 7zip)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)

View File

@@ -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)

View File

@@ -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)

View File

@@ -1,6 +1,6 @@
set(OUTPUT_NAME "test.tar")
set(COMPRESSION_FORMAT gnutar)
set(ARCHIVE_FORMAT gnutar)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)

View File

@@ -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)

View File

@@ -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)

View File

@@ -1,6 +1,6 @@
set(OUTPUT_NAME "test.tar")
set(COMPRESSION_FORMAT pax)
set(ARCHIVE_FORMAT pax)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)

View File

@@ -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)

View File

@@ -1,6 +1,6 @@
set(OUTPUT_NAME "test.tar")
set(COMPRESSION_FORMAT paxr)
set(ARCHIVE_FORMAT paxr)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)

View File

@@ -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})

View File

@@ -1,5 +1,5 @@
set(OUTPUT_NAME "test.rar")
set(COMPRESSION_FORMAT rar)
set(ARCHIVE_FORMAT rar)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)

View File

@@ -1,6 +1,6 @@
set(OUTPUT_NAME "test.zip")
set(COMPRESSION_FORMAT zip)
set(ARCHIVE_FORMAT zip)
set(DECOMPRESSION_OPTIONS
FILES

View File

@@ -0,0 +1 @@
1

View File

@@ -1,5 +1,5 @@
CMake Error at roundtrip.cmake:38 \(file\):
file archive format zip does not support TYPE arguments
file archive format zip does not support COMPRESSION arguments
Call Stack \(most recent call first\):
zip-with-bad-type.cmake:6 \(include\)
zip-with-bad-compression.cmake:6 \(include\)
CMakeLists.txt:3 \(include\)

View File

@@ -1,6 +1,6 @@
set(OUTPUT_NAME "test.zip")
set(COMPRESSION_FORMAT zip)
set(ARCHIVE_FORMAT zip)
set(COMPRESSION_TYPE BZip2)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)

View File

@@ -1,6 +1,6 @@
set(OUTPUT_NAME "test.zip")
set(COMPRESSION_FORMAT zip)
set(ARCHIVE_FORMAT zip)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)