RunCPackVerifyResult.cmake 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. # prevent older policies from interfearing 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-*.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. endif()
  67. if(CPackGen MATCHES "DragNDrop")
  68. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.dmg")
  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. # clean-up previously CPack generated files
  80. if(expected_file_mask)
  81. file(GLOB expected_file "${expected_file_mask}")
  82. if (expected_file)
  83. file(REMOVE ${expected_file})
  84. endif()
  85. endif()
  86. message("config_args = ${config_args}")
  87. message("config_verbose = ${config_verbose}")
  88. execute_process(COMMAND ${CMAKE_CPACK_COMMAND} ${config_verbose} -G ${CPackGen} ${config_args}
  89. RESULT_VARIABLE CPack_result
  90. OUTPUT_VARIABLE CPack_output
  91. ERROR_VARIABLE CPack_error
  92. WORKING_DIRECTORY ${CPackComponentsForAll_BINARY_DIR})
  93. if (CPack_result)
  94. message(FATAL_ERROR "error: CPack execution went wrong!, CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  95. else ()
  96. message(STATUS "CPack_output=${CPack_output}")
  97. endif()
  98. # Now verify if the number of expected file is OK
  99. # - using expected_file_mask and
  100. # - expected_count
  101. if(expected_file_mask)
  102. file(GLOB expected_file "${expected_file_mask}")
  103. message(STATUS "expected_count='${expected_count}'")
  104. message(STATUS "expected_file='${expected_file}'")
  105. message(STATUS "expected_file_mask='${expected_file_mask}'")
  106. if(NOT expected_file)
  107. message(FATAL_ERROR "error: expected_file=${expected_file} does not exist: CPackComponentsForAll test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  108. endif()
  109. list(LENGTH expected_file actual_count)
  110. message(STATUS "actual_count='${actual_count}'")
  111. if(NOT actual_count EQUAL expected_count)
  112. message(FATAL_ERROR "error: expected_count=${expected_count} does not match actual_count=${actual_count}: CPackComponents test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error})")
  113. endif()
  114. endif()
  115. # Validate content
  116. if(CPackGen MATCHES "RPM")
  117. find_program(RPM_EXECUTABLE rpm)
  118. if(NOT RPM_EXECUTABLE)
  119. message(FATAL_ERROR "error: missing rpm executable required by the test")
  120. endif()
  121. set(CPACK_RPM_PACKAGE_SUMMARY "default summary")
  122. set(CPACK_RPM_headers_PACKAGE_SUMMARY "headers summary")
  123. set(CPACK_RPM_headers_PACKAGE_DESCRIPTION "headers description")
  124. set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
  125. "An extremely useful application that makes use of MyLib")
  126. set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
  127. "Static libraries used to build programs with MyLib")
  128. set(LIB_SUFFIX "6?4?")
  129. # test package info
  130. if(${CPackComponentWay} STREQUAL "IgnoreGroup")
  131. # set gnu install prefixes to what they are set during rpm creation
  132. # CMAKE_SIZEOF_VOID_P is not set here but lib is prefix of lib64 so
  133. # relocation path test won't fail on OSes with lib64 library location
  134. include(GNUInstallDirs)
  135. set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/foo/bar")
  136. foreach(check_file ${expected_file})
  137. string(REGEX MATCH ".*libraries.*" check_file_libraries_match ${check_file})
  138. string(REGEX MATCH ".*headers.*" check_file_headers_match ${check_file})
  139. string(REGEX MATCH ".*applications.*" check_file_applications_match ${check_file})
  140. string(REGEX MATCH ".*Unspecified.*" check_file_Unspecified_match ${check_file})
  141. execute_process(COMMAND ${RPM_EXECUTABLE} -pqi ${check_file}
  142. OUTPUT_VARIABLE check_file_content
  143. ERROR_QUIET
  144. OUTPUT_STRIP_TRAILING_WHITESPACE)
  145. execute_process(COMMAND ${RPM_EXECUTABLE} -pqa ${check_file}
  146. RESULT_VARIABLE check_package_architecture_result
  147. OUTPUT_VARIABLE check_package_architecture
  148. ERROR_QUIET
  149. OUTPUT_STRIP_TRAILING_WHITESPACE)
  150. execute_process(COMMAND ${RPM_EXECUTABLE} -pql ${check_file}
  151. OUTPUT_VARIABLE check_package_content
  152. ERROR_QUIET
  153. OUTPUT_STRIP_TRAILING_WHITESPACE)
  154. set(whitespaces "[\\t\\n\\r ]*")
  155. if(check_file_libraries_match)
  156. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  157. set(check_file_match_expected_description ".*${CPACK_COMPONENT_LIBRARIES_DESCRIPTION}.*")
  158. 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")
  159. set(check_file_match_expected_architecture "") # we don't explicitly set this value so it is different on each platform - ignore it
  160. set(spec_regex "*libraries*")
  161. set(check_content_list "^/usr/foo/bar/lib${LIB_SUFFIX}
  162. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one
  163. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two
  164. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/depth_three
  165. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/depth_three/symlink_parentdir_path
  166. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_outside_package
  167. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_relocatable_subpath
  168. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_samedir_path
  169. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_samedir_path_current_dir
  170. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_samedir_path_longer
  171. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/symlink_subdir_path
  172. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two
  173. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two
  174. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two/different_relocatable
  175. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two/different_relocatable/bar
  176. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two/symlink_other_relocatable_path
  177. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two/symlink_to_non_relocatable_path
  178. /usr/foo/bar/lib${LIB_SUFFIX}/libmylib.a
  179. /usr/foo/bar/non_relocatable
  180. /usr/foo/bar/non_relocatable/depth_two
  181. /usr/foo/bar/non_relocatable/depth_two/symlink_from_non_relocatable_path
  182. /usr/foo/bar/other_relocatable
  183. /usr/foo/bar/other_relocatable/depth_two$")
  184. elseif(check_file_headers_match)
  185. set(check_file_match_expected_summary ".*${CPACK_RPM_headers_PACKAGE_SUMMARY}.*")
  186. set(check_file_match_expected_description ".*${CPACK_RPM_headers_PACKAGE_DESCRIPTION}.*")
  187. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
  188. set(check_file_match_expected_architecture "noarch")
  189. set(spec_regex "*headers*")
  190. set(check_content_list "^/usr/foo/bar\n/usr/foo/bar/include\n/usr/foo/bar/include/mylib.h$")
  191. elseif(check_file_applications_match)
  192. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  193. set(check_file_match_expected_description ".*${CPACK_COMPONENT_APPLICATIONS_DESCRIPTION}.*")
  194. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
  195. set(check_file_match_expected_architecture "armv7hf")
  196. set(spec_regex "*applications*")
  197. set(check_content_list "^/usr/foo/bar
  198. /usr/foo/bar/bin
  199. /usr/foo/bar/bin/mylibapp$")
  200. elseif(check_file_Unspecified_match)
  201. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  202. set(check_file_match_expected_description ".*DESCRIPTION.*")
  203. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
  204. set(check_file_match_expected_architecture "") # we don't explicitly set this value so it is different on each platform - ignore it
  205. set(spec_regex "*Unspecified*")
  206. set(check_content_list "^/usr/foo/bar
  207. /usr/foo/bar/bin
  208. /usr/foo/bar/bin/@in@_@path@@with
  209. /usr/foo/bar/bin/@in@_@path@@with/@and
  210. /usr/foo/bar/bin/@in@_@path@@with/@and/@
  211. /usr/foo/bar/bin/@in@_@path@@with/@and/@/@in_path@
  212. /usr/foo/bar/bin/@in@_@path@@with/@and/@/@in_path@/mylibapp2
  213. /usr/foo/bar/share
  214. /usr/foo/bar/share/man
  215. /usr/foo/bar/share/man/mylib
  216. /usr/foo/bar/share/man/mylib/man3
  217. /usr/foo/bar/share/man/mylib/man3/mylib.1
  218. /usr/foo/bar/share/man/mylib/man3/mylib.1/mylib
  219. /usr/foo/bar/share/man/mylib/man3/mylib.1/mylib2$")
  220. else()
  221. message(FATAL_ERROR "error: unexpected rpm package '${check_file}'")
  222. endif()
  223. #######################
  224. # test package info
  225. #######################
  226. string(REGEX MATCH ${check_file_match_expected_summary} check_file_match_summary ${check_file_content})
  227. if(NOT check_file_match_summary)
  228. 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}'")
  229. endif()
  230. string(REGEX MATCH ${check_file_match_expected_description} check_file_match_description ${check_file_content})
  231. if(NOT check_file_match_description)
  232. 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}'")
  233. endif()
  234. string(REGEX MATCH ${check_file_match_expected_relocation_path} check_file_match_relocation_path ${check_file_content})
  235. if(NOT check_file_match_relocation_path)
  236. file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/${spec_regex}.spec")
  237. if(spec_file)
  238. file(READ ${spec_file} spec_file_content)
  239. endif()
  240. 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}'")
  241. endif()
  242. #######################
  243. # test package architecture
  244. #######################
  245. string(REGEX MATCH "Architecture${whitespaces}:" check_info_contains_arch ${check_file_content})
  246. if(check_info_contains_arch) # test for rpm versions that contain architecture in package info (e.g. 4.11.x)
  247. string(REGEX MATCH "Architecture${whitespaces}:${whitespaces}${check_file_match_expected_architecture}" check_file_match_architecture ${check_file_content})
  248. if(NOT check_file_match_architecture)
  249. 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}'")
  250. endif()
  251. elseif(NOT check_package_architecture_result) # test result only on platforms that support -pqa rpm query
  252. # test for rpm versions that do not contain architecture in package info (e.g. 4.8.x)
  253. string(REGEX MATCH ".*${check_file_match_expected_architecture}" check_file_match_architecture "${check_package_architecture}")
  254. if(NOT check_file_match_architecture)
  255. 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}'")
  256. endif()
  257. # else rpm version too old (e.g. 4.4.x) - skip test
  258. endif()
  259. #######################
  260. # test package content
  261. #######################
  262. string(REGEX MATCH "${check_content_list}" expected_content_list "${check_package_content}")
  263. if(NOT expected_content_list)
  264. file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/${spec_regex}.spec")
  265. if(spec_file)
  266. file(READ ${spec_file} spec_file_content)
  267. endif()
  268. 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}'")
  269. endif()
  270. endforeach()
  271. #######################
  272. # verify generated symbolic links
  273. #######################
  274. file(GLOB_RECURSE symlink_files RELATIVE "${CPackComponentsForAll_BINARY_DIR}" "${CPackComponentsForAll_BINARY_DIR}/*/symlink_*")
  275. foreach(check_symlink IN LISTS symlink_files)
  276. get_filename_component(symlink_name "${check_symlink}" NAME)
  277. execute_process(COMMAND ls -la "${check_symlink}"
  278. WORKING_DIRECTORY "${CPackComponentsForAll_BINARY_DIR}"
  279. OUTPUT_VARIABLE SYMLINK_POINT_
  280. OUTPUT_STRIP_TRAILING_WHITESPACE)
  281. if("${symlink_name}" STREQUAL "symlink_samedir_path"
  282. OR "${symlink_name}" STREQUAL "symlink_samedir_path_current_dir"
  283. OR "${symlink_name}" STREQUAL "symlink_samedir_path_longer")
  284. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}depth_three$" check_symlink "${SYMLINK_POINT_}")
  285. elseif("${symlink_name}" STREQUAL "symlink_subdir_path")
  286. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}depth_two/depth_three$" check_symlink "${SYMLINK_POINT_}")
  287. elseif("${symlink_name}" STREQUAL "symlink_parentdir_path")
  288. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}../$" check_symlink "${SYMLINK_POINT_}")
  289. elseif("${symlink_name}" STREQUAL "symlink_to_non_relocatable_path")
  290. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/non_relocatable/depth_two$" check_symlink "${SYMLINK_POINT_}")
  291. elseif("${symlink_name}" STREQUAL "symlink_outside_package")
  292. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}outside_package$" check_symlink "${SYMLINK_POINT_}")
  293. elseif("${symlink_name}" STREQUAL "symlink_other_relocatable_path"
  294. OR "${symlink_name}" STREQUAL "symlink_from_non_relocatable_path"
  295. OR "${symlink_name}" STREQUAL "symlink_relocatable_subpath")
  296. # these links were not canged - post install script only - ignore them
  297. else()
  298. message(FATAL_ERROR "error: unexpected rpm symbolic link '${check_symlink}'")
  299. endif()
  300. if(NOT check_symlink)
  301. message(FATAL_ERROR "symlink points to unexpected location '${SYMLINK_POINT_}'")
  302. endif()
  303. endforeach()
  304. # verify post install symlink relocation script
  305. file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/*libraries*.spec")
  306. file(READ ${spec_file} spec_file_content)
  307. file(READ "${CMAKE_CURRENT_LIST_DIR}/symlink_postinstall_expected.txt" symlink_postinstall_expected)
  308. # prepare regex
  309. string(STRIP "${symlink_postinstall_expected}" symlink_postinstall_expected)
  310. string(REPLACE "[" "\\[" symlink_postinstall_expected "${symlink_postinstall_expected}")
  311. string(REPLACE "$" "\\$" symlink_postinstall_expected "${symlink_postinstall_expected}")
  312. string(REPLACE "lib" "lib${LIB_SUFFIX}" symlink_postinstall_expected "${symlink_postinstall_expected}")
  313. # compare
  314. string(REGEX MATCH ".*${symlink_postinstall_expected}.*" symlink_postinstall_expected_matches "${spec_file_content}")
  315. if(NOT symlink_postinstall_expected_matches)
  316. message(FATAL_ERROR "error: unexpected rpm symbolic link postinstall script! generated spec file: '${spec_file_content}'")
  317. endif()
  318. endif()
  319. endif()
  320. cmake_policy(POP)