RunCPackVerifyResult.cmake 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. # prevent older policies from interfering with this script
  2. cmake_policy(PUSH)
  3. cmake_policy(VERSION ${CMAKE_VERSION})
  4. message(STATUS "=============================================================================")
  5. message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
  6. message(STATUS "")
  7. if(NOT CPackComponentsForAll_BINARY_DIR)
  8. message(FATAL_ERROR "CPackComponentsForAll_BINARY_DIR not set")
  9. endif()
  10. if(NOT CPackGen)
  11. message(FATAL_ERROR "CPackGen not set")
  12. endif()
  13. message("CMAKE_CPACK_COMMAND = ${CMAKE_CPACK_COMMAND}")
  14. if(NOT CMAKE_CPACK_COMMAND)
  15. message(FATAL_ERROR "CMAKE_CPACK_COMMAND not set")
  16. endif()
  17. if(NOT CPackComponentWay)
  18. message(FATAL_ERROR "CPackComponentWay not set")
  19. endif()
  20. set(expected_file_mask "")
  21. # The usual default behavior is to expect a single file
  22. # Then some specific generators (Archive, RPM, ...)
  23. # May produce several numbers of files depending on
  24. # CPACK_COMPONENT_xxx values
  25. set(expected_count 1)
  26. set(config_type $ENV{CMAKE_CONFIG_TYPE})
  27. set(config_args )
  28. if(config_type)
  29. set(config_args -C ${config_type})
  30. endif()
  31. set(config_verbose )
  32. if(CPackGen MATCHES "ZIP")
  33. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.zip")
  34. if(${CPackComponentWay} STREQUAL "default")
  35. set(expected_count 1)
  36. elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
  37. set(expected_count 3)
  38. elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
  39. set(expected_count 4)
  40. elseif(${CPackComponentWay} STREQUAL "AllInOne")
  41. set(expected_count 1)
  42. endif()
  43. elseif(CPackGen MATCHES "RPM")
  44. set(config_verbose -D "CPACK_RPM_PACKAGE_DEBUG=1")
  45. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.rpm")
  46. if(${CPackComponentWay} STREQUAL "default")
  47. set(expected_count 1)
  48. elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
  49. set(expected_count 3)
  50. elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
  51. set(expected_count 4)
  52. elseif(${CPackComponentWay} STREQUAL "AllInOne")
  53. set(expected_count 1)
  54. endif()
  55. elseif(CPackGen MATCHES "DEB")
  56. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/mylib*_1.0.2_*.deb")
  57. if(${CPackComponentWay} STREQUAL "default")
  58. set(expected_count 1)
  59. elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
  60. set(expected_count 3)
  61. elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
  62. set(expected_count 4)
  63. elseif(${CPackComponentWay} STREQUAL "AllInOne")
  64. set(expected_count 1)
  65. endif()
  66. elseif(CPackGen MATCHES "NuGet")
  67. set(config_verbose -D "CPACK_NUGET_PACKAGE_DEBUG=1")
  68. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib*1.0.2.nupkg")
  69. if(${CPackComponentWay} STREQUAL "default")
  70. set(expected_count 1)
  71. elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
  72. set(expected_count 3)
  73. elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
  74. set(expected_count 4)
  75. elseif(${CPackComponentWay} STREQUAL "AllInOne")
  76. set(expected_count 1)
  77. endif()
  78. endif()
  79. if(CPackGen MATCHES "DragNDrop")
  80. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.dmg")
  81. if(${CPackComponentWay} STREQUAL "default")
  82. set(expected_count 1)
  83. set(expect_dmg_sla 1)
  84. elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
  85. set(expected_count 3)
  86. elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
  87. set(expected_count 4)
  88. elseif(${CPackComponentWay} STREQUAL "AllInOne")
  89. set(expected_count 1)
  90. set(expect_dmg_sla 1)
  91. endif()
  92. endif()
  93. # clean-up previously CPack generated files
  94. if(expected_file_mask)
  95. file(GLOB expected_file "${expected_file_mask}")
  96. if(expected_file)
  97. file(REMOVE ${expected_file})
  98. endif()
  99. endif()
  100. message("config_args = ${config_args}")
  101. message("config_verbose = ${config_verbose}")
  102. execute_process(COMMAND ${CMAKE_CPACK_COMMAND} ${config_verbose} -G ${CPackGen} ${config_args}
  103. RESULT_VARIABLE CPack_result
  104. OUTPUT_VARIABLE CPack_output
  105. ERROR_VARIABLE CPack_error
  106. WORKING_DIRECTORY ${CPackComponentsForAll_BINARY_DIR})
  107. string(REPLACE "\n" "\n cpack-out> " cpack_out "\n${CPack_output}")
  108. string(REPLACE "\n" "\n cpack-err> " cpack_err "\n${CPack_error}")
  109. string(REPLACE "\n" "\n cpack-res> " cpack_res "\n${CPack_result}")
  110. string(CONCAT output_error_message
  111. "CPack output:${cpack_out}\n"
  112. "CPack error:${cpack_err}\n"
  113. "CPack result:${cpack_res}\n"
  114. )
  115. if(CPack_result)
  116. message(FATAL_ERROR "error: CPack execution went wrong!,\n${output_error_message}")
  117. else ()
  118. message(STATUS "CPack_output=${CPack_output}")
  119. endif()
  120. # Now verify if the number of expected file is OK
  121. # - using expected_file_mask and
  122. # - expected_count
  123. if(expected_file_mask)
  124. file(GLOB expected_file "${expected_file_mask}")
  125. message(STATUS "expected_count='${expected_count}'")
  126. message(STATUS "expected_file='${expected_file}'")
  127. message(STATUS "expected_file_mask='${expected_file_mask}'")
  128. if(NOT expected_file)
  129. message(FATAL_ERROR "error: expected_file does not exist: CPackComponentsForAll test fails.\n${output_error_message}")
  130. endif()
  131. list(LENGTH expected_file actual_count)
  132. message(STATUS "actual_count='${actual_count}'")
  133. if(NOT actual_count EQUAL expected_count)
  134. message(FATAL_ERROR "error: expected_count=${expected_count} does not match actual_count=${actual_count}: CPackComponents test fails.\n${output_error_message}")
  135. endif()
  136. if(expect_dmg_sla)
  137. execute_process(COMMAND hdiutil udifderez -xml "${expected_file}" OUTPUT_VARIABLE out ERROR_VARIABLE err RESULT_VARIABLE res)
  138. if(NOT res EQUAL 0)
  139. string(REPLACE "\n" "\n " err " ${err}")
  140. message(FATAL_ERROR "error: running 'hdiutil udifderez -xml' on\n ${expected_file}\nfailed with:\n${err}")
  141. endif()
  142. foreach(key "LPic" "STR#" "TEXT")
  143. if(NOT out MATCHES "<key>${key}</key>")
  144. string(REPLACE "\n" "\n " out " ${out}")
  145. message(FATAL_ERROR "error: running 'hdiutil udifderez -xml' on\n ${expected_file}\ndid not show '${key}' key:\n${out}")
  146. endif()
  147. endforeach()
  148. foreach(line
  149. # LPic first and last base64 lines
  150. "\tAAIAEQADAAEAAAAAAAIAAAAIAAMAAAABAAQAAAAEAAUAAAAOAAYA\n"
  151. "\tAA0AAABbAAQAAAAzAA8AAQAMABAAAAALAA4AAA==\n"
  152. # STR# first and last base64 lines
  153. "\tAAkHRW5nbGlzaAVBZ3JlZQhEaXNhZ3JlZQVQcmludAdTYXZlLi4u\n"
  154. "\tdGVkIGEgcHJpbnRlci4=\n"
  155. # TEXT first and last base64 lines
  156. "\tTElDRU5TRQ0tLS0tLS0tDVRoaXMgaXMgYW4gaW5zdGFsbGVyIGNy\n"
  157. "\tTm8gbGljZW5zZSBwcm92aWRlZC4NDQ==\n"
  158. )
  159. if(NOT out MATCHES "${line}")
  160. string(REPLACE "\n" "\n " out " ${out}")
  161. message(FATAL_ERROR "error: running 'hdiutil udifderez -xml' on\n ${expected_file}\ndid not show '${line}':\n${out}")
  162. endif()
  163. endforeach()
  164. endif()
  165. endif()
  166. # Validate content
  167. if(CPackGen MATCHES "RPM")
  168. find_program(RPM_EXECUTABLE rpm)
  169. if(NOT RPM_EXECUTABLE)
  170. message(FATAL_ERROR "error: missing rpm executable required by the test")
  171. endif()
  172. set(CPACK_RPM_PACKAGE_SUMMARY "default summary")
  173. set(CPACK_RPM_HEADERS_PACKAGE_SUMMARY "headers summary")
  174. set(CPACK_RPM_HEADERS_PACKAGE_DESCRIPTION "headers description")
  175. set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
  176. "An extremely useful application that makes use of MyLib")
  177. set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
  178. "Static libraries used to build programs with MyLib")
  179. set(LIB_SUFFIX "6?4?")
  180. # test package info
  181. if(${CPackComponentWay} STREQUAL "IgnoreGroup")
  182. # set gnu install prefixes to what they are set during rpm creation
  183. # CMAKE_SIZEOF_VOID_P is not set here but lib is prefix of lib64 so
  184. # relocation path test won't fail on OSes with lib64 library location
  185. include(GNUInstallDirs)
  186. set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/foo/bar")
  187. foreach(check_file ${expected_file})
  188. string(REGEX MATCH ".*libraries.*" check_file_libraries_match ${check_file})
  189. string(REGEX MATCH ".*headers.*" check_file_headers_match ${check_file})
  190. string(REGEX MATCH ".*applications.*" check_file_applications_match ${check_file})
  191. string(REGEX MATCH ".*Unspecified.*" check_file_Unspecified_match ${check_file})
  192. execute_process(COMMAND ${RPM_EXECUTABLE} -pqi ${check_file}
  193. OUTPUT_VARIABLE check_file_content
  194. ERROR_QUIET
  195. OUTPUT_STRIP_TRAILING_WHITESPACE)
  196. execute_process(COMMAND ${RPM_EXECUTABLE} -pqa ${check_file}
  197. RESULT_VARIABLE check_package_architecture_result
  198. OUTPUT_VARIABLE check_package_architecture
  199. ERROR_QUIET
  200. OUTPUT_STRIP_TRAILING_WHITESPACE)
  201. execute_process(COMMAND ${RPM_EXECUTABLE} -pql ${check_file}
  202. OUTPUT_VARIABLE check_package_content
  203. ERROR_QUIET
  204. OUTPUT_STRIP_TRAILING_WHITESPACE)
  205. set(whitespaces "[\\t\\n\\r ]*")
  206. if(check_file_libraries_match)
  207. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  208. set(check_file_match_expected_description ".*${CPACK_COMPONENT_LIBRARIES_DESCRIPTION}.*")
  209. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}${LIB_SUFFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/other_relocatable${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}${LIB_SUFFIX}/inside_relocatable_two/depth_two/different_relocatable")
  210. set(check_file_match_expected_architecture "") # we don't explicitly set this value so it is different on each platform - ignore it
  211. set(spec_regex "*libraries*")
  212. set(check_content_list "^/usr/foo/bar/lib${LIB_SUFFIX}
  213. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one
  214. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two
  215. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/depth_three
  216. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/depth_three/symlink_parentdir_path
  217. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_outside_package
  218. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_outside_wdr
  219. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_relocatable_subpath
  220. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_samedir_path
  221. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_samedir_path_current_dir
  222. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_samedir_path_longer
  223. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/symlink_subdir_path
  224. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two
  225. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two
  226. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two/different_relocatable
  227. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two/different_relocatable/bar
  228. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two/symlink_other_relocatable_path
  229. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two/symlink_to_non_relocatable_path
  230. /usr/foo/bar/lib${LIB_SUFFIX}/libmylib.a
  231. /usr/foo/bar/non_relocatable
  232. /usr/foo/bar/non_relocatable/depth_two
  233. /usr/foo/bar/non_relocatable/depth_two/symlink_from_non_relocatable_path
  234. /usr/foo/bar/other_relocatable
  235. /usr/foo/bar/other_relocatable/depth_two(\n.*\.build-id.*)*$")
  236. elseif(check_file_headers_match)
  237. set(check_file_match_expected_summary ".*${CPACK_RPM_HEADERS_PACKAGE_SUMMARY}.*")
  238. set(check_file_match_expected_description ".*${CPACK_RPM_HEADERS_PACKAGE_DESCRIPTION}.*")
  239. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
  240. set(check_file_match_expected_architecture "noarch")
  241. set(spec_regex "*headers*")
  242. set(check_content_list "^/usr/foo/bar\n/usr/foo/bar/include\n/usr/foo/bar/include/mylib.h(\n.*\.build-id.*)*$")
  243. elseif(check_file_applications_match)
  244. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  245. set(check_file_match_expected_description ".*${CPACK_COMPONENT_APPLICATIONS_DESCRIPTION}.*")
  246. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
  247. set(check_file_match_expected_architecture "armv7hl")
  248. set(spec_regex "*applications*")
  249. set(check_content_list "^/usr/foo/bar
  250. /usr/foo/bar/bin
  251. /usr/foo/bar/bin/mylibapp(\n.*\.build-id.*)*$")
  252. elseif(check_file_Unspecified_match)
  253. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  254. set(check_file_match_expected_description ".*DESCRIPTION.*")
  255. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
  256. set(check_file_match_expected_architecture "") # we don't explicitly set this value so it is different on each platform - ignore it
  257. set(spec_regex "*Unspecified*")
  258. set(check_content_list "^/usr/foo/bar
  259. /usr/foo/bar/bin
  260. /usr/foo/bar/bin/@in@_@path@@with
  261. /usr/foo/bar/bin/@in@_@path@@with/@and
  262. /usr/foo/bar/bin/@in@_@path@@with/@and/@
  263. /usr/foo/bar/bin/@in@_@path@@with/@and/@/@in_path@
  264. /usr/foo/bar/bin/@in@_@path@@with/@and/@/@in_path@/mylibapp2
  265. /usr/foo/bar/share
  266. /usr/foo/bar/share/man
  267. /usr/foo/bar/share/man/mylib
  268. /usr/foo/bar/share/man/mylib/man3
  269. /usr/foo/bar/share/man/mylib/man3/mylib.1
  270. /usr/foo/bar/share/man/mylib/man3/mylib.1/mylib
  271. /usr/foo/bar/share/man/mylib/man3/mylib.1/mylib2(\n.*\.build-id.*)*$")
  272. else()
  273. message(FATAL_ERROR "error: unexpected rpm package '${check_file}'")
  274. endif()
  275. #######################
  276. # test package info
  277. #######################
  278. string(REGEX MATCH ${check_file_match_expected_summary} check_file_match_summary ${check_file_content})
  279. if(NOT check_file_match_summary)
  280. message(FATAL_ERROR "error: '${check_file}' rpm package summary does not match expected value - regex '${check_file_match_expected_summary}'; RPM output: '${check_file_content}'")
  281. endif()
  282. string(REGEX MATCH ${check_file_match_expected_description} check_file_match_description ${check_file_content})
  283. if(NOT check_file_match_description)
  284. message(FATAL_ERROR "error: '${check_file}' rpm package description does not match expected value - regex '${check_file_match_expected_description}'; RPM output: '${check_file_content}'")
  285. endif()
  286. string(REGEX MATCH ${check_file_match_expected_relocation_path} check_file_match_relocation_path ${check_file_content})
  287. if(NOT check_file_match_relocation_path)
  288. file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/${spec_regex}.spec")
  289. if(spec_file)
  290. file(READ ${spec_file} spec_file_content)
  291. endif()
  292. message(FATAL_ERROR "error: '${check_file}' rpm package relocation path does not match expected value - regex '${check_file_match_expected_relocation_path}'; RPM output: '${check_file_content}'; generated spec file: '${spec_file_content}'")
  293. endif()
  294. #######################
  295. # test package architecture
  296. #######################
  297. string(REGEX MATCH "Architecture${whitespaces}:" check_info_contains_arch ${check_file_content})
  298. if(check_info_contains_arch) # test for rpm versions that contain architecture in package info (e.g. 4.11.x)
  299. string(REGEX MATCH "Architecture${whitespaces}:${whitespaces}${check_file_match_expected_architecture}" check_file_match_architecture ${check_file_content})
  300. if(NOT check_file_match_architecture)
  301. message(FATAL_ERROR "error: '${check_file}' Architecture does not match expected value - '${check_file_match_expected_architecture}'; RPM output: '${check_file_content}'; generated spec file: '${spec_file_content}'")
  302. endif()
  303. elseif(NOT check_package_architecture_result) # test result only on platforms that support -pqa rpm query
  304. # test for rpm versions that do not contain architecture in package info (e.g. 4.8.x)
  305. string(REGEX MATCH ".*${check_file_match_expected_architecture}" check_file_match_architecture "${check_package_architecture}")
  306. if(NOT check_file_match_architecture)
  307. message(FATAL_ERROR "error: '${check_file}' Architecture does not match expected value - '${check_file_match_expected_architecture}'; RPM output: '${check_package_architecture}'; generated spec file: '${spec_file_content}'")
  308. endif()
  309. # else rpm version too old (e.g. 4.4.x) - skip test
  310. endif()
  311. #######################
  312. # test package content
  313. #######################
  314. string(REGEX MATCH "${check_content_list}" expected_content_list "${check_package_content}")
  315. if(NOT expected_content_list)
  316. file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/${spec_regex}.spec")
  317. if(spec_file)
  318. file(READ ${spec_file} spec_file_content)
  319. endif()
  320. message(FATAL_ERROR "error: '${check_file}' rpm package content does not match expected value - regex '${check_content_list}'; RPM output: '${check_package_content}'; generated spec file: '${spec_file_content}'")
  321. endif()
  322. # validate permissions user and group
  323. execute_process(COMMAND ${RPM_EXECUTABLE} -pqlv ${check_file}
  324. OUTPUT_VARIABLE check_file_content
  325. ERROR_QUIET
  326. OUTPUT_STRIP_TRAILING_WHITESPACE)
  327. if(check_file_libraries_match)
  328. set(check_file_match_expected_permissions ".*-rwx------.*user.*defgrp.*")
  329. elseif(check_file_headers_match)
  330. set(check_file_match_expected_permissions ".*-rwxr--r--.*defusr.*defgrp.*")
  331. elseif(check_file_applications_match)
  332. set(check_file_match_expected_permissions ".*-rwxr--r--.*defusr.*group.*")
  333. elseif(check_file_Unspecified_match)
  334. set(check_file_match_expected_permissions ".*-rwxr--r--.*defusr.*defgrp.*")
  335. else()
  336. message(FATAL_ERROR "error: unexpected rpm package '${check_file}'")
  337. endif()
  338. string(REGEX MATCH "${check_file_match_expected_permissions}" check_file_match_permissions "${check_file_content}")
  339. if(NOT check_file_match_permissions)
  340. message(FATAL_ERROR "error: '${check_file}' rpm package permissions do not match expected value - regex '${check_file_match_expected_permissions}'")
  341. endif()
  342. endforeach()
  343. #######################
  344. # verify generated symbolic links
  345. #######################
  346. file(GLOB_RECURSE symlink_files RELATIVE "${CPackComponentsForAll_BINARY_DIR}" "${CPackComponentsForAll_BINARY_DIR}/*/symlink_*")
  347. foreach(check_symlink IN LISTS symlink_files)
  348. get_filename_component(symlink_name "${check_symlink}" NAME)
  349. execute_process(COMMAND ls -la "${check_symlink}"
  350. WORKING_DIRECTORY "${CPackComponentsForAll_BINARY_DIR}"
  351. OUTPUT_VARIABLE SYMLINK_POINT_
  352. OUTPUT_STRIP_TRAILING_WHITESPACE)
  353. if("${symlink_name}" STREQUAL "symlink_samedir_path"
  354. OR "${symlink_name}" STREQUAL "symlink_samedir_path_current_dir"
  355. OR "${symlink_name}" STREQUAL "symlink_samedir_path_longer")
  356. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}depth_three$" check_symlink "${SYMLINK_POINT_}")
  357. elseif("${symlink_name}" STREQUAL "symlink_subdir_path")
  358. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}depth_two/depth_three$" check_symlink "${SYMLINK_POINT_}")
  359. elseif("${symlink_name}" STREQUAL "symlink_parentdir_path")
  360. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}../$" check_symlink "${SYMLINK_POINT_}")
  361. elseif("${symlink_name}" STREQUAL "symlink_to_non_relocatable_path")
  362. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/non_relocatable/depth_two$" check_symlink "${SYMLINK_POINT_}")
  363. elseif("${symlink_name}" STREQUAL "symlink_outside_package")
  364. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}outside_package$" check_symlink "${SYMLINK_POINT_}")
  365. elseif("${symlink_name}" STREQUAL "symlink_outside_wdr")
  366. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}/outside_package_wdr$" check_symlink "${SYMLINK_POINT_}")
  367. elseif("${symlink_name}" STREQUAL "symlink_other_relocatable_path"
  368. OR "${symlink_name}" STREQUAL "symlink_from_non_relocatable_path"
  369. OR "${symlink_name}" STREQUAL "symlink_relocatable_subpath")
  370. # these links were not changed - post install script only - ignore them
  371. else()
  372. message(FATAL_ERROR "error: unexpected rpm symbolic link '${check_symlink}'")
  373. endif()
  374. if(NOT check_symlink)
  375. message(FATAL_ERROR "symlink points to unexpected location '${SYMLINK_POINT_}'")
  376. endif()
  377. endforeach()
  378. # verify post install symlink relocation script
  379. file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/*libraries*.spec")
  380. file(READ ${spec_file} spec_file_content)
  381. file(READ "${CMAKE_CURRENT_LIST_DIR}/symlink_postinstall_expected.txt" symlink_postinstall_expected)
  382. # prepare regex
  383. string(STRIP "${symlink_postinstall_expected}" symlink_postinstall_expected)
  384. string(REPLACE "[" "\\[" symlink_postinstall_expected "${symlink_postinstall_expected}")
  385. string(REPLACE "$" "\\$" symlink_postinstall_expected "${symlink_postinstall_expected}")
  386. string(REPLACE "lib" "lib${LIB_SUFFIX}" symlink_postinstall_expected "${symlink_postinstall_expected}")
  387. # compare
  388. string(REGEX MATCH ".*${symlink_postinstall_expected}.*" symlink_postinstall_expected_matches "${spec_file_content}")
  389. if(NOT symlink_postinstall_expected_matches)
  390. message(FATAL_ERROR "error: unexpected rpm symbolic link postinstall script! generated spec file: '${spec_file_content}'")
  391. endif()
  392. endif()
  393. endif()
  394. cmake_policy(POP)