cli tar: extend supported compression methods

This commit is contained in:
AJIOB
2026-01-06 09:49:57 +03:00
parent d8f1d5b034
commit e4e29aeb66
21 changed files with 196 additions and 1 deletions
+24
View File
@@ -1509,6 +1509,30 @@ Available commands are:
Specify modification time recorded in tarball entries.
.. option:: --cmake-tar-compression-method=<compression-method>
.. versionadded:: 4.3
The ``<compression-method>`` must be one of the following:
* ``none`` or ``store`` - no compression is used
* ``deflate`` or ``gzip`` - Deflate-based
* ``bzip2`` - BZip2-based
* ``lzma`` - LZMA-based
* ``lzma2`` or ``xz`` - LZMA2-based
* ``ppmd`` - PPMd-based
This compression method is only supported by the ``7zip`` archive format.
* ``zstd`` - Zstandard-based
This is the second variant for the compression method selection.
It provide more compression methods, that the classic ``tar``-like interface.
You can use any of them.
The default value depends on the :option:`--format <cmake-E_tar --format>`
option value and described in the corresponding section.
.. option:: --cmake-tar-compression-level=<compression-level>
.. versionadded:: 4.3
@@ -0,0 +1,5 @@
cli-tar-compression-method
--------------------------
* The :manual:`cmake(1)` ``-E tar`` tool supports specifying compression method
via ``--cmake-tar-compression-method`` option
+33
View File
@@ -1657,6 +1657,39 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
compressionLevel =
static_cast<decltype(compressionLevel)>(compressionLevelLong);
compressionLevelFlagPassed = true;
} else if (cmHasLiteralPrefix(arg,
"--cmake-tar-compression-method=")) {
std::string const& compressionMethodStr = arg.substr(31);
if (compressionMethodStr == "none" ||
compressionMethodStr == "store") {
compress = cmSystemTools::TarCompressNone;
++nCompress;
} else if (compressionMethodStr == "deflate" ||
compressionMethodStr == "gzip") {
compress = cmSystemTools::TarCompressGZip;
++nCompress;
} else if (compressionMethodStr == "bzip2") {
compress = cmSystemTools::TarCompressBZip2;
++nCompress;
} else if (compressionMethodStr == "lzma") {
compress = cmSystemTools::TarCompressLZMA;
++nCompress;
} else if (compressionMethodStr == "lzma2" ||
compressionMethodStr == "xz") {
compress = cmSystemTools::TarCompressXZ;
++nCompress;
} else if (compressionMethodStr == "zstd") {
compress = cmSystemTools::TarCompressZstd;
++nCompress;
} else if (compressionMethodStr == "ppmd") {
compress = cmSystemTools::TarCompressPPMd;
++nCompress;
} else {
cmSystemTools::Error(
cmStrCat("Unknown --cmake-tar-compression-method value: '",
compressionMethodStr, '\''));
return 1;
}
} else if (cmHasLiteralPrefix(arg, "--files-from=")) {
std::string const& files_from = arg.substr(13);
if (!cmTarFilesFrom(files_from, files)) {
@@ -94,6 +94,31 @@ if (test_3_8_0)
run_cmake(compression-level-zip-zstd)
endif()
# Check the --cmake-tar-compression-method option
external_command_test(bad-compression-method-unknown
tar cvf bad.tar "--cmake-tar-compression-method=bad-method"
${CMAKE_CURRENT_LIST_DIR}/test-file.txt
)
external_command_test(bad-compression-method-duplicate
tar cvzf bad.tar "--cmake-tar-compression-method=gzip"
${CMAKE_CURRENT_LIST_DIR}/test-file.txt
)
external_command_test(bad-compression-method-different
tar cvzf bad.tar "--cmake-tar-compression-method=none"
${CMAKE_CURRENT_LIST_DIR}/test-file.txt
)
run_cmake(compression-method-none)
run_cmake(compression-method-store)
run_cmake(compression-method-bzip2)
run_cmake(compression-method-gzip)
run_cmake(compression-method-deflate)
run_cmake(compression-method-xz)
run_cmake(compression-method-lzma2)
run_cmake(compression-method-lzma)
run_cmake(compression-method-zstd)
run_cmake(compression-method-ppmd)
# Extracting only selected files or directories
run_cmake(zip-filtered)
@@ -0,0 +1 @@
^CMake Error: Can only compress a tar file one way; at most one flag of z, j, or J may be used$
@@ -0,0 +1 @@
^CMake Error: Can only compress a tar file one way; at most one flag of z, j, or J may be used$
@@ -0,0 +1 @@
^CMake Error: Unknown --cmake-tar-compression-method value: 'bad-method'$
@@ -1,4 +1,4 @@
set(OUTPUT_NAME "test.tar.zstd")
set(OUTPUT_NAME "test.tar.lzma")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --format=pax --lzma --cmake-tar-compression-level=9)
@@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar.bz2")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --format=paxr --cmake-tar-compression-method=bzip2)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("425a68" LIMIT 3 HEX)
@@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar.gz")
set(COMPRESSION_FLAGS -cvf)
set(COMPRESSION_OPTIONS --format=gnutar --cmake-tar-compression-method=deflate)
set(DECOMPRESSION_FLAGS -xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("1f8b" LIMIT 2 HEX)
@@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar.gz")
set(COMPRESSION_FLAGS -cvf)
set(COMPRESSION_OPTIONS --format=gnutar --cmake-tar-compression-method=gzip)
set(DECOMPRESSION_FLAGS -xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("1f8b" LIMIT 2 HEX)
@@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar.lzma")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --format=pax --cmake-tar-compression-method=lzma)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("5d0000[08]00[04]" LIMIT 5 HEX)
@@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar.xz")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --cmake-tar-compression-method=lzma2)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("fd377a585a00" LIMIT 6 HEX)
@@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --format=gnutar --cmake-tar-compression-method=none)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("7573746172202000" OFFSET 257 LIMIT 8 HEX)
@@ -0,0 +1,11 @@
set(OUTPUT_NAME "test.7z")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --format=7zip --cmake-tar-compression-method=ppmd)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
# libarchive 3.8.2 enables a checksum feature; older versions do not.
check_magic("377abcaf271c" LIMIT 6 HEX)
@@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --format=gnutar --cmake-tar-compression-method=store)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("7573746172202000" OFFSET 257 LIMIT 8 HEX)
@@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar.xz")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --cmake-tar-compression-method=xz)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("fd377a585a00" LIMIT 6 HEX)
@@ -0,0 +1,11 @@
set(OUTPUT_NAME "test.tar.zstd")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --cmake-tar-compression-method=zstd)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
# libarchive 3.8.2 enables a checksum feature; older versions do not.
check_magic("^28b52ffd0[04][56]8$" LIMIT 6 HEX)