RunCPackVerifyResult.cmake 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. # prevent older policies from interfearing with this script
  2. cmake_policy(PUSH)
  3. cmake_policy(VERSION ${CMAKE_VERSION})
  4. include(CMakeParseArguments)
  5. message(STATUS "=============================================================================")
  6. message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
  7. message(STATUS "")
  8. if(NOT CPackComponentsDEB_BINARY_DIR)
  9. message(FATAL_ERROR "CPackComponentsDEB_BINARY_DIR not set")
  10. endif()
  11. if(NOT CPackGen)
  12. message(FATAL_ERROR "CPackGen not set")
  13. endif()
  14. message("CMAKE_CPACK_COMMAND = ${CMAKE_CPACK_COMMAND}")
  15. if(NOT CMAKE_CPACK_COMMAND)
  16. message(FATAL_ERROR "CMAKE_CPACK_COMMAND not set")
  17. endif()
  18. if(NOT CPackDEBConfiguration)
  19. message(FATAL_ERROR "CPackDEBConfiguration not set")
  20. endif()
  21. # run cpack with some options and returns the list of files generated
  22. # -output_expected_file: list of files that match the pattern
  23. function(run_cpack output_expected_file CPack_output_parent CPack_error_parent)
  24. set(options )
  25. set(oneValueArgs "EXPECTED_FILE_MASK" "CONFIG_VERBOSE")
  26. set(multiValueArgs "CONFIG_ARGS")
  27. cmake_parse_arguments(run_cpack_deb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  28. # clean-up previously CPack generated files
  29. if(${run_cpack_deb_EXPECTED_FILE_MASK})
  30. file(GLOB expected_file "${${run_cpack_deb_EXPECTED_FILE_MASK}}")
  31. if (expected_file)
  32. file(REMOVE "${expected_file}")
  33. endif()
  34. endif()
  35. message("config_args = ${run_cpack_deb_CONFIG_ARGS}")
  36. message("config_verbose = ${run_cpack_deb_CONFIG_VERBOSE}")
  37. execute_process(COMMAND ${CMAKE_CPACK_COMMAND} ${run_cpack_deb_CONFIG_VERBOSE} -G ${CPackGen} ${run_cpack_deb_CONFIG_ARGS}
  38. RESULT_VARIABLE CPack_result
  39. OUTPUT_VARIABLE CPack_output
  40. ERROR_VARIABLE CPack_error
  41. WORKING_DIRECTORY ${CPackComponentsDEB_BINARY_DIR})
  42. set(${CPack_output_parent} ${CPack_output} PARENT_SCOPE)
  43. set(${CPack_error_parent} ${CPack_error} PARENT_SCOPE)
  44. if (CPack_result)
  45. message(FATAL_ERROR "error: CPack execution went wrong!, CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  46. else ()
  47. message(STATUS "CPack_output=${CPack_output}")
  48. message(STATUS "CPack_error=${CPack_error}")
  49. endif()
  50. if(run_cpack_deb_EXPECTED_FILE_MASK)
  51. file(GLOB _output_expected_file "${run_cpack_deb_EXPECTED_FILE_MASK}")
  52. set(${output_expected_file} "${_output_expected_file}" PARENT_SCOPE)
  53. endif()
  54. endfunction()
  55. # This function runs lintian on a .deb and returns its output
  56. function(run_lintian lintian_output)
  57. set(${lintian_output} "" PARENT_SCOPE)
  58. find_program(LINTIAN_EXECUTABLE lintian)
  59. if(LINTIAN_EXECUTABLE)
  60. set(options "")
  61. set(oneValueArgs "FILENAME")
  62. set(multiValueArgs "")
  63. cmake_parse_arguments(run_lintian_deb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  64. if(NOT run_lintian_deb_FILENAME)
  65. message(FATAL_ERROR "error: run_lintian needs FILENAME to be set")
  66. endif()
  67. # run dpkg-deb
  68. execute_process(COMMAND ${LINTIAN_EXECUTABLE} ${run_lintian_deb_FILENAME}
  69. WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
  70. OUTPUT_VARIABLE LINTIAN_OUTPUT
  71. RESULT_VARIABLE LINTIAN_RESULT
  72. ERROR_VARIABLE LINTIAN_ERROR
  73. OUTPUT_STRIP_TRAILING_WHITESPACE )
  74. set(${lintian_output} "${LINTIAN_OUTPUT}" PARENT_SCOPE)
  75. else()
  76. message(FATAL_ERROR "run_lintian called without lintian executable being present")
  77. endif()
  78. endfunction()
  79. # Higher level lintian check that parse the output for errors and required strings
  80. function(lintian_check_specific_errors output_errors)
  81. set(${output_errors} "" PARENT_SCOPE)
  82. set(ERROR_ACC)
  83. set(options "")
  84. set(oneValueArgs "FILENAME")
  85. set(multiValueArgs "ERROR_REGEX_STRINGS")
  86. cmake_parse_arguments(lintian_check_specific_errors_deb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  87. set(lintian_output)
  88. run_lintian(lintian_output FILENAME ${lintian_check_specific_errors_deb_FILENAME})
  89. message(STATUS "Lintian output is ''${lintian_output}'")
  90. # regex to avoid
  91. foreach(_s IN LISTS lintian_check_specific_errors_deb_ERROR_REGEX_STRINGS)
  92. if("${_s}" STREQUAL "")
  93. continue()
  94. endif()
  95. string(REGEX MATCHALL "${_s}" "_TMP_CHECK_ERROR" "${lintian_output}")
  96. if(NOT "${_TMP_CHECK_ERROR}" STREQUAL "")
  97. string(APPEND ERROR_ACC "\nlintian: ${_f}: output contains an undesirable regex:\n\t${_TMP_CHECK_ERROR}")
  98. endif()
  99. endforeach()
  100. set(${output_errors} "${ERROR_ACC}" PARENT_SCOPE)
  101. endfunction()
  102. # This function runs dpkg-deb on a .deb and returns its output
  103. # the default behaviour it to run "--info" on the specified Debian package
  104. # ACTION is one of the option accepted by dpkg-deb
  105. function(run_dpkgdeb dpkg_deb_output)
  106. set(${dpkg_deb_output} "" PARENT_SCOPE)
  107. find_program(DPKGDEB_EXECUTABLE dpkg-deb)
  108. if(DPKGDEB_EXECUTABLE)
  109. set(options "")
  110. set(oneValueArgs "FILENAME" "ACTION")
  111. set(multiValueArgs "")
  112. cmake_parse_arguments(run_dpkgdeb_deb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  113. if(NOT run_dpkgdeb_deb_FILENAME)
  114. message(FATAL_ERROR "error: run_dpkgdeb needs FILENAME to be set")
  115. endif()
  116. if(NOT run_dpkgdeb_deb_ACTION)
  117. set(run_dpkgdeb_deb_ACTION "--info")
  118. endif()
  119. # run dpkg-deb
  120. execute_process(COMMAND ${DPKGDEB_EXECUTABLE} ${run_dpkgdeb_deb_ACTION} ${run_dpkgdeb_deb_FILENAME}
  121. WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
  122. OUTPUT_VARIABLE DPKGDEB_OUTPUT
  123. RESULT_VARIABLE DPKGDEB_RESULT
  124. ERROR_VARIABLE DPKGDEB_ERROR
  125. OUTPUT_STRIP_TRAILING_WHITESPACE )
  126. if(NOT ("${DPKGDEB_RESULT}" EQUAL "0"))
  127. message(FATAL_ERROR "Error '${DPKGDEB_RESULT}' returned by dpkg-deb: '${DPKGDEB_ERROR}'")
  128. endif()
  129. set(${dpkg_deb_output} "${DPKGDEB_OUTPUT}" PARENT_SCOPE)
  130. else()
  131. message(FATAL_ERROR "run_dpkgdeb called without dpkg-deb executable being present")
  132. endif()
  133. endfunction()
  134. # returns a particular line of the metadata of the .deb, for checking
  135. # a previous call to run_dpkgdeb should provide the DPKGDEB_OUTPUT entry.
  136. function(dpkgdeb_return_specific_metaentry output)
  137. set(${output} "" PARENT_SCOPE)
  138. set(options "")
  139. set(oneValueArgs "DPKGDEB_OUTPUT" "METAENTRY")
  140. set(multiValueArgs "")
  141. cmake_parse_arguments(dpkgdeb_return_specific_metaentry_deb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  142. if(NOT dpkgdeb_return_specific_metaentry_deb_METAENTRY)
  143. message(FATAL_ERROR "error: dpkgdeb_return_specific_metaentry needs METAENTRY to be set")
  144. endif()
  145. string(REGEX MATCH "${dpkgdeb_return_specific_metaentry_deb_METAENTRY}([^\r\n]*)" _TMP_STR "${dpkgdeb_return_specific_metaentry_deb_DPKGDEB_OUTPUT}")
  146. #message("################ _TMP_STR = ${CMAKE_MATCH_1} ##################")
  147. if(NOT "${CMAKE_MATCH_1}" STREQUAL "")
  148. string(STRIP "${CMAKE_MATCH_1}" _TMP_STR)
  149. set(${output} "${_TMP_STR}" PARENT_SCOPE)
  150. endif()
  151. endfunction()
  152. cmake_policy(POP)