CMake/Tests/CPackComponentsForAll/RunCPackVerifyResult.cmake

253 lines
11 KiB
CMake
Raw Normal View History

2010-12-03 00:56:26 +03:00
message(STATUS "=============================================================================")
message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
message(STATUS "")
if(NOT CPackComponentsForAll_BINARY_DIR)
message(FATAL_ERROR "CPackComponentsForAll_BINARY_DIR not set")
endif()
2010-12-03 00:56:26 +03:00
if(NOT CPackGen)
message(FATAL_ERROR "CPackGen not set")
endif()
message("CMAKE_CPACK_COMMAND = ${CMAKE_CPACK_COMMAND}")
if(NOT CMAKE_CPACK_COMMAND)
message(FATAL_ERROR "CMAKE_CPACK_COMMAND not set")
endif()
if(NOT CPackComponentWay)
message(FATAL_ERROR "CPackComponentWay not set")
endif()
2010-12-03 00:56:26 +03:00
set(expected_file_mask "")
# The usual default behavior is to expect a single file
# Then some specific generators (Archive, RPM, ...)
# May produce several numbers of files depending on
# CPACK_COMPONENT_xxx values
set(expected_count 1)
set(config_type $ENV{CMAKE_CONFIG_TYPE})
set(config_args )
if(config_type)
set(config_args -C ${config_type})
endif()
set(config_verbose )
2010-12-03 00:56:26 +03:00
if(CPackGen MATCHES "ZIP")
set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.zip")
if (${CPackComponentWay} STREQUAL "default")
set(expected_count 1)
elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
set(expected_count 3)
elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
set(expected_count 4)
elseif (${CPackComponentWay} STREQUAL "AllInOne")
set(expected_count 1)
endif ()
elseif (CPackGen MATCHES "RPM")
set(config_verbose -D "CPACK_RPM_PACKAGE_DEBUG=1")
set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.rpm")
if (${CPackComponentWay} STREQUAL "default")
set(expected_count 1)
elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
set(expected_count 3)
elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
set(expected_count 4)
elseif (${CPackComponentWay} STREQUAL "AllInOne")
set(expected_count 1)
endif ()
elseif (CPackGen MATCHES "DEB")
set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.deb")
if (${CPackComponentWay} STREQUAL "default")
set(expected_count 1)
elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
set(expected_count 3)
elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
set(expected_count 4)
elseif (${CPackComponentWay} STREQUAL "AllInOne")
set(expected_count 1)
endif ()
endif()
2010-12-03 00:56:26 +03:00
if(CPackGen MATCHES "DragNDrop")
set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.dmg")
if (${CPackComponentWay} STREQUAL "default")
set(expected_count 1)
elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
set(expected_count 3)
elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
set(expected_count 4)
elseif (${CPackComponentWay} STREQUAL "AllInOne")
set(expected_count 1)
endif ()
endif()
# clean-up previously CPack generated files
if(expected_file_mask)
file(GLOB expected_file "${expected_file_mask}")
if (expected_file)
file(REMOVE ${expected_file})
endif()
endif()
message("config_args = ${config_args}")
message("config_verbose = ${config_verbose}")
execute_process(COMMAND ${CMAKE_CPACK_COMMAND} ${config_verbose} -G ${CPackGen} ${config_args}
RESULT_VARIABLE CPack_result
OUTPUT_VARIABLE CPack_output
ERROR_VARIABLE CPack_error
WORKING_DIRECTORY ${CPackComponentsForAll_BINARY_DIR})
if (CPack_result)
message(FATAL_ERROR "error: CPack execution went wrong!, CPack_output=${CPack_output}, CPack_error=${CPack_error}")
else ()
message(STATUS "CPack_output=${CPack_output}")
endif()
# Now verify if the number of expected file is OK
# - using expected_file_mask and
# - expected_count
2010-12-03 00:56:26 +03:00
if(expected_file_mask)
file(GLOB expected_file "${expected_file_mask}")
message(STATUS "expected_count='${expected_count}'")
message(STATUS "expected_file='${expected_file}'")
message(STATUS "expected_file_mask='${expected_file_mask}'")
if(NOT expected_file)
2010-12-13 00:35:18 +03:00
message(FATAL_ERROR "error: expected_file=${expected_file} does not exist: CPackComponentsForAll test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error}")
endif()
2010-12-03 00:56:26 +03:00
list(LENGTH expected_file actual_count)
message(STATUS "actual_count='${actual_count}'")
if(NOT actual_count EQUAL expected_count)
2010-12-13 00:35:18 +03:00
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})")
endif()
endif()
# Validate content
if(CPackGen MATCHES "RPM")
find_program(RPM_EXECUTABLE rpm)
if(NOT RPM_EXECUTABLE)
message(FATAL_ERROR "error: missing rpm executable required by the test")
endif()
set(CPACK_RPM_PACKAGE_SUMMARY "default summary")
set(CPACK_RPM_libraries_PACKAGE_SUMMARY "libraries summary")
set(CPACK_RPM_libraries_PACKAGE_DESCRIPTION "libraries description")
set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
"An extremely useful application that makes use of MyLib")
set(CPACK_COMPONENT_HEADERS_DESCRIPTION
"C/C\\+\\+ header files for use with MyLib")
# test package info
if(${CPackComponentWay} STREQUAL "IgnoreGroup")
# set gnu install prefixes to what they are set during rpm creation
# CMAKE_SIZEOF_VOID_P is not set here but lib is prefix of lib64 so
# relocation path test won't fail on OSes with lib64 library location
include(GNUInstallDirs)
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/foo/bar")
foreach(check_file ${expected_file})
string(REGEX MATCH ".*libraries.*" check_file_libraries_match ${check_file})
string(REGEX MATCH ".*headers.*" check_file_headers_match ${check_file})
string(REGEX MATCH ".*applications.*" check_file_applications_match ${check_file})
string(REGEX MATCH ".*Unspecified.*" check_file_Unspecified_match ${check_file})
execute_process(COMMAND ${RPM_EXECUTABLE} -pqi ${check_file}
OUTPUT_VARIABLE check_file_content
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${RPM_EXECUTABLE} -pql ${check_file}
OUTPUT_VARIABLE check_package_content
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(check_file_libraries_match)
set(check_file_match_expected_summary ".*${CPACK_RPM_libraries_PACKAGE_SUMMARY}.*")
set(check_file_match_expected_description ".*${CPACK_RPM_libraries_PACKAGE_DESCRIPTION}.*")
set(check_file_match_expected_relocation_path "Relocations : ${CPACK_PACKAGING_INSTALL_PREFIX} ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set(check_file_match_expected_architecture "Architecture: ${CPACK_RPM_applications_PACKAGE_ARCHITECTURE}")
set(spec_regex "*libraries*")
set(check_content_list "^/usr/foo/bar\n/usr/foo/bar/lib.*\n/usr/foo/bar/lib.*/libmylib.a$")
elseif(check_file_headers_match)
set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
set(check_file_match_expected_description ".*${CPACK_COMPONENT_HEADERS_DESCRIPTION}.*")
set(check_file_match_expected_relocation_path "Relocations : ${CPACK_PACKAGING_INSTALL_PREFIX} ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
set(check_file_match_expected_architecture "Architecture: ${CPACK_RPM_libraries_PACKAGE_ARCHITECTURE}")
set(spec_regex "*headers*")
set(check_content_list "^/usr/foo/bar\n/usr/foo/bar/include\n/usr/foo/bar/include/mylib.h$")
elseif(check_file_applications_match)
set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
set(check_file_match_expected_description ".*${CPACK_COMPONENT_APPLICATIONS_DESCRIPTION}.*")
set(check_file_match_expected_relocation_path "Relocations : ${CPACK_PACKAGING_INSTALL_PREFIX} ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
set(check_file_match_expected_architecture "Architecture: ${CPACK_RPM_headers_PACKAGE_ARCHITECTURE}")
set(spec_regex "*applications*")
set(check_content_list "^/usr/foo/bar\n/usr/foo/bar/bin\n/usr/foo/bar/bin/mylibapp$")
elseif(check_file_Unspecified_match)
set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
set(check_file_match_expected_description ".*DESCRIPTION.*")
set(check_file_match_expected_relocation_path "Relocations : ${CPACK_PACKAGING_INSTALL_PREFIX} ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
set(check_file_match_expected_architecture "Architecture: ${CPACK_RPM_Unspecified_PACKAGE_ARCHITECTURE}")
set(spec_regex "*Unspecified*")
set(check_content_list "^/usr/foo/bar
/usr/foo/bar/bin
/usr/foo/bar/bin/@in@_@path@@with
/usr/foo/bar/bin/@in@_@path@@with/@and
/usr/foo/bar/bin/@in@_@path@@with/@and/@
/usr/foo/bar/bin/@in@_@path@@with/@and/@/@in_path@
/usr/foo/bar/bin/@in@_@path@@with/@and/@/@in_path@/mylibapp2$")
else()
message(FATAL_ERROR "error: unexpected rpm package '${check_file}'")
endif()
#######################
# test package info
#######################
string(REGEX MATCH ${check_file_match_expected_summary} check_file_match_summary ${check_file_content})
if(NOT check_file_match_summary)
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}'")
endif()
string(REGEX MATCH ${check_file_match_expected_description} check_file_match_description ${check_file_content})
if(NOT check_file_match_description)
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}'")
endif()
string(REGEX MATCH ${check_file_match_expected_relocation_path} check_file_match_relocation_path ${check_file_content})
if(NOT check_file_match_relocation_path)
file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/${spec_regex}.spec")
if(spec_file)
file(READ ${spec_file} spec_file_content)
endif()
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}'")
endif()
string(REGEX MATCH ${check_file_match_expected_architecture} check_file_match_architecture ${check_file_content})
if (NOT check_file_match_architecture)
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}'")
endif()
#######################
# test package content
#######################
string(REGEX MATCH "${check_content_list}" expected_content_list "${check_package_content}")
if(NOT expected_content_list)
file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/${spec_regex}.spec")
if(spec_file)
file(READ ${spec_file} spec_file_content)
endif()
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}'")
endif()
endforeach()
endif()
endif()