RunCPackVerifyResult.cmake 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. if(${CPackComponentWay} STREQUAL "IgnoreGroup")
  126. foreach(check_file ${expected_file})
  127. string(REGEX MATCH ".*libraries.*" check_file_libraries_match ${check_file})
  128. string(REGEX MATCH ".*headers.*" check_file_headers_match ${check_file})
  129. string(REGEX MATCH ".*applications.*" check_file_applications_match ${check_file})
  130. string(REGEX MATCH ".*Unspecified.*" check_file_Unspecified_match ${check_file})
  131. execute_process(COMMAND ${RPM_EXECUTABLE} -pqi ${check_file}
  132. OUTPUT_VARIABLE check_file_content
  133. ERROR_QUIET
  134. OUTPUT_STRIP_TRAILING_WHITESPACE)
  135. if(check_file_libraries_match)
  136. set(check_file_match_expected_summary ".*${CPACK_RPM_libraries_PACKAGE_SUMMARY}.*")
  137. set(check_file_match_expected_description ".*${CPACK_RPM_libraries_PACKAGE_DESCRIPTION}.*")
  138. elseif(check_file_headers_match)
  139. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  140. set(check_file_match_expected_description ".*${CPACK_COMPONENT_HEADERS_DESCRIPTION}.*")
  141. elseif(check_file_applications_match)
  142. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  143. set(check_file_match_expected_description ".*${CPACK_COMPONENT_APPLICATIONS_DESCRIPTION}.*")
  144. elseif(check_file_Unspecified_match)
  145. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  146. set(check_file_match_expected_description ".*DESCRIPTION.*")
  147. else()
  148. message(FATAL_ERROR "error: unexpected rpm package '${check_file}'")
  149. endif()
  150. string(REGEX MATCH ${check_file_match_expected_summary} check_file_match_summary ${check_file_content})
  151. if(NOT check_file_match_summary)
  152. message(FATAL_ERROR "error: '${check_file}' rpm package summary does not match expected value - regex '${check_file_match_expected_summary}'")
  153. endif()
  154. string(REGEX MATCH ${check_file_match_expected_description} check_file_match_description ${check_file_content})
  155. if(NOT check_file_match_description)
  156. message(FATAL_ERROR "error: '${check_file}' rpm package description does not match expected value - regex '${check_file_match_expected_description}'")
  157. endif()
  158. endforeach()
  159. elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
  160. endif()
  161. endif()