CPackDeb: Use CPACK_PACKAGE_DESCRIPTION_FILE

Also, handle per-component description nicely.
This commit is contained in:
Alex Turbov 2019-07-11 19:31:59 +03:00
parent 53be31e19c
commit 33c7ea513d
13 changed files with 307 additions and 54 deletions

View File

@ -179,16 +179,24 @@ List of CPack DEB generator specific variables:
* Default : ``CPACK_PACKAGE_CONTACT``
.. variable:: CPACK_DEBIAN_PACKAGE_DESCRIPTION
CPACK_COMPONENT_<COMPONENT>_DESCRIPTION
CPACK_DEBIAN_<COMPONENT>_DESCRIPTION
The Debian package description
* Mandatory : YES
* Default :
- :variable:`CPACK_DEBIAN_PACKAGE_DESCRIPTION` if set or
- :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY`
- :variable:`CPACK_DEBIAN_<COMPONENT>_DESCRIPTION` (component
based installers only) if set, or :variable:`CPACK_DEBIAN_PACKAGE_DESCRIPTION` if set, or
- :variable:`CPACK_COMPONENT_<compName>_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_<COMPONENT>_PACKAGE_SECTION

View File

@ -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,27 +497,54 @@ 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()
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
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)
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CMAKE_PROJECT_HOMEPAGE_URL}")

View File

@ -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)

View File

@ -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")

View File

@ -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}

View File

@ -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")
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} != applications_description")
endif()
elseif(dpkg_package_name STREQUAL "mylib-headers")
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} != 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}

View File

@ -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)

View File

@ -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

View File

@ -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"
)

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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")