RunCPackVerifyResult.cmake 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. message(STATUS "=============================================================================")
  2. message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
  3. message(STATUS "")
  4. if(NOT CPackComponentsForAll_BINARY_DIR)
  5. message(FATAL_ERROR "CPackComponentsForAll_BINARY_DIR not set")
  6. endif()
  7. if(NOT CPackGen)
  8. message(FATAL_ERROR "CPackGen not set")
  9. endif()
  10. message("CMAKE_CPACK_COMMAND = ${CMAKE_CPACK_COMMAND}")
  11. if(NOT CMAKE_CPACK_COMMAND)
  12. message(FATAL_ERROR "CMAKE_CPACK_COMMAND not set")
  13. endif()
  14. if(NOT CPackComponentWay)
  15. message(FATAL_ERROR "CPackComponentWay not set")
  16. endif()
  17. set(expected_file_mask "")
  18. # The usual default behavior is to expect a single file
  19. # Then some specific generators (Archive, RPM, ...)
  20. # May produce several numbers of files depending on
  21. # CPACK_COMPONENT_xxx values
  22. set(expected_count 1)
  23. set(config_type $ENV{CMAKE_CONFIG_TYPE})
  24. set(config_args )
  25. if(config_type)
  26. set(config_args -C ${config_type})
  27. endif()
  28. set(config_verbose )
  29. if(CPackGen MATCHES "ZIP")
  30. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.zip")
  31. if (${CPackComponentWay} STREQUAL "default")
  32. set(expected_count 1)
  33. elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
  34. set(expected_count 3)
  35. elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
  36. set(expected_count 4)
  37. elseif (${CPackComponentWay} STREQUAL "AllInOne")
  38. set(expected_count 1)
  39. endif ()
  40. elseif (CPackGen MATCHES "RPM")
  41. set(config_verbose -D "CPACK_RPM_PACKAGE_DEBUG=1")
  42. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.rpm")
  43. if (${CPackComponentWay} STREQUAL "default")
  44. set(expected_count 1)
  45. elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
  46. set(expected_count 3)
  47. elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
  48. set(expected_count 4)
  49. elseif (${CPackComponentWay} STREQUAL "AllInOne")
  50. set(expected_count 1)
  51. endif ()
  52. elseif (CPackGen MATCHES "DEB")
  53. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.deb")
  54. if (${CPackComponentWay} STREQUAL "default")
  55. set(expected_count 1)
  56. elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
  57. set(expected_count 3)
  58. elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
  59. set(expected_count 4)
  60. elseif (${CPackComponentWay} STREQUAL "AllInOne")
  61. set(expected_count 1)
  62. endif ()
  63. endif()
  64. if(CPackGen MATCHES "DragNDrop")
  65. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.dmg")
  66. if (${CPackComponentWay} STREQUAL "default")
  67. set(expected_count 1)
  68. elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
  69. set(expected_count 3)
  70. elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
  71. set(expected_count 4)
  72. elseif (${CPackComponentWay} STREQUAL "AllInOne")
  73. set(expected_count 1)
  74. endif ()
  75. endif()
  76. # clean-up previously CPack generated files
  77. if(expected_file_mask)
  78. file(GLOB expected_file "${expected_file_mask}")
  79. if (expected_file)
  80. file(REMOVE ${expected_file})
  81. endif()
  82. endif()
  83. message("config_args = ${config_args}")
  84. message("config_verbose = ${config_verbose}")
  85. execute_process(COMMAND ${CMAKE_CPACK_COMMAND} ${config_verbose} -G ${CPackGen} ${config_args}
  86. RESULT_VARIABLE CPack_result
  87. OUTPUT_VARIABLE CPack_output
  88. ERROR_VARIABLE CPack_error
  89. WORKING_DIRECTORY ${CPackComponentsForAll_BINARY_DIR})
  90. if (CPack_result)
  91. message(FATAL_ERROR "error: CPack execution went wrong!, CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  92. else ()
  93. message(STATUS "CPack_output=${CPack_output}")
  94. endif()
  95. # Now verify if the number of expected file is OK
  96. # - using expected_file_mask and
  97. # - expected_count
  98. if(expected_file_mask)
  99. file(GLOB expected_file "${expected_file_mask}")
  100. message(STATUS "expected_count='${expected_count}'")
  101. message(STATUS "expected_file='${expected_file}'")
  102. message(STATUS "expected_file_mask='${expected_file_mask}'")
  103. if(NOT expected_file)
  104. message(FATAL_ERROR "error: expected_file=${expected_file} does not exist: CPackComponentsForAll test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  105. endif()
  106. list(LENGTH expected_file actual_count)
  107. message(STATUS "actual_count='${actual_count}'")
  108. if(NOT actual_count EQUAL expected_count)
  109. 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})")
  110. endif()
  111. endif()
  112. # Validate content
  113. if(CPackGen MATCHES "RPM")
  114. find_program(RPM_EXECUTABLE rpm)
  115. if(NOT RPM_EXECUTABLE)
  116. message(FATAL_ERROR "error: missing rpm executable required by the test")
  117. endif()
  118. set(CPACK_RPM_PACKAGE_SUMMARY "default summary")
  119. set(CPACK_RPM_libraries_PACKAGE_SUMMARY "libraries summary")
  120. set(CPACK_RPM_libraries_PACKAGE_DESCRIPTION "libraries description")
  121. set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
  122. "An extremely useful application that makes use of MyLib")
  123. set(CPACK_COMPONENT_HEADERS_DESCRIPTION
  124. "C/C\\+\\+ header files for use with MyLib")
  125. # test package info
  126. if(${CPackComponentWay} STREQUAL "IgnoreGroup")
  127. # set gnu install prefixes to what they are set during rpm creation
  128. # CMAKE_SIZEOF_VOID_P is not set here but lib is prefix of lib64 so
  129. # relocation path test won't fail on OSes with lib64 library location
  130. include(GNUInstallDirs)
  131. set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/foo/bar")
  132. foreach(check_file ${expected_file})
  133. string(REGEX MATCH ".*libraries.*" check_file_libraries_match ${check_file})
  134. string(REGEX MATCH ".*headers.*" check_file_headers_match ${check_file})
  135. string(REGEX MATCH ".*applications.*" check_file_applications_match ${check_file})
  136. string(REGEX MATCH ".*Unspecified.*" check_file_Unspecified_match ${check_file})
  137. execute_process(COMMAND ${RPM_EXECUTABLE} -pqi ${check_file}
  138. OUTPUT_VARIABLE check_file_content
  139. ERROR_QUIET
  140. OUTPUT_STRIP_TRAILING_WHITESPACE)
  141. execute_process(COMMAND ${RPM_EXECUTABLE} -pql ${check_file}
  142. OUTPUT_VARIABLE check_package_content
  143. ERROR_QUIET
  144. OUTPUT_STRIP_TRAILING_WHITESPACE)
  145. set(whitespaces "[\\t\\n\\r ]*")
  146. if(check_file_libraries_match)
  147. set(check_file_match_expected_summary ".*${CPACK_RPM_libraries_PACKAGE_SUMMARY}.*")
  148. set(check_file_match_expected_description ".*${CPACK_RPM_libraries_PACKAGE_DESCRIPTION}.*")
  149. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
  150. set(check_file_match_expected_architecture "Architecture: ${CPACK_RPM_applications_PACKAGE_ARCHITECTURE}")
  151. set(spec_regex "*libraries*")
  152. set(check_content_list "^/usr/foo/bar\n/usr/foo/bar/lib.*\n/usr/foo/bar/lib.*/libmylib.a$")
  153. elseif(check_file_headers_match)
  154. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  155. set(check_file_match_expected_description ".*${CPACK_COMPONENT_HEADERS_DESCRIPTION}.*")
  156. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
  157. set(check_file_match_expected_architecture "Architecture: ${CPACK_RPM_libraries_PACKAGE_ARCHITECTURE}")
  158. set(spec_regex "*headers*")
  159. set(check_content_list "^/usr/foo/bar\n/usr/foo/bar/include\n/usr/foo/bar/include/mylib.h$")
  160. elseif(check_file_applications_match)
  161. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  162. set(check_file_match_expected_description ".*${CPACK_COMPONENT_APPLICATIONS_DESCRIPTION}.*")
  163. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}.*")
  164. set(check_file_match_expected_architecture "Architecture: ${CPACK_RPM_headers_PACKAGE_ARCHITECTURE}")
  165. set(spec_regex "*applications*")
  166. set(check_content_list "^/usr/foo/bar\n/usr/foo/bar/bin\n/usr/foo/bar/bin/mylibapp$")
  167. elseif(check_file_Unspecified_match)
  168. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  169. set(check_file_match_expected_description ".*DESCRIPTION.*")
  170. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
  171. set(check_file_match_expected_architecture "Architecture: ${CPACK_RPM_Unspecified_PACKAGE_ARCHITECTURE}")
  172. set(spec_regex "*Unspecified*")
  173. set(check_content_list "^/usr/foo/bar
  174. /usr/foo/bar/bin
  175. /usr/foo/bar/bin/@in@_@path@@with
  176. /usr/foo/bar/bin/@in@_@path@@with/@and
  177. /usr/foo/bar/bin/@in@_@path@@with/@and/@
  178. /usr/foo/bar/bin/@in@_@path@@with/@and/@/@in_path@
  179. /usr/foo/bar/bin/@in@_@path@@with/@and/@/@in_path@/mylibapp2$")
  180. else()
  181. message(FATAL_ERROR "error: unexpected rpm package '${check_file}'")
  182. endif()
  183. #######################
  184. # test package info
  185. #######################
  186. string(REGEX MATCH ${check_file_match_expected_summary} check_file_match_summary ${check_file_content})
  187. if(NOT check_file_match_summary)
  188. 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}'")
  189. endif()
  190. string(REGEX MATCH ${check_file_match_expected_description} check_file_match_description ${check_file_content})
  191. if(NOT check_file_match_description)
  192. 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}'")
  193. endif()
  194. string(REGEX MATCH ${check_file_match_expected_relocation_path} check_file_match_relocation_path ${check_file_content})
  195. if(NOT check_file_match_relocation_path)
  196. file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/${spec_regex}.spec")
  197. if(spec_file)
  198. file(READ ${spec_file} spec_file_content)
  199. endif()
  200. 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}'")
  201. endif()
  202. string(REGEX MATCH ${check_file_match_expected_architecture} check_file_match_architecture ${check_file_content})
  203. if (NOT check_file_match_architecture)
  204. 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}'")
  205. endif()
  206. #######################
  207. # test package content
  208. #######################
  209. string(REGEX MATCH "${check_content_list}" expected_content_list "${check_package_content}")
  210. if(NOT expected_content_list)
  211. file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/${spec_regex}.spec")
  212. if(spec_file)
  213. file(READ ${spec_file} spec_file_content)
  214. endif()
  215. 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}'")
  216. endif()
  217. endforeach()
  218. endif()
  219. endif()