summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/CPack
diff options
context:
space:
mode:
authorAtılhan Emre Dursunoğlu <atilhan.dursunoglu@sparsetechnology.com>2023-10-09 10:13:23 (GMT)
committerAtılhan Emre Dursunoğlu <atilhan.dursunoglu@sparsetechnology.com>2023-10-26 15:20:48 (GMT)
commit770efceccb6f1e9ea1e452b7c79227f94996a751 (patch)
treedeee65838232dee921373c8f6377be264466d78d /Tests/RunCMake/CPack
parent35424aab2e35ae5e4e3762feae26a0c305c73b9d (diff)
downloadCMake-770efceccb6f1e9ea1e452b7c79227f94996a751.zip
CMake-770efceccb6f1e9ea1e452b7c79227f94996a751.tar.gz
CMake-770efceccb6f1e9ea1e452b7c79227f94996a751.tar.bz2
CPack: Avoid adding duplicate files to archive when combining components
Fixes: #25280
Diffstat (limited to 'Tests/RunCMake/CPack')
-rw-r--r--Tests/RunCMake/CPack/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/CPack/tests/DUPLICATE_FILE/ExpectedFiles.cmake16
-rw-r--r--Tests/RunCMake/CPack/tests/DUPLICATE_FILE/conflict_file-stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/DUPLICATE_FILE/conflict_symlink-stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/DUPLICATE_FILE/test.cmake74
5 files changed, 93 insertions, 0 deletions
diff --git a/Tests/RunCMake/CPack/RunCMakeTest.cmake b/Tests/RunCMake/CPack/RunCMakeTest.cmake
index ca02b76..5086a3b 100644
--- a/Tests/RunCMake/CPack/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CPack/RunCMakeTest.cmake
@@ -69,3 +69,4 @@ run_cpack_test_subtests(
)
run_cpack_test(PROJECT_META "RPM.PROJECT_META;DEB.PROJECT_META" false "MONOLITHIC;COMPONENT")
run_cpack_test_package_target(PRE_POST_SCRIPTS "ZIP" false "MONOLITHIC;COMPONENT")
+run_cpack_test_subtests(DUPLICATE_FILE "success;conflict_file;conflict_symlink" "TGZ" false "COMPONENT;GROUP")
diff --git a/Tests/RunCMake/CPack/tests/DUPLICATE_FILE/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DUPLICATE_FILE/ExpectedFiles.cmake
new file mode 100644
index 0000000..5341ecd
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DUPLICATE_FILE/ExpectedFiles.cmake
@@ -0,0 +1,16 @@
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "success")
+ if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(EXPECTED_FILES_COUNT "1")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/files;/files/1.txt;/files/2.txt;/files/3.txt;/files/4.txt;/files/5.txt;/files/6.txt;/files/7.txt;/files/8.txt;/files/symlink2")
+ elseif(PACKAGING_TYPE STREQUAL "GROUP")
+ set(EXPECTED_FILES_COUNT "3")
+ set(EXPECTED_FILE_1 "duplicate_file-0.1.1-*-g1.${cpack_archive_extension_}")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/files;/files/1.txt;/files/2.txt;/files/3.txt;/files/4.txt;/files/5.txt;/files/6.txt;/files/symlink2")
+ set(EXPECTED_FILE_2 "duplicate_file-0.1.1-*-g2.${cpack_archive_extension_}")
+ set(EXPECTED_FILE_CONTENT_2_LIST "/files;/files/3.txt;/files/4.txt;/files/5.txt;/files/6.txt;/files/7.txt;/files/8.txt")
+ set(EXPECTED_FILE_3 "duplicate_file-0.1.1-*-c5.${cpack_archive_extension_}")
+ set(EXPECTED_FILE_CONTENT_3_LIST "/files;/files/5.txt;/files/6.txt;/files/7.txt;/files/8.txt;/files/9.txt")
+ endif ()
+else()
+ set(EXPECTED_FILES_COUNT "0")
+endif ()
diff --git a/Tests/RunCMake/CPack/tests/DUPLICATE_FILE/conflict_file-stderr.txt b/Tests/RunCMake/CPack/tests/DUPLICATE_FILE/conflict_file-stderr.txt
new file mode 100644
index 0000000..5544885
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DUPLICATE_FILE/conflict_file-stderr.txt
@@ -0,0 +1 @@
+CPack Error: ERROR The data in files with the same filename is different.*
diff --git a/Tests/RunCMake/CPack/tests/DUPLICATE_FILE/conflict_symlink-stderr.txt b/Tests/RunCMake/CPack/tests/DUPLICATE_FILE/conflict_symlink-stderr.txt
new file mode 100644
index 0000000..5544885
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DUPLICATE_FILE/conflict_symlink-stderr.txt
@@ -0,0 +1 @@
+CPack Error: ERROR The data in files with the same filename is different.*
diff --git a/Tests/RunCMake/CPack/tests/DUPLICATE_FILE/test.cmake b/Tests/RunCMake/CPack/tests/DUPLICATE_FILE/test.cmake
new file mode 100644
index 0000000..89d6784
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DUPLICATE_FILE/test.cmake
@@ -0,0 +1,74 @@
+# Create files named 1 to 9
+foreach(i RANGE 1 9)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${i}.txt" "This is file ${i}")
+endforeach()
+
+set(COMPONENT_NAMES c1 c2 c3 c4 c5)
+foreach(j RANGE 1 5)
+ # Select 4 file and install to the component
+ math(EXPR COMPONENT_IDX "${j} - 1")
+ list(GET COMPONENT_NAMES "${COMPONENT_IDX}" SELECTED_COMPONENT)
+ math(EXPR END_FILE "${j} + 4")
+ foreach(k RANGE ${j} ${END_FILE})
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${k}.txt" DESTINATION "files" COMPONENT ${SELECTED_COMPONENT})
+ endforeach()
+endforeach()
+
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "conflict_file")
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/conflict/1.txt" "This should create a conflict.")
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/conflict/1.txt" DESTINATION "files" COMPONENT c2)
+endif ()
+
+# You cannot create symlink in Windows test environment. Instead mock the symlink.
+if(NOT CMAKE_HOST_WIN32)
+ file(CREATE_LINK "${CMAKE_CURRENT_BINARY_DIR}/2.txt" "${CMAKE_CURRENT_BINARY_DIR}/symlink2" SYMBOLIC)
+else()
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/symlink2" "This is file 2")
+endif()
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/symlink2" DESTINATION "files" COMPONENT c1)
+
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "conflict_symlink" AND NOT CMAKE_HOST_WIN32)
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/conflict)
+ file(CREATE_LINK "${CMAKE_CURRENT_BINARY_DIR}/1.txt" "${CMAKE_CURRENT_BINARY_DIR}/conflict/symlink2" SYMBOLIC)
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/conflict/symlink2" DESTINATION "files" COMPONENT c2)
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "conflict_symlink" AND CMAKE_HOST_WIN32)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/conflict/symlink2" "This should create a conflict.")
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/conflict/symlink2" DESTINATION "files" COMPONENT c2)
+else()
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/symlink2" DESTINATION "files" COMPONENT c2)
+endif ()
+
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE ON)
+ set(CPACK_COMPONENTS_ALL "c1;c2;c3;c4")
+elseif(PACKAGING_TYPE STREQUAL "GROUP")
+ set(CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP ON)
+ set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
+ include(CPackComponent)
+
+ cpack_add_component_group(g1 DISPLAY_NAME "Group 1")
+ cpack_add_component_group(g2 DISPLAY_NAME "Group 2")
+ cpack_add_component(c1
+ DISPLAY_NAME "Group 1"
+ DESCRIPTION "Component for Group 1"
+ GROUP g1
+ )
+ cpack_add_component(c2
+ DISPLAY_NAME "Group 1"
+ DESCRIPTION "Component for Group 1"
+ GROUP g1
+ )
+ cpack_add_component(c3
+ DISPLAY_NAME "Group 2"
+ DESCRIPTION "Component for Group 2"
+ GROUP g2
+ )
+ cpack_add_component(c4
+ DISPLAY_NAME "Group 2"
+ DESCRIPTION "Component for Group 2"
+ GROUP g2
+ )
+
+ set(CPACK_${GENERATOR_TYPE}_PACKAGE_GROUP g1 g2)
+endif ()