diff options
author | Cristian Adam <cristian.adam@gmail.com> | 2020-03-13 17:09:14 (GMT) |
---|---|---|
committer | Cristian Adam <cristian.adam@gmail.com> | 2020-03-16 13:33:27 (GMT) |
commit | c7e1198a237f3a6562ffc57806fdeb730c20356b (patch) | |
tree | 1f205ac4a0a3156ae83c40c679afb7a118db1ffd /Tests/RunCMake/File_Archive | |
parent | 3766633b8a49cb24f4849721bb22a0feb9ba1f60 (diff) | |
download | CMake-c7e1198a237f3a6562ffc57806fdeb730c20356b.zip CMake-c7e1198a237f3a6562ffc57806fdeb730c20356b.tar.gz CMake-c7e1198a237f3a6562ffc57806fdeb730c20356b.tar.bz2 |
file: Add ARCHIVE_{CREATE|EXTRACT} subcommands
Fixes: #20443
Diffstat (limited to 'Tests/RunCMake/File_Archive')
19 files changed, 228 insertions, 0 deletions
diff --git a/Tests/RunCMake/File_Archive/7zip.cmake b/Tests/RunCMake/File_Archive/7zip.cmake new file mode 100644 index 0000000..7b0b9b7 --- /dev/null +++ b/Tests/RunCMake/File_Archive/7zip.cmake @@ -0,0 +1,7 @@ +set(OUTPUT_NAME "test.7z") + +set(COMPRESSION_FORMAT 7zip) + +include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake) + +check_magic("377abcaf271c" LIMIT 6 HEX) diff --git a/Tests/RunCMake/File_Archive/CMakeLists.txt b/Tests/RunCMake/File_Archive/CMakeLists.txt new file mode 100644 index 0000000..2897109 --- /dev/null +++ b/Tests/RunCMake/File_Archive/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.0) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/File_Archive/RunCMakeTest.cmake b/Tests/RunCMake/File_Archive/RunCMakeTest.cmake new file mode 100644 index 0000000..871cb6d --- /dev/null +++ b/Tests/RunCMake/File_Archive/RunCMakeTest.cmake @@ -0,0 +1,17 @@ +include(RunCMake) + +run_cmake(7zip) +run_cmake(gnutar) +run_cmake(gnutar-gz) +run_cmake(pax) +run_cmake(pax-xz) +run_cmake(pax-zstd) +run_cmake(paxr) +run_cmake(paxr-bz2) +run_cmake(zip) + +# Extracting only selected files or directories +run_cmake(zip-filtered) + +run_cmake(unsupported-format) +run_cmake(zip-with-bad-type) diff --git a/Tests/RunCMake/File_Archive/gnutar-gz.cmake b/Tests/RunCMake/File_Archive/gnutar-gz.cmake new file mode 100644 index 0000000..f4e3975 --- /dev/null +++ b/Tests/RunCMake/File_Archive/gnutar-gz.cmake @@ -0,0 +1,8 @@ +set(OUTPUT_NAME "test.tar.gz") + +set(COMPRESSION_FORMAT gnutar) +set(COMPRESSION_TYPE GZip) + +include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake) + +check_magic("1f8b" LIMIT 2 HEX) diff --git a/Tests/RunCMake/File_Archive/gnutar.cmake b/Tests/RunCMake/File_Archive/gnutar.cmake new file mode 100644 index 0000000..e5cbd35 --- /dev/null +++ b/Tests/RunCMake/File_Archive/gnutar.cmake @@ -0,0 +1,7 @@ +set(OUTPUT_NAME "test.tar") + +set(COMPRESSION_FORMAT gnutar) + +include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake) + +check_magic("7573746172202000" OFFSET 257 LIMIT 8 HEX) diff --git a/Tests/RunCMake/File_Archive/pax-xz.cmake b/Tests/RunCMake/File_Archive/pax-xz.cmake new file mode 100644 index 0000000..47fb0fd --- /dev/null +++ b/Tests/RunCMake/File_Archive/pax-xz.cmake @@ -0,0 +1,8 @@ +set(OUTPUT_NAME "test.tar.xz") + +set(COMPRESSION_FORMAT pax) +set(COMPRESSION_TYPE XZ) + +include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake) + +check_magic("fd377a585a00" LIMIT 6 HEX) diff --git a/Tests/RunCMake/File_Archive/pax-zstd.cmake b/Tests/RunCMake/File_Archive/pax-zstd.cmake new file mode 100644 index 0000000..59e0443 --- /dev/null +++ b/Tests/RunCMake/File_Archive/pax-zstd.cmake @@ -0,0 +1,8 @@ +set(OUTPUT_NAME "test.tar.zstd") + +set(COMPRESSION_FORMAT pax) +set(COMPRESSION_TYPE Zstd) + +include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake) + +check_magic("28b52ffd0058" LIMIT 6 HEX) diff --git a/Tests/RunCMake/File_Archive/pax.cmake b/Tests/RunCMake/File_Archive/pax.cmake new file mode 100644 index 0000000..e50c74f --- /dev/null +++ b/Tests/RunCMake/File_Archive/pax.cmake @@ -0,0 +1,7 @@ +set(OUTPUT_NAME "test.tar") + +set(COMPRESSION_FORMAT pax) + +include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake) + +check_magic("7573746172003030" OFFSET 257 LIMIT 8 HEX) diff --git a/Tests/RunCMake/File_Archive/paxr-bz2.cmake b/Tests/RunCMake/File_Archive/paxr-bz2.cmake new file mode 100644 index 0000000..469a131 --- /dev/null +++ b/Tests/RunCMake/File_Archive/paxr-bz2.cmake @@ -0,0 +1,8 @@ +set(OUTPUT_NAME "test.tar.bz2") + +set(COMPRESSION_FORMAT paxr) +set(COMPRESSION_TYPE BZip2) + +include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake) + +check_magic("425a68" LIMIT 3 HEX) diff --git a/Tests/RunCMake/File_Archive/paxr.cmake b/Tests/RunCMake/File_Archive/paxr.cmake new file mode 100644 index 0000000..e3a4d5c --- /dev/null +++ b/Tests/RunCMake/File_Archive/paxr.cmake @@ -0,0 +1,7 @@ +set(OUTPUT_NAME "test.tar") + +set(COMPRESSION_FORMAT paxr) + +include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake) + +check_magic("7573746172003030" OFFSET 257 LIMIT 8 HEX) diff --git a/Tests/RunCMake/File_Archive/roundtrip.cmake b/Tests/RunCMake/File_Archive/roundtrip.cmake new file mode 100644 index 0000000..9050400 --- /dev/null +++ b/Tests/RunCMake/File_Archive/roundtrip.cmake @@ -0,0 +1,92 @@ +foreach(parameter OUTPUT_NAME COMPRESSION_FORMAT) + if(NOT DEFINED ${parameter}) + message(FATAL_ERROR "missing required parameter ${parameter}") + endif() +endforeach() + +set(COMPRESS_DIR compress_dir) +set(FULL_COMPRESS_DIR ${CMAKE_CURRENT_BINARY_DIR}/${COMPRESS_DIR}) + +set(DECOMPRESS_DIR decompress_dir) +set(FULL_DECOMPRESS_DIR ${CMAKE_CURRENT_BINARY_DIR}/${DECOMPRESS_DIR}) + +set(FULL_OUTPUT_NAME ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}) + +set(CHECK_FILES + "f1.txt" + "d1/f1.txt" + "d 2/f1.txt" + "d + 3/f1.txt" + "d_4/f1.txt" + "d-4/f1.txt" + "My Special Directory/f1.txt" +) + +foreach(file ${CHECK_FILES}) + configure_file(${CMAKE_CURRENT_LIST_FILE} ${FULL_COMPRESS_DIR}/${file} COPYONLY) +endforeach() + +if(UNIX) + execute_process(COMMAND ln -sf f1.txt ${FULL_COMPRESS_DIR}/d1/f2.txt) + list(APPEND CHECK_FILES "d1/f2.txt") +endif() + +file(REMOVE ${FULL_OUTPUT_NAME}) +file(REMOVE_RECURSE ${FULL_DECOMPRESS_DIR}) +file(MAKE_DIRECTORY ${FULL_DECOMPRESS_DIR}) + +file(ARCHIVE_CREATE + OUTPUT ${FULL_OUTPUT_NAME} + FORMAT "${COMPRESSION_FORMAT}" + TYPE "${COMPRESSION_TYPE}" + VERBOSE + DIRECTORY ${COMPRESS_DIR}) + +file(ARCHIVE_EXTRACT + INPUT ${FULL_OUTPUT_NAME} + ${DECOMPRESSION_OPTIONS} + DESTINATION ${FULL_DECOMPRESS_DIR} + VERBOSE) + +if(CUSTOM_CHECK_FILES) + set(CHECK_FILES ${CUSTOM_CHECK_FILES}) +endif() + +foreach(file ${CHECK_FILES}) + set(input ${FULL_COMPRESS_DIR}/${file}) + set(output ${FULL_DECOMPRESS_DIR}/${COMPRESS_DIR}/${file}) + + if(NOT EXISTS ${input}) + message(SEND_ERROR "Cannot find input file ${output}") + endif() + + if(NOT EXISTS ${output}) + message(SEND_ERROR "Cannot find output file ${output}") + endif() + + file(MD5 ${input} input_md5) + file(MD5 ${output} output_md5) + + if(NOT input_md5 STREQUAL output_md5) + message(SEND_ERROR "Files \"${input}\" and \"${output}\" are different") + endif() +endforeach() + +foreach(file ${NOT_EXISTING_FILES_CHECK}) + set(output ${FULL_DECOMPRESS_DIR}/${COMPRESS_DIR}/${file}) + + if(EXISTS ${output}) + message(SEND_ERROR "File ${output} exists but it shouldn't") + endif() +endforeach() + +function(check_magic EXPECTED) + file(READ ${FULL_OUTPUT_NAME} ACTUAL + ${ARGN} + ) + + if(NOT ACTUAL STREQUAL EXPECTED) + message(FATAL_ERROR + "Actual [${ACTUAL}] does not match expected [${EXPECTED}]") + endif() +endfunction() diff --git a/Tests/RunCMake/File_Archive/unsupported-format-result.txt b/Tests/RunCMake/File_Archive/unsupported-format-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/File_Archive/unsupported-format-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/File_Archive/unsupported-format-stderr.txt b/Tests/RunCMake/File_Archive/unsupported-format-stderr.txt new file mode 100644 index 0000000..4328022 --- /dev/null +++ b/Tests/RunCMake/File_Archive/unsupported-format-stderr.txt @@ -0,0 +1,5 @@ +CMake Error at roundtrip.cmake:38 \(file\): + file archive format rar not supported +Call Stack \(most recent call first\): + unsupported-format.cmake:5 \(include\) + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/File_Archive/unsupported-format.cmake b/Tests/RunCMake/File_Archive/unsupported-format.cmake new file mode 100644 index 0000000..61edc1b --- /dev/null +++ b/Tests/RunCMake/File_Archive/unsupported-format.cmake @@ -0,0 +1,5 @@ +set(OUTPUT_NAME "test.rar") + +set(COMPRESSION_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 new file mode 100644 index 0000000..2d259bc --- /dev/null +++ b/Tests/RunCMake/File_Archive/zip-filtered.cmake @@ -0,0 +1,26 @@ +set(OUTPUT_NAME "test.zip") + +set(COMPRESSION_FORMAT zip) + +set(DECOMPRESSION_OPTIONS + FILES + compress_dir/f1.txt # Decompress only file + compress_dir/d1 # and whole directory +) + +set(CUSTOM_CHECK_FILES + "f1.txt" + "d1/f1.txt" +) + +# This files shouldn't exists +set(NOT_EXISTING_FILES_CHECK + "d 2/f1.txt" + "d + 3/f1.txt" + "d_4/f1.txt" + "d-4/f1.txt" +) + +include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake) + +check_magic("504b0304" LIMIT 4 HEX) diff --git a/Tests/RunCMake/File_Archive/zip-with-bad-type-result.txt b/Tests/RunCMake/File_Archive/zip-with-bad-type-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/File_Archive/zip-with-bad-type-result.txt @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000..fe12feb --- /dev/null +++ b/Tests/RunCMake/File_Archive/zip-with-bad-type-stderr.txt @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000..ebb97a3 --- /dev/null +++ b/Tests/RunCMake/File_Archive/zip-with-bad-type.cmake @@ -0,0 +1,6 @@ +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 new file mode 100644 index 0000000..1b93058 --- /dev/null +++ b/Tests/RunCMake/File_Archive/zip.cmake @@ -0,0 +1,7 @@ +set(OUTPUT_NAME "test.zip") + +set(COMPRESSION_FORMAT zip) + +include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake) + +check_magic("504b0304" LIMIT 4 HEX) |