Tests: Extend symlink-related archive tests to cross-platform

Use `cmake -E create_symlink` or `file(CREATE_LINK)` as appropriate
instead of `ln -sf` on UNIX only to extend cases of (a) symlinks inside
archives and (b) archive extraction to a directory symlink to non-UNIX
platforms where either of these modes may be supported.

The latter relies on the NEW behavior of CMP0205 as it uses
`COPY_ON_ERROR` for platforms where directory symlinks aren't
supported.

Issue: #27756
This commit is contained in:
Tyler Yankee
2026-04-15 16:20:31 -04:00
parent 19f8fcfd24
commit 4229667859
4 changed files with 50 additions and 14 deletions

View File

@@ -37,17 +37,29 @@ 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)
# Test a (file) symlink inside the archive on platforms which support it.
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink f1.txt ${FULL_COMPRESS_DIR}/d1/f2.txt
OUTPUT_VARIABLE create_symlink_stdout
ERROR_VARIABLE create_symlink_stderr
RESULT_VARIABLE create_symlink_result
)
if(create_symlink_result EQUAL 0 AND EXISTS "${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})
if(DESTINATION_SYMLINK AND UNIX)
if(DESTINATION_SYMLINK)
# If specified, test extraction to a directory symlink on platforms which
# support it, but fall back to a plain directory otherwise.
cmake_policy(SET CMP0205 NEW)
file(MAKE_DIRECTORY ${FULL_DECOMPRESS_DIR}-dir)
execute_process(COMMAND ln -sf
${FULL_DECOMPRESS_DIR}-dir ${FULL_DECOMPRESS_DIR})
file(CREATE_LINK
${FULL_DECOMPRESS_DIR}-dir ${FULL_DECOMPRESS_DIR}
COPY_ON_ERROR
SYMBOLIC
)
else()
file(MAKE_DIRECTORY ${FULL_DECOMPRESS_DIR})
endif()

View File

@@ -27,8 +27,14 @@ function(check_compression_level COMPRESSION_LEVEL)
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)
# Test a (file) symlink inside the archive on platforms which support it.
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink f1.txt ${FULL_COMPRESS_DIR}/d1/f2.txt
OUTPUT_VARIABLE create_symlink_stdout
ERROR_VARIABLE create_symlink_stderr
RESULT_VARIABLE create_symlink_result
)
if(create_symlink_result EQUAL 0 AND EXISTS "${FULL_COMPRESS_DIR}/d1/f2.txt")
list(APPEND CHECK_FILES "d1/f2.txt")
endif()

View File

@@ -26,17 +26,29 @@ 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)
# Test a (file) symlink inside the archive on platforms which support it.
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink f1.txt ${FULL_COMPRESS_DIR}/d1/f2.txt
OUTPUT_VARIABLE create_symlink_stdout
ERROR_VARIABLE create_symlink_stderr
RESULT_VARIABLE create_symlink_result
)
if(create_symlink_result EQUAL 0 AND EXISTS "${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})
if(DESTINATION_SYMLINK AND UNIX)
if(DESTINATION_SYMLINK)
# If specified, test extraction to a directory symlink on platforms which
# support it, but fall back to a plain directory otherwise.
cmake_policy(SET CMP0205 NEW)
file(MAKE_DIRECTORY ${FULL_DECOMPRESS_DIR}-dir)
execute_process(COMMAND ln -sf
${FULL_DECOMPRESS_DIR}-dir ${FULL_DECOMPRESS_DIR})
file(CREATE_LINK
${FULL_DECOMPRESS_DIR}-dir ${FULL_DECOMPRESS_DIR}
COPY_ON_ERROR
SYMBOLIC
)
else()
file(MAKE_DIRECTORY ${FULL_DECOMPRESS_DIR})
endif()

View File

@@ -27,8 +27,14 @@ function(check_threads THREADS)
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)
# Test a (file) symlink inside the archive on platforms which support it.
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink f1.txt ${FULL_COMPRESS_DIR}/d1/f2.txt
OUTPUT_VARIABLE create_symlink_stdout
ERROR_VARIABLE create_symlink_stderr
RESULT_VARIABLE create_symlink_result
)
if(create_symlink_result EQUAL 0 AND EXISTS "${FULL_COMPRESS_DIR}/d1/f2.txt")
list(APPEND CHECK_FILES "d1/f2.txt")
endif()