Commit 5fa625d6 authored by Kyle Edwards's avatar Kyle Edwards Committed by Kitware Robot

Merge topic 'cpack-DEB-use-CPACK_PACKAGE_DESCRIPTION_FILE'

33c7ea51 CPackDeb: Use `CPACK_PACKAGE_DESCRIPTION_FILE`
53be31e1 Refactor: Use `list` commands instead of old-way string ops
b2c67a77 Style: Remove spaces after command call and `(`
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !3541
parents 67e6b55c 33c7ea51
Pipeline #147140 passed with stage
in 0 seconds
......@@ -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
......
This diff is collapsed.
......@@ -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)
......@@ -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")
......@@ -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}
......
......@@ -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}
......
......@@ -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)
......@@ -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
......
......@@ -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"
)
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;
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;
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;
......@@ -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")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment