RunCPackVerifyResult.cmake 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. endif()
  49. if(run_cpack_deb_EXPECTED_FILE_MASK)
  50. file(GLOB _output_expected_file "${run_cpack_deb_EXPECTED_FILE_MASK}")
  51. set(${output_expected_file} "${_output_expected_file}" PARENT_SCOPE)
  52. endif()
  53. endfunction()
  54. # This function runs lintian on a .deb and returns its output
  55. function(run_lintian lintian_output)
  56. set(${lintian_output} "" PARENT_SCOPE)
  57. find_program(LINTIAN_EXECUTABLE lintian)
  58. if(LINTIAN_EXECUTABLE)
  59. set(options "")
  60. set(oneValueArgs "FILENAME")
  61. set(multiValueArgs "")
  62. cmake_parse_arguments(run_lintian_deb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  63. if(NOT run_lintian_deb_FILENAME)
  64. message(FATAL_ERROR "error: run_lintian needs FILENAME to be set")
  65. endif()
  66. # run lintian
  67. execute_process(COMMAND ${LINTIAN_EXECUTABLE} ${run_lintian_deb_FILENAME}
  68. WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
  69. OUTPUT_VARIABLE LINTIAN_OUTPUT
  70. RESULT_VARIABLE LINTIAN_RESULT
  71. ERROR_VARIABLE LINTIAN_ERROR
  72. OUTPUT_STRIP_TRAILING_WHITESPACE )
  73. set(${lintian_output} "${LINTIAN_OUTPUT}" PARENT_SCOPE)
  74. else()
  75. message(FATAL_ERROR "run_lintian called without lintian executable being present")
  76. endif()
  77. endfunction()
  78. # Higher level lintian check that parse the output for errors and required strings
  79. function(lintian_check_specific_errors output_errors)
  80. set(${output_errors} "" PARENT_SCOPE)
  81. set(ERROR_ACC)
  82. set(options "")
  83. set(oneValueArgs "FILENAME")
  84. set(multiValueArgs "ERROR_REGEX_STRINGS")
  85. cmake_parse_arguments(lintian_check_specific_errors_deb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  86. set(lintian_output)
  87. run_lintian(lintian_output FILENAME ${lintian_check_specific_errors_deb_FILENAME})
  88. message(STATUS "Lintian output is ''${lintian_output}'")
  89. # regex to avoid
  90. foreach(_s IN LISTS lintian_check_specific_errors_deb_ERROR_REGEX_STRINGS)
  91. if("${_s}" STREQUAL "")
  92. continue()
  93. endif()
  94. string(REGEX MATCHALL "${_s}" "_TMP_CHECK_ERROR" "${lintian_output}")
  95. if(NOT "${_TMP_CHECK_ERROR}" STREQUAL "")
  96. set(ERROR_ACC "${ERROR_ACC}\nlintian: ${_f}: output contains an undesirable regex:\n\t${_TMP_CHECK_ERROR}")
  97. endif()
  98. endforeach()
  99. set(${output_errors} "${ERROR_ACC}" PARENT_SCOPE)
  100. endfunction()
  101. # This function runs dpkg-deb on a .deb and returns its output
  102. function(run_dpkgdeb dpkg_deb_output)
  103. set(${dpkg_deb_output} "" PARENT_SCOPE)
  104. find_program(DPKGDEB_EXECUTABLE dpkg-deb)
  105. if(DPKGDEB_EXECUTABLE)
  106. set(options "")
  107. set(oneValueArgs "FILENAME")
  108. set(multiValueArgs "")
  109. cmake_parse_arguments(run_dpkgdeb_deb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  110. if(NOT run_dpkgdeb_deb_FILENAME)
  111. message(FATAL_ERROR "error: run_dpkgdeb needs FILENAME to be set")
  112. endif()
  113. # run lintian
  114. execute_process(COMMAND ${DPKGDEB_EXECUTABLE} -I ${run_dpkgdeb_deb_FILENAME}
  115. WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
  116. OUTPUT_VARIABLE DPKGDEB_OUTPUT
  117. RESULT_VARIABLE DPKGDEB_RESULT
  118. ERROR_VARIABLE DPKGDEB_ERROR
  119. OUTPUT_STRIP_TRAILING_WHITESPACE )
  120. set(${dpkg_deb_output} "${DPKGDEB_OUTPUT}" PARENT_SCOPE)
  121. else()
  122. message(FATAL_ERROR "run_dpkgdeb called without dpkg-deb executable being present")
  123. endif()
  124. endfunction()
  125. # returns a particular line of the metadata of the .deb, for checking
  126. # a previous call to run_dpkgdeb should provide the DPKGDEB_OUTPUT entry.
  127. function(dpkgdeb_return_specific_metaentry output)
  128. set(${output} "" PARENT_SCOPE)
  129. set(options "")
  130. set(oneValueArgs "DPKGDEB_OUTPUT" "METAENTRY")
  131. set(multiValueArgs "")
  132. cmake_parse_arguments(dpkgdeb_return_specific_metaentry_deb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  133. if(NOT dpkgdeb_return_specific_metaentry_deb_METAENTRY)
  134. message(FATAL_ERROR "error: dpkgdeb_return_specific_metaentry needs METAENTRY to be set")
  135. endif()
  136. string(REGEX MATCH "${dpkgdeb_return_specific_metaentry_deb_METAENTRY}([^\r\n]*)" _TMP_STR "${dpkgdeb_return_specific_metaentry_deb_DPKGDEB_OUTPUT}")
  137. #message("################ _TMP_STR = ${CMAKE_MATCH_1} ##################")
  138. if(NOT "${CMAKE_MATCH_1}" STREQUAL "")
  139. string(STRIP "${CMAKE_MATCH_1}" _TMP_STR)
  140. set(${output} "${_TMP_STR}" PARENT_SCOPE)
  141. endif()
  142. endfunction()
  143. cmake_policy(POP)