From b2c67a7703836a0015a7e4bf3837dbb613061a74 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Thu, 11 Jul 2019 02:08:10 +0300 Subject: Style: Remove spaces after command call and `(` --- Modules/Internal/CPack/CPackDeb.cmake | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Modules/Internal/CPack/CPackDeb.cmake b/Modules/Internal/CPack/CPackDeb.cmake index 7791822..51e505b 100644 --- a/Modules/Internal/CPack/CPackDeb.cmake +++ b/Modules/Internal/CPack/CPackDeb.cmake @@ -102,7 +102,7 @@ function(cpack_deb_prepare_package_vars) RESULT_VARIABLE FILE_RESULT_ OUTPUT_VARIABLE INSTALL_FILE_) if(NOT FILE_RESULT_ EQUAL 0) - message (FATAL_ERROR "CPackDeb: execution of command: '${FILE_EXECUTABLE} ./${FILE_}' failed with exit code: ${FILE_RESULT_}") + message(FATAL_ERROR "CPackDeb: execution of command: '${FILE_EXECUTABLE} ./${FILE_}' failed with exit code: ${FILE_RESULT_}") endif() list(APPEND CPACK_DEB_INSTALL_FILES "${INSTALL_FILE_}") endforeach() @@ -253,7 +253,7 @@ function(cpack_deb_prepare_package_vars) message( "CPackDeb Debug: dpkg-shlibdeps warnings \n${SHLIBDEPS_ERROR}") endif() if(NOT SHLIBDEPS_RESULT EQUAL 0) - message (FATAL_ERROR "CPackDeb: dpkg-shlibdeps: '${SHLIBDEPS_ERROR}';\n" + message(FATAL_ERROR "CPackDeb: dpkg-shlibdeps: '${SHLIBDEPS_ERROR}';\n" "executed command: '${SHLIBDEPS_EXECUTABLE} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES}';\n" "found files: '${INSTALL_FILE_}';\n" "files info: '${CPACK_DEB_INSTALL_FILES}';\n" @@ -403,7 +403,7 @@ function(cpack_deb_prepare_package_vars) if(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS) set(COMPONENT_DEPENDS "") - foreach (_PACK ${CPACK_COMPONENT_${_local_component_name}_DEPENDS}) + foreach(_PACK ${CPACK_COMPONENT_${_local_component_name}_DEPENDS}) get_component_package_name(_PACK_NAME "${_PACK}") if(COMPONENT_DEPENDS) set(COMPONENT_DEPENDS "${_PACK_NAME} (= ${CPACK_DEBIAN_PACKAGE_VERSION}), ${COMPONENT_DEPENDS}") @@ -425,11 +425,11 @@ function(cpack_deb_prepare_package_vars) # to the minimal dependency of the package # Append automatically discovered dependencies . if(NOT "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}" STREQUAL "") - if (CPACK_DEBIAN_PACKAGE_DEPENDS) + if(CPACK_DEBIAN_PACKAGE_DEPENDS) set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}") - else () + else() set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}") - endif () + endif() endif() if(NOT CPACK_DEBIAN_PACKAGE_DEPENDS) @@ -529,7 +529,7 @@ function(cpack_deb_prepare_package_vars) set(CPACK_DEBIAN_PACKAGE_SHLIBS_LIST "") - if (NOT CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY) + if(NOT CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY) set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY "=") endif() @@ -544,7 +544,7 @@ function(cpack_deb_prepare_package_vars) message(AUTHOR_WARNING "Shared library '${_FILE}' is missing soname or soversion. Library will not be added to DEBIAN/shlibs control file.") endif() endforeach() - if (CPACK_DEBIAN_PACKAGE_SHLIBS_LIST) + if(CPACK_DEBIAN_PACKAGE_SHLIBS_LIST) string(REPLACE ";" "\n" CPACK_DEBIAN_PACKAGE_SHLIBS_LIST "${CPACK_DEBIAN_PACKAGE_SHLIBS_LIST}") endif() else() -- cgit v0.12 From 53be31e19c0dc0f517825d1be056c55d7729a4b7 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Thu, 11 Jul 2019 02:26:48 +0300 Subject: Refactor: Use `list` commands instead of old-way string ops --- Modules/Internal/CPack/CPackDeb.cmake | 51 ++++++++++++++--------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/Modules/Internal/CPack/CPackDeb.cmake b/Modules/Internal/CPack/CPackDeb.cmake index 51e505b..e22f623 100644 --- a/Modules/Internal/CPack/CPackDeb.cmake +++ b/Modules/Internal/CPack/CPackDeb.cmake @@ -210,7 +210,7 @@ function(cpack_deb_prepare_package_vars) if(_TMP_VERSION MATCHES "dpkg-shlibdeps version ([0-9]+\\.[0-9]+\\.[0-9]+)") set(SHLIBDEPS_EXECUTABLE_VERSION "${CMAKE_MATCH_1}") else() - set(SHLIBDEPS_EXECUTABLE_VERSION "") + unset(SHLIBDEPS_EXECUTABLE_VERSION) endif() if(CPACK_DEBIAN_PACKAGE_DEBUG) @@ -388,7 +388,7 @@ function(cpack_deb_prepare_package_vars) # if per-component variable, overrides the global CPACK_DEBIAN_PACKAGE_${variable_type_} # automatic dependency discovery will be performed afterwards. if(CPACK_DEB_PACKAGE_COMPONENT) - foreach(value_type_ DEPENDS RECOMMENDS SUGGESTS PREDEPENDS ENHANCES BREAKS CONFLICTS PROVIDES REPLACES SOURCE SECTION PRIORITY NAME) + foreach(value_type_ IN ITEMS DEPENDS RECOMMENDS SUGGESTS PREDEPENDS ENHANCES BREAKS CONFLICTS PROVIDES REPLACES SOURCE SECTION PRIORITY NAME) set(_component_var "CPACK_DEBIAN_${_local_component_name}_PACKAGE_${value_type_}") # if set, overrides the global variable @@ -402,21 +402,15 @@ function(cpack_deb_prepare_package_vars) endforeach() if(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS) - set(COMPONENT_DEPENDS "") - foreach(_PACK ${CPACK_COMPONENT_${_local_component_name}_DEPENDS}) + unset(COMPONENT_DEPENDS) + foreach(_PACK IN LISTS CPACK_COMPONENT_${_local_component_name}_DEPENDS) get_component_package_name(_PACK_NAME "${_PACK}") - if(COMPONENT_DEPENDS) - set(COMPONENT_DEPENDS "${_PACK_NAME} (= ${CPACK_DEBIAN_PACKAGE_VERSION}), ${COMPONENT_DEPENDS}") - else() - set(COMPONENT_DEPENDS "${_PACK_NAME} (= ${CPACK_DEBIAN_PACKAGE_VERSION})") - endif() + list(PREPEND COMPONENT_DEPENDS "${_PACK_NAME} (= ${CPACK_DEBIAN_PACKAGE_VERSION})") endforeach() + list(JOIN COMPONENT_DEPENDS ", " COMPONENT_DEPENDS) if(COMPONENT_DEPENDS) - if(CPACK_DEBIAN_PACKAGE_DEPENDS) - set(CPACK_DEBIAN_PACKAGE_DEPENDS "${COMPONENT_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_DEPENDS}") - else() - set(CPACK_DEBIAN_PACKAGE_DEPENDS "${COMPONENT_DEPENDS}") - endif() + list(PREPEND CPACK_DEBIAN_PACKAGE_DEPENDS ${COMPONENT_DEPENDS}) + list(JOIN CPACK_DEBIAN_PACKAGE_DEPENDS ", " CPACK_DEBIAN_PACKAGE_DEPENDS) endif() endif() endif() @@ -424,12 +418,9 @@ function(cpack_deb_prepare_package_vars) # at this point, the CPACK_DEBIAN_PACKAGE_DEPENDS is properly set # to the minimal dependency of the package # Append automatically discovered dependencies . - if(NOT "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}" STREQUAL "") - if(CPACK_DEBIAN_PACKAGE_DEPENDS) - set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}") - else() - set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}") - endif() + if(CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS) + list(APPEND CPACK_DEBIAN_PACKAGE_DEPENDS ${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}) + list(JOIN CPACK_DEBIAN_PACKAGE_DEPENDS ", " CPACK_DEBIAN_PACKAGE_DEPENDS) endif() if(NOT CPACK_DEBIAN_PACKAGE_DEPENDS) @@ -519,7 +510,7 @@ function(cpack_deb_prepare_package_vars) # Are we packaging components ? if(CPACK_DEB_PACKAGE_COMPONENT) # override values with per component version if set - foreach(VAR_NAME_ "PACKAGE_CONTROL_EXTRA" "PACKAGE_CONTROL_STRICT_PERMISSION") + foreach(VAR_NAME_ IN ITEMS PACKAGE_CONTROL_EXTRA PACKAGE_CONTROL_STRICT_PERMISSION) if(CPACK_DEBIAN_${_local_component_name}_${VAR_NAME_}) set(CPACK_DEBIAN_${VAR_NAME_} "${CPACK_DEBIAN_${_local_component_name}_${VAR_NAME_}}") endif() @@ -527,12 +518,12 @@ function(cpack_deb_prepare_package_vars) get_component_package_name(CPACK_DEBIAN_PACKAGE_NAME ${_local_component_name}) endif() - set(CPACK_DEBIAN_PACKAGE_SHLIBS_LIST "") - if(NOT CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY) set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY "=") endif() + unset(CPACK_DEBIAN_PACKAGE_SHLIBS_LIST) + if(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS) if(READELF_EXECUTABLE) foreach(_FILE IN LISTS CPACK_DEB_SHARED_OBJECT_FILES) @@ -544,9 +535,7 @@ function(cpack_deb_prepare_package_vars) message(AUTHOR_WARNING "Shared library '${_FILE}' is missing soname or soversion. Library will not be added to DEBIAN/shlibs control file.") endif() endforeach() - if(CPACK_DEBIAN_PACKAGE_SHLIBS_LIST) - string(REPLACE ";" "\n" CPACK_DEBIAN_PACKAGE_SHLIBS_LIST "${CPACK_DEBIAN_PACKAGE_SHLIBS_LIST}") - endif() + list(JOIN CPACK_DEBIAN_PACKAGE_SHLIBS_LIST "\n" CPACK_DEBIAN_PACKAGE_SHLIBS_LIST) else() message(FATAL_ERROR "Readelf utility is not available. CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS option is not available.") endif() @@ -554,7 +543,7 @@ function(cpack_deb_prepare_package_vars) # add ldconfig call in default postrm and postint set(CPACK_ADD_LDCONFIG_CALL 0) - foreach(_FILE ${CPACK_DEB_SHARED_OBJECT_FILES}) + foreach(_FILE IN LISTS CPACK_DEB_SHARED_OBJECT_FILES) get_filename_component(_DIR ${_FILE} DIRECTORY) # all files in CPACK_DEB_SHARED_OBJECT_FILES have dot at the beginning if(_DIR STREQUAL "./lib" OR _DIR STREQUAL "./usr/lib") @@ -565,12 +554,12 @@ function(cpack_deb_prepare_package_vars) if(CPACK_ADD_LDCONFIG_CALL) set(CPACK_DEBIAN_GENERATE_POSTINST 1) set(CPACK_DEBIAN_GENERATE_POSTRM 1) - foreach(f ${PACKAGE_CONTROL_EXTRA}) + foreach(f IN LISTS PACKAGE_CONTROL_EXTRA) get_filename_component(n "${f}" NAME) - if("${n}" STREQUAL "postinst") + if(n STREQUAL "postinst") set(CPACK_DEBIAN_GENERATE_POSTINST 0) endif() - if("${n}" STREQUAL "postrm") + if(n STREQUAL "postrm") set(CPACK_DEBIAN_GENERATE_POSTRM 0) endif() endforeach() @@ -671,7 +660,7 @@ function(cpack_deb_prepare_package_vars) if(BUILD_IDS) set(GEN_DBGSYMDIR "${DBGSYMDIR}" PARENT_SCOPE) set(GEN_CPACK_DBGSYM_OUTPUT_FILE_NAME "${CPACK_DBGSYM_OUTPUT_FILE_NAME}" PARENT_SCOPE) - string(REPLACE ";" " " BUILD_IDS "${BUILD_IDS}") + list(JOIN BUILD_IDS " " BUILD_IDS) set(GEN_BUILD_IDS "${BUILD_IDS}" PARENT_SCOPE) endif() endfunction() -- cgit v0.12 From 33c7ea513dc8a7e1322c5c37003c7c515bd8ad99 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Thu, 11 Jul 2019 19:31:59 +0300 Subject: CPackDeb: Use `CPACK_PACKAGE_DESCRIPTION_FILE` Also, handle per-component description nicely. --- Help/cpack_gen/deb.rst | 14 ++- Modules/Internal/CPack/CPackDeb.cmake | 120 ++++++++++++++++++--- ...LibCPackConfig-components-description1.cmake.in | 7 +- ...LibCPackConfig-components-description2.cmake.in | 10 +- ...CPackVerifyResult-components-description1.cmake | 18 ++-- ...CPackVerifyResult-components-description2.cmake | 20 ++-- .../CPackComponentsDEB/RunCPackVerifyResult.cmake | 25 +++++ Tests/RunCMake/CMakeLists.txt | 1 + Tests/RunCMake/CPack/RunCMakeTest.cmake | 7 ++ .../tests/DEB_DESCRIPTION/ExpectedFiles.cmake | 16 +++ .../CPack/tests/DEB_DESCRIPTION/VerifyResult.cmake | 65 +++++++++++ .../CPack/tests/DEB_DESCRIPTION/test.cmake | 45 ++++++++ .../tests/PER_COMPONENT_FIELDS/VerifyResult.cmake | 9 +- 13 files changed, 305 insertions(+), 52 deletions(-) create mode 100644 Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/ExpectedFiles.cmake create mode 100644 Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/VerifyResult.cmake create mode 100644 Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/test.cmake diff --git a/Help/cpack_gen/deb.rst b/Help/cpack_gen/deb.rst index 23f0515..db71c87 100644 --- a/Help/cpack_gen/deb.rst +++ b/Help/cpack_gen/deb.rst @@ -179,16 +179,24 @@ List of CPack DEB generator specific variables: * Default : ``CPACK_PACKAGE_CONTACT`` .. variable:: CPACK_DEBIAN_PACKAGE_DESCRIPTION - CPACK_COMPONENT__DESCRIPTION + CPACK_DEBIAN__DESCRIPTION The Debian package description * Mandatory : YES * Default : - - :variable:`CPACK_DEBIAN_PACKAGE_DESCRIPTION` if set or - - :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY` + - :variable:`CPACK_DEBIAN__DESCRIPTION` (component + based installers only) if set, or :variable:`CPACK_DEBIAN_PACKAGE_DESCRIPTION` if set, or + - :variable:`CPACK_COMPONENT__DESCRIPTION` (component + based installers only) if set, or :variable:`CPACK_PACKAGE_DESCRIPTION` if set, or + - content of the file specified in :variable:`CPACK_PACKAGE_DESCRIPTION_FILE` if set + If after that description is not set, :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY` going to be + used if set. Otherwise, :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY` will be added as the first + line of description as defined in `Debian Policy Manual`_. + +.. _Debian Policy Manual: https://www.debian.org/doc/debian-policy/ch-controlfields.html#description .. variable:: CPACK_DEBIAN_PACKAGE_SECTION CPACK_DEBIAN__PACKAGE_SECTION diff --git a/Modules/Internal/CPack/CPackDeb.cmake b/Modules/Internal/CPack/CPackDeb.cmake index e22f623..ad8e078 100644 --- a/Modules/Internal/CPack/CPackDeb.cmake +++ b/Modules/Internal/CPack/CPackDeb.cmake @@ -56,6 +56,67 @@ function(extract_so_info shared_object libname version) endif() endfunction() +function(cpack_deb_check_description SUMMARY LINES RESULT_VARIABLE) + set(_result TRUE) + + # Get the summary line + if(NOT SUMMARY MATCHES "^[^\\s].*$") + set(_result FALSE) + set(${RESULT_VARIABLE} ${_result} PARENT_SCOPE) + return() + endif() + + foreach(_line IN LISTS LINES) + if(NOT _line MATCHES "^ +[^ ]+.*$") + set(_result FALSE) + break() + endif() + endforeach() + + set(${RESULT_VARIABLE} ${_result} PARENT_SCOPE) +endfunction() + +function(cpack_deb_format_package_description TEXT OUTPUT_VAR) + # Turn the possible multi-line string into a list + string(UUID uuid NAMESPACE 00000000-0000-0000-0000-000000000000 TYPE SHA1) + string(REPLACE ";" "${uuid}" _text "${TEXT}") + string(REPLACE "\n" ";" _lines "${_text}") + list(POP_FRONT _lines _summary) + + # Check if reformatting required + cpack_deb_check_description("${_summary}" "${_lines}" _result) + if(_result) + # Ok, no formatting required + set(${OUTPUT_VAR} "${TEXT}" PARENT_SCOPE) + return() + endif() + + # Format the summary line + string(STRIP "${_summary}" _summary) + + # Make sure the rest formatted properly + set(_result) + foreach(_line IN LISTS _lines) + string(STRIP "${_line}" _line_strip) + if(NOT _line_strip) + # Replace empty lines w/ a _single full stop character_ + set(_line " .") + else() + # Prepend the normal lines w/ a single space. + # If the line already starts w/ at least one space, + # it'll become _verbatim_ (assuming it supposed to be + # verbatim in the original text). + string(PREPEND _line " ") + endif() + list(APPEND _result "${_line}") + endforeach() + + list(PREPEND _result "${_summary}") + list(JOIN _result "\n" _result) + string(REPLACE "${uuid}" ";" _result "${_result}") + set(${OUTPUT_VAR} "${_result}" PARENT_SCOPE) +endfunction() + function(cpack_deb_prepare_package_vars) # CPACK_DEBIAN_PACKAGE_SHLIBDEPS # If specify OFF, only user depends are used @@ -436,26 +497,53 @@ function(cpack_deb_prepare_package_vars) endif() # Description: (mandatory) - if(NOT CPACK_DEB_PACKAGE_COMPONENT) - if(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION) - if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY) - message(FATAL_ERROR "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION") - endif() - set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) - endif() + # Try package description first + if(CPACK_DEB_PACKAGE_COMPONENT) + cpack_deb_variable_fallback("CPACK_DEBIAN_PACKAGE_DESCRIPTION" + "CPACK_DEBIAN_${_local_component_name}_DESCRIPTION" + "CPACK_COMPONENT_${_local_component_name}_DESCRIPTION") else() - set(component_description_var CPACK_COMPONENT_${_local_component_name}_DESCRIPTION) - - # component description overrides package description - if(${component_description_var}) - set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${${component_description_var}}) - elseif(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION) - if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY) - message(FATAL_ERROR "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION or ${component_description_var}") - endif() + cpack_deb_variable_fallback("CPACK_DEBIAN_PACKAGE_DESCRIPTION" + "CPACK_DEBIAN_PACKAGE_DESCRIPTION" + "CPACK_PACKAGE_DESCRIPTION") + endif() + + # Still no description? ... and description file has set ... + if(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION AND CPACK_PACKAGE_DESCRIPTION_FILE) + # Read `CPACK_PACKAGE_DESCRIPTION_FILE` then... + file(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_DEBIAN_PACKAGE_DESCRIPTION) + endif() + + # Still no description? #2 + if(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION) + # Try to get `CPACK_PACKAGE_DESCRIPTION_SUMMARY` as the last hope + if(CPACK_PACKAGE_DESCRIPTION_SUMMARY) set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) + else() + # Giving up! Report an error... + set(_description_failure_message + "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION") + if(CPACK_DEB_PACKAGE_COMPONENT) + string(APPEND _description_failure_message + " or CPACK_DEBIAN_${_local_component_name}_DESCRIPTION") + endif() + message(FATAL_ERROR _description_failure_message) endif() + + # Ok, description has set. According to the `Debian Policy Manual`_ the frist + # line is a pacakge summary. Try to get it as well... + # See also: https://www.debian.org/doc/debian-policy/ch-controlfields.html#description + elseif(CPACK_PACKAGE_DESCRIPTION_SUMMARY) + # Merge summary w/ the detailed description + string(PREPEND CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}\n") endif() + # assert(CPACK_DEBIAN_PACKAGE_DESCRIPTION) + + # Make sure description is properly formatted + cpack_deb_format_package_description( + "${CPACK_DEBIAN_PACKAGE_DESCRIPTION}" + CPACK_DEBIAN_PACKAGE_DESCRIPTION + ) # Homepage: (optional) if(NOT CPACK_DEBIAN_PACKAGE_HOMEPAGE AND CMAKE_PROJECT_HOMEPAGE_URL) diff --git a/Tests/CPackComponentsDEB/MyLibCPackConfig-components-description1.cmake.in b/Tests/CPackComponentsDEB/MyLibCPackConfig-components-description1.cmake.in index 74d816c..67b108b 100644 --- a/Tests/CPackComponentsDEB/MyLibCPackConfig-components-description1.cmake.in +++ b/Tests/CPackComponentsDEB/MyLibCPackConfig-components-description1.cmake.in @@ -15,8 +15,9 @@ set(CPACK_COMPONENTS_IGNORE_GROUPS 1) #set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1) # overriding previous descriptions -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "main description") -set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION "applications_description") -set(CPACK_COMPONENT_HEADERS_DESCRIPTION "headers_description") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "main description") # This become a summary line (the first one) of all descriptions +set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION "applications_description") +set(CPACK_COMPONENT_HEADERS_DESCRIPTION "headers_description") # libraries does not have any description and should inherit from CPACK_PACKAGE_DESCRIPTION_SUMMARY +# plus content of the `CPACK_PACKAGE_DESCRIPTION_FILE`. unset(CPACK_COMPONENT_LIBRARIES_DESCRIPTION) diff --git a/Tests/CPackComponentsDEB/MyLibCPackConfig-components-description2.cmake.in b/Tests/CPackComponentsDEB/MyLibCPackConfig-components-description2.cmake.in index cda79bc..d877325 100644 --- a/Tests/CPackComponentsDEB/MyLibCPackConfig-components-description2.cmake.in +++ b/Tests/CPackComponentsDEB/MyLibCPackConfig-components-description2.cmake.in @@ -15,12 +15,12 @@ set(CPACK_COMPONENTS_IGNORE_GROUPS 1) #set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1) # overriding previous descriptions -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "main description 2") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "main description 2") -# Components do not have any description +# Components do not have any description. +# So, content of `CPACK_PACKAGE_DESCRIPTION_FILE` gonna used +# after summary line. unset(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION) unset(CPACK_COMPONENT_HEADERS_DESCRIPTION) -unset(CPACK_COMPONENT_LIBRARIES_DESCRIPTION) - -set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION "library description") +set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION "library description") diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description1.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description1.cmake index f74137c..86a74b2 100644 --- a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description1.cmake +++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description1.cmake @@ -48,26 +48,26 @@ if(DPKGDEB_EXECUTABLE) DPKGDEB_OUTPUT "${dpkg_output}" METAENTRY "Package:") - dpkgdeb_return_specific_metaentry(dpkg_description - DPKGDEB_OUTPUT "${dpkg_output}" - METAENTRY "Description:") + get_package_description("${dpkg_output}" dpkg_description) message(STATUS "package='${dpkg_package_name}', description='${dpkg_description}'") if(dpkg_package_name STREQUAL "mylib-applications") - if(NOT "${dpkg_description}" STREQUAL "applications_description") + set(expected_description "main description\n applications_description") + if(NOT dpkg_description STREQUAL expected_description) set(dpkgdeb_output_errors_all ${dpkgdeb_output_errors_all} - "dpkg-deb: ${_f}: Incorrect description for package ${dpkg_package_name}: ${dpkg_description} != applications_description") + "dpkg-deb: ${_f}: Incorrect description for package ${dpkg_package_name}: `${dpkg_description}` != `${expected_description}`") endif() elseif(dpkg_package_name STREQUAL "mylib-headers") - if(NOT dpkg_description STREQUAL "headers_description") + set(expected_description "main description\n headers_description") + if(NOT dpkg_description STREQUAL expected_description) set(dpkgdeb_output_errors_all ${dpkgdeb_output_errors_all} - "dpkg-deb: ${_f}: Incorrect description for package ${dpkg_package_name}: ${dpkg_description} != headers_description") + "dpkg-deb: ${_f}: Incorrect description for package ${dpkg_package_name}: `${dpkg_description}` != `${expected_description}`") endif() elseif(dpkg_package_name STREQUAL "mylib-libraries") - if(NOT dpkg_description STREQUAL "main description") + if(NOT dpkg_description MATCHES "main description\n.*") set(dpkgdeb_output_errors_all ${dpkgdeb_output_errors_all} - "dpkg-deb: ${_f}: Incorrect description for package ${dpkg_package_name}: ${dpkg_description} != 'main description'") + "dpkg-deb: ${_f}: Incorrect description for package ${dpkg_package_name}: `${dpkg_description}` =~ `main description.*`") endif() else() set(dpkgdeb_output_errors_all ${dpkgdeb_output_errors_all} diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description2.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description2.cmake index 241dda5..d53c73d 100644 --- a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description2.cmake +++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description2.cmake @@ -48,26 +48,20 @@ if(DPKGDEB_EXECUTABLE) DPKGDEB_OUTPUT "${dpkg_output}" METAENTRY "Package:") - dpkgdeb_return_specific_metaentry(dpkg_description - DPKGDEB_OUTPUT "${dpkg_output}" - METAENTRY "Description:") + get_package_description("${dpkg_output}" dpkg_description) message(STATUS "package='${dpkg_package_name}', description='${dpkg_description}'") - if(dpkg_package_name STREQUAL "mylib-applications") - if(NOT dpkg_description STREQUAL "main description 2") - set(dpkgdeb_output_errors_all ${dpkgdeb_output_errors_all} - "dpkg-deb: ${_f}: Incorrect description for package ${dpkg_package_name}: ${dpkg_description} != applications_description") - endif() - elseif(dpkg_package_name STREQUAL "mylib-headers") - if(NOT dpkg_description STREQUAL "main description 2") + if(dpkg_package_name STREQUAL "mylib-applications" OR dpkg_package_name STREQUAL "mylib-headers") + if(NOT dpkg_description MATCHES "main description 2\n.*") set(dpkgdeb_output_errors_all ${dpkgdeb_output_errors_all} - "dpkg-deb: ${_f}: Incorrect description for package ${dpkg_package_name}: ${dpkg_description} != headers_description") + "dpkg-deb: ${_f}: Incorrect description for package ${dpkg_package_name}: `${dpkg_description}` =~ `main description 2`") endif() elseif(dpkg_package_name STREQUAL "mylib-libraries") - if(NOT dpkg_description STREQUAL "library description") + set(expected_description "main description 2\n library description") + if(NOT dpkg_description STREQUAL expected_description) set(dpkgdeb_output_errors_all ${dpkgdeb_output_errors_all} - "dpkg-deb: ${_f}: Incorrect description for package ${dpkg_package_name}: ${dpkg_description} != 'main description'") + "dpkg-deb: ${_f}: Incorrect description for package ${dpkg_package_name}: `${dpkg_description}` != `${expected_description}`") endif() else() set(dpkgdeb_output_errors_all ${dpkgdeb_output_errors_all} diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake index 2093e7e..b172da2 100644 --- a/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake +++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake @@ -200,4 +200,29 @@ function(dpkgdeb_return_specific_metaentry output) endif() endfunction() +function(get_package_description DPKG_OUTPUT RESULT_VAR) + string(UUID uuid NAMESPACE 00000000-0000-0000-0000-000000000000 TYPE SHA1) + string(REPLACE ";" "${uuid}" DPKG_OUTPUT "${DPKG_OUTPUT}") + string(REPLACE "\n" ";" DPKG_OUTPUT "${DPKG_OUTPUT}") + + unset(_actual_description) + set(_parse_description FALSE) + foreach(_line IN LISTS DPKG_OUTPUT) + if(_line MATCHES " Description:.*") + set(_parse_description TRUE) + string(REPLACE " Description: " "" _line "${_line}") + list(APPEND _actual_description "${_line}") + elseif(_parse_description) + if(_line MATCHES " [A-Z][A-Za-z\-]+: .*") + set(_parse_description FALSE) + else() + list(APPEND _actual_description "${_line}") + endif() + endif() + endforeach() + list(JOIN _actual_description "\n" _actual_description) + + set(${RESULT_VAR} "${_actual_description}" PARENT_SCOPE) +endfunction() + cmake_policy(POP) diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 8fd5234..13fbecf 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -510,6 +510,7 @@ set(cpack_tests DEB.TIMESTAMPS DEB.MD5SUMS DEB.DEB_PACKAGE_VERSION_BACK_COMPATIBILITY + DEB.DEB_DESCRIPTION RPM.CUSTOM_BINARY_SPEC_FILE RPM.CUSTOM_NAMES diff --git a/Tests/RunCMake/CPack/RunCMakeTest.cmake b/Tests/RunCMake/CPack/RunCMakeTest.cmake index 8e98961..b0b7a99 100644 --- a/Tests/RunCMake/CPack/RunCMakeTest.cmake +++ b/Tests/RunCMake/CPack/RunCMakeTest.cmake @@ -39,3 +39,10 @@ run_cpack_test_subtests(EXTERNAL "none;good;good_multi;bad_major;bad_minor;inval if(RunCMake_GENERATOR MATCHES "Visual Studio|Xcode") run_cpack_test(CPACK_INSTALL_CMAKE_CONFIGURATIONS "ZIP" false "MONOLITHIC") endif() +run_cpack_test_subtests( + DEB_DESCRIPTION + "CPACK_DEBIAN_PACKAGE_DESCRIPTION;CPACK_PACKAGE_DESCRIPTION;CPACK_PACKAGE_DESCRIPTION_FILE" + "DEB.DEB_DESCRIPTION" + false + "MONOLITHIC;COMPONENT" +) diff --git a/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/ExpectedFiles.cmake new file mode 100644 index 0000000..39f18a3 --- /dev/null +++ b/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/ExpectedFiles.cmake @@ -0,0 +1,16 @@ +set(EXPECTED_FILES_COUNT_MONOLITHIC "1") +set(EXPECTED_FILES_COUNT_COMPONENT "2") +set(EXPECTED_FILES_COUNT "${EXPECTED_FILES_COUNT_${PACKAGING_TYPE}}") + +if(PACKAGING_TYPE STREQUAL "COMPONENT") + set(EXPECTED_FILE_1 "deb_description-0.1.1-*-satu.deb") + set(EXPECTED_FILE_2 "deb_description-0.1.1-*-dua.deb") + set(EXPECTED_FILE_CONTENT_1_LIST "/satu;/satu/CMakeLists.txt") + set(EXPECTED_FILE_CONTENT_2_LIST "/dua;/dua/CMakeLists.txt") + +elseif(PACKAGING_TYPE STREQUAL "MONOLITHIC") + set(EXPECTED_FILE_CONTENT_1_LIST "/dua;/dua/CMakeLists.txt;/satu;/satu/CMakeLists.txt") + +endif() + +# kate: indent-width 2; diff --git a/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/VerifyResult.cmake new file mode 100644 index 0000000..e9ac13a --- /dev/null +++ b/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/VerifyResult.cmake @@ -0,0 +1,65 @@ +function(checkPackageDescription FILE EXPECTED_DESCRIPTION) + getPackageInfo("${FILE}" "_file_info") + string(UUID uuid NAMESPACE 00000000-0000-0000-0000-000000000000 TYPE SHA1) + string(REPLACE ";" "${uuid}" _file_info "${_file_info}") + string(REPLACE ";" "${uuid}" EXPECTED_DESCRIPTION "${EXPECTED_DESCRIPTION}") + string(REPLACE "\n" ";" _file_info "${_file_info}") + + set(_actual_description) + set(_parse_description FALSE) + foreach(_line IN LISTS _file_info) + if(_line MATCHES " Description:.*") + set(_parse_description TRUE) + list(APPEND _actual_description "${_line}") + elseif(_parse_description) + if(_line MATCHES " [A-Z][A-Za-z\-]+: .*") + set(_parse_description FALSE) + else() + list(APPEND _actual_description "${_line}") + endif() + endif() + endforeach() + list(JOIN _actual_description "\n" _actual_description) + + if(NOT _actual_description STREQUAL EXPECTED_DESCRIPTION) + set(_error "---[BEGIN Expected description]---\n${EXPECTED_DESCRIPTION}---[END Expected description]---\n") + string(APPEND _error "---[BEGIN Actual description]---\n${_actual_description}---[END Actual description]---\n") + string(REPLACE "${uuid}" ";" _error "${_error}") + message(FATAL_ERROR "${_error}") + endif() +endfunction() + +# ALERT The output of `dpkg -I *.deb` indented by one space +set(_expected_description [[ Description: This is the summary line + This is the Debian package multiline description. + . + It must be formatted properly! Otherwise, the result `*.deb` + package become broken and cant be installed! + . + It may contains `;` characters (even like this `;;;;`). Example: + . + - one; + - two; + - three; + . + ... and they are properly handled by the automatic description formatter! + . + See also: https://www.debian.org/doc/debian-policy/ch-controlfields.html#description]]) + +# ATTENTION The code in `cmCPackGenerator.cxx` to read `CPACK_PACKAGE_DESCRIPTION_FILE` +# has a BUG: it appends the `\n` character to every line of the +# input, even if there was no EOL (e.g. at the last line of the file). +# That is WHY for this sub-test the one more pre-formatted "empty" +# line required! +# NOTE For component based installers content of the file gonna read by +# `CPackDeb` module and the `file(READ...)` command so no the mentioned +# workaround required! +if(RunCMake_SUBTEST_SUFFIX STREQUAL "CPACK_PACKAGE_DESCRIPTION_FILE" AND PACKAGING_TYPE STREQUAL "MONOLITHIC") + string(APPEND _expected_description "\n ." ) +endif() + +foreach(_file_no RANGE 1 ${EXPECTED_FILES_COUNT}) + checkPackageDescription("${FOUND_FILE_${_file_no}}" "${_expected_description}") +endforeach() + +# kate: indent-width 2; diff --git a/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/test.cmake b/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/test.cmake new file mode 100644 index 0000000..ce3f651 --- /dev/null +++ b/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/test.cmake @@ -0,0 +1,45 @@ +install(FILES CMakeLists.txt DESTINATION satu COMPONENT satu) +install(FILES CMakeLists.txt DESTINATION dua COMPONENT dua) + +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "This is the summary line") +set(_description [[This is the Debian package multiline description. + +It must be formatted properly! Otherwise, the result `*.deb` +package become broken and cant be installed! + +It may contains `;` characters (even like this `;;;;`). Example: + + - one; + - two; + - three; + +... and they are properly handled by the automatic description formatter! + +See also: https://www.debian.org/doc/debian-policy/ch-controlfields.html#description]]) + +if(RunCMake_SUBTEST_SUFFIX STREQUAL "CPACK_DEBIAN_PACKAGE_DESCRIPTION") + if(PACKAGING_TYPE STREQUAL "COMPONENT") + set(CPACK_DEBIAN_SATU_DESCRIPTION "${_description}") + set(CPACK_DEBIAN_DUA_DESCRIPTION "${_description}") + else() + set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "${_description}") + endif() + +elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "CPACK_PACKAGE_DESCRIPTION") + # NOTE Documented fallback variable + if(PACKAGING_TYPE STREQUAL "COMPONENT") + set(CPACK_COMPONENT_SATU_DESCRIPTION "${_description}") + set(CPACK_COMPONENT_DUA_DESCRIPTION "${_description}") + else() + set(CPACK_PACKAGE_DESCRIPTION "${_description}") + endif() + +elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "CPACK_PACKAGE_DESCRIPTION_FILE") + # NOTE Getting the description from the file + set(_file "${CMAKE_CURRENT_BINARY_DIR}/description.txt") + file(WRITE "${_file}" "${_description}") + set(CPACK_PACKAGE_DESCRIPTION_FILE "${_file}") + +endif() + +# kate: indent-width 2; diff --git a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake index b4bdb61..c47b40e 100644 --- a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake +++ b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake @@ -8,6 +8,9 @@ endfunction() if(GENERATOR_TYPE STREQUAL "DEB") set(name_ "Package") set(group_ "Section") + # NOTE For a Debian package the first line of the `Description` + # field is generated by CMake and gonna be ignored + set(ignore_rest_cond_ ".*\n") elseif(GENERATOR_TYPE STREQUAL "RPM") set(name_ "Name") set(group_ "Group") @@ -33,6 +36,6 @@ if(GENERATOR_TYPE STREQUAL "RPM") endif() # check package description -checkPackageInfo_("description" "${FOUND_FILE_1}" ".*Description${whitespaces_}:${whitespaces_}Description for pkg_1") -checkPackageInfo_("description" "${FOUND_FILE_2}" ".*Description${whitespaces_}:${whitespaces_}Description for pkg_2") -checkPackageInfo_("description" "${FOUND_FILE_3}" ".*Description${whitespaces_}:${whitespaces_}Description for pkg_3") +checkPackageInfo_("description" "${FOUND_FILE_1}" ".*Description${whitespaces_}:${ignore_rest_cond_}${whitespaces_}Description for pkg_1") +checkPackageInfo_("description" "${FOUND_FILE_2}" ".*Description${whitespaces_}:${ignore_rest_cond_}${whitespaces_}Description for pkg_2") +checkPackageInfo_("description" "${FOUND_FILE_3}" ".*Description${whitespaces_}:${ignore_rest_cond_}${whitespaces_}Description for pkg_3") -- cgit v0.12