CPack/RPM: Add support for all weak dependency tags

Co-authored-by: Brad King <brad.king@kitware.com>
This commit is contained in:
Balazs Kosaras 2025-02-27 11:20:13 -05:00 committed by Brad King
parent 847f515934
commit 14baa13ab8
20 changed files with 255 additions and 1 deletions

View File

@ -439,6 +439,51 @@ List of CPack RPM generator specific variables:
variable. Note that you must enclose the entire value between quotes when
setting this variable.
.. variable:: CPACK_RPM_PACKAGE_RECOMMENDS
CPACK_RPM_<component>_PACKAGE_RECOMMENDS
.. versionadded:: 4.1
RPM spec recommends field.
:Mandatory: No
:Default:
May be used to set weak RPM dependencies (recommends). If ``rpmbuild`` doesn't
support the ``Recommends`` tag, CPack will emit a warning and ignore this
variable. Note that you must enclose the entire value between quotes when
setting this variable.
.. variable:: CPACK_RPM_PACKAGE_SUPPLEMENTS
CPACK_RPM_<component>_PACKAGE_SUPPLEMENTS
.. versionadded:: 4.1
RPM spec supplements field.
:Mandatory: No
:Default:
May be used to set weak RPM dependencies (supplements). If ``rpmbuild`` doesn't
support the ``Supplements`` tag, CPack will emit a warning and ignore this
variable. Note that you must enclose the entire value between quotes when
setting this variable.
.. variable:: CPACK_RPM_PACKAGE_ENHANCES
CPACK_RPM_<component>_PACKAGE_ENHANCES
.. versionadded:: 4.1
RPM spec enhances field.
:Mandatory: No
:Default:
May be used to set weak RPM dependencies (enhances). If ``rpmbuild`` doesn't
support the ``Enhances`` tag, CPack will emit a warning and ignore this
variable. Note that you must enclose the entire value between quotes when
setting this variable.
.. variable:: CPACK_RPM_PACKAGE_PROVIDES
CPACK_RPM_<component>_PACKAGE_PROVIDES

View File

@ -0,0 +1,8 @@
cpack-rpm-weak-deps-tags
------------------------
* The :cpack_gen:`CPack RPM Generator` gained
:variable:`CPACK_RPM_PACKAGE_ENHANCES`,
:variable:`CPACK_RPM_PACKAGE_RECOMMENDS`, and
:variable:`CPACK_RPM_PACKAGE_SUPPLEMENTS`
variables to specify the corresponding RPM spec fields.

View File

@ -1112,7 +1112,7 @@ function(cpack_rpm_generate_package)
# There may be some COMPONENT specific variables as well
# If component specific var is not provided we use the global one
# for each component
foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLICTS AUTOPROV AUTOREQ AUTOREQPROV REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN)
foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS RECOMMENDS SUPPLEMENTS ENHANCES PROVIDES OBSOLETES PREFIX CONFLICTS AUTOPROV AUTOREQ AUTOREQPROV REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN)
if(CPACK_RPM_PACKAGE_DEBUG)
message("CPackRPM:Debug: processing ${_RPM_SPEC_HEADER}")
@ -1730,7 +1730,10 @@ Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
\@TMP_RPM_PROVIDES\@
\@TMP_RPM_OBSOLETES\@
\@TMP_RPM_CONFLICTS\@
\@TMP_RPM_RECOMMENDS\@
\@TMP_RPM_SUGGESTS\@
\@TMP_RPM_SUPPLEMENTS\@
\@TMP_RPM_ENHANCES\@
\@TMP_RPM_AUTOPROV\@
\@TMP_RPM_AUTOREQ\@
\@TMP_RPM_AUTOREQPROV\@
@ -1799,7 +1802,10 @@ Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@
\@TMP_RPM_PROVIDES\@
\@TMP_RPM_OBSOLETES\@
\@TMP_RPM_CONFLICTS\@
\@TMP_RPM_RECOMMENDS\@
\@TMP_RPM_SUGGESTS\@
\@TMP_RPM_SUPPLEMENTS\@
\@TMP_RPM_ENHANCES\@
\@TMP_RPM_AUTOPROV\@
\@TMP_RPM_AUTOREQ\@
\@TMP_RPM_AUTOREQPROV\@

View File

@ -1195,6 +1195,9 @@ set(cpack_tests
RPM.EXTRA_SLASH_IN_PATH
RPM.SOURCE_PACKAGE
RPM.SUGGESTS
RPM.ENHANCES
RPM.RECOMMENDS
RPM.SUPPLEMENTS
RPM.SYMLINKS
RPM.USER_FILELIST
RPM.PROJECT_META

View File

@ -54,6 +54,9 @@ if(NOT BRPALT)
run_cpack_source_test(SOURCE_PACKAGE "RPM.SOURCE_PACKAGE")
endif()
run_cpack_test(SUGGESTS "RPM.SUGGESTS" false "MONOLITHIC")
run_cpack_test(ENHANCES "RPM.ENHANCES" false "MONOLITHIC")
run_cpack_test(RECOMMENDS "RPM.RECOMMENDS" false "MONOLITHIC")
run_cpack_test(SUPPLEMENTS "RPM.SUPPLEMENTS" false "MONOLITHIC")
run_cpack_test(SYMLINKS "RPM.SYMLINKS;TGZ" false "MONOLITHIC;COMPONENT")
set(ENVIRONMENT "SOURCE_DATE_EPOCH=123456789")
run_cpack_test(TIMESTAMPS "DEB.TIMESTAMPS;TGZ" false "COMPONENT")

View File

@ -0,0 +1,2 @@
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")

View File

@ -0,0 +1 @@
^CPackRPM: Will use GENERATED spec file: (/[^/]*)*/Tests/RunCMake/RPM\.ENHANCES/CPack/[^-]*-build/_CPack_Packages/.*/RPM/SPECS/[^\.]*\.spec$

View File

@ -0,0 +1,35 @@
# CPack uses `rpm --enhances` to check if rpmbuild supports the "Enhances:" tag.
# This test intentionally uses a different method (build a test .spec) so any
# problems will be caught early if functionality should change in the future.
execute_process(
COMMAND ${RPMBUILD_EXECUTABLE} --nobuild test_enhances.spec
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
RESULT_VARIABLE RPMBUILD_ENHANCES_RESULT)
if(RPMBUILD_ENHANCES_RESULT EQUAL 0)
set(should_contain_enhances_tag_ true)
endif()
# Only verify that enhances tag is present only if that tag is supported.
# If it is not supported the rpm package was correctly generated by ignoring
# that tag and that was already checked by expected files test.
if(should_contain_enhances_tag_)
execute_process(COMMAND ${RPM_EXECUTABLE} -q --enhances -p "${FOUND_FILE_1}"
RESULT_VARIABLE rpm_result_
OUTPUT_VARIABLE rpm_stdout_
ERROR_VARIABLE rpm_stderr_
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(rpm_result_ OR NOT rpm_stdout_ STREQUAL "libenhanced")
string(REPLACE "\n" "\n " rpm_stdout_ "${rpm_stdout_}")
string(REPLACE "\n" "\n " rpm_stderr_ "${rpm_stderr_}")
message(FATAL_ERROR "RPM_ENHANCED package error: no enhanced packages\n"
"result: ${rpm_result_}\n"
"stdout:\n"
" ${rpm_stdout_}\n"
"stderr:\n"
" ${rpm_stderr_}\n"
)
endif()
endif()

View File

@ -0,0 +1,3 @@
install(FILES CMakeLists.txt DESTINATION foo)
set(CPACK_RPM_PACKAGE_ENHANCES "libenhanced")

View File

@ -0,0 +1,22 @@
# This spec file is used to check if the provided version of rpmbuild supports the "Enhances:" tag
Name: test
Version: 0
Release: 1
Summary: test
License: test
Enhances: enhanced_package
%description
%prep
%build
%configure
%install
%clean
%files
%doc
%changelog

View File

@ -0,0 +1,2 @@
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")

View File

@ -0,0 +1 @@
^CPackRPM: Will use GENERATED spec file: (/[^/]*)*/Tests/RunCMake/RPM\.RECOMMENDS/CPack/[^-]*-build/_CPack_Packages/.*/RPM/SPECS/[^\.]*\.spec$

View File

@ -0,0 +1,35 @@
# CPack uses `rpm --recommends` to check if rpmbuild supports the "Recommends:" tag.
# This test intentionally uses a different method (build a test .spec) so any
# problems will be caught early if functionality should change in the future.
execute_process(
COMMAND ${RPMBUILD_EXECUTABLE} --nobuild test_recommends.spec
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
RESULT_VARIABLE RPMBUILD_RECOMMENDS_RESULT)
if(RPMBUILD_RECOMMENDS_RESULT EQUAL 0)
set(should_contain_recommends_tag_ true)
endif()
# Only verify that recommends tag is present only if that tag is supported.
# If it is not supported the rpm package was correctly generated by ignoring
# that tag and that was already checked by expected files test.
if(should_contain_recommends_tag_)
execute_process(COMMAND ${RPM_EXECUTABLE} -q --recommends -p "${FOUND_FILE_1}"
RESULT_VARIABLE rpm_result_
OUTPUT_VARIABLE rpm_stdout_
ERROR_VARIABLE rpm_stderr_
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(rpm_result_ OR NOT rpm_stdout_ STREQUAL "librecommended")
string(REPLACE "\n" "\n " rpm_stdout_ "${rpm_stdout_}")
string(REPLACE "\n" "\n " rpm_stderr_ "${rpm_stderr_}")
message(FATAL_ERROR "RPM_RECOMMENDED package error: no recommended packages\n"
"result: ${rpm_result_}\n"
"stdout:\n"
" ${rpm_stdout_}\n"
"stderr:\n"
" ${rpm_stderr_}\n"
)
endif()
endif()

View File

@ -0,0 +1,3 @@
install(FILES CMakeLists.txt DESTINATION foo)
set(CPACK_RPM_PACKAGE_RECOMMENDS "librecommended")

View File

@ -0,0 +1,22 @@
# This spec file is used to check if the provided version of rpmbuild supports the "Recommends:" tag
Name: test
Version: 0
Release: 1
Summary: test
License: test
Recommends: recommended_package
%description
%prep
%build
%configure
%install
%clean
%files
%doc
%changelog

View File

@ -0,0 +1,2 @@
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")

View File

@ -0,0 +1 @@
^CPackRPM: Will use GENERATED spec file: (/[^/]*)*/Tests/RunCMake/RPM\.SUPPLEMENTS/CPack/[^-]*-build/_CPack_Packages/.*/RPM/SPECS/[^\.]*\.spec$

View File

@ -0,0 +1,35 @@
# CPack uses `rpm --supplements` to check if rpmbuild supports the "Supplements:" tag.
# This test intentionally uses a different method (build a test .spec) so any
# problems will be caught early if functionality should change in the future.
execute_process(
COMMAND ${RPMBUILD_EXECUTABLE} --nobuild test_supplements.spec
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
RESULT_VARIABLE RPMBUILD_SUPPLEMENTS_RESULT)
if(RPMBUILD_SUPPLEMENTS_RESULT EQUAL 0)
set(should_contain_supplements_tag_ true)
endif()
# Only verify that supplements tag is present only if that tag is supported.
# If it is not supported the rpm package was correctly generated by ignoring
# that tag and that was already checked by expected files test.
if(should_contain_supplements_tag_)
execute_process(COMMAND ${RPM_EXECUTABLE} -q --supplements -p "${FOUND_FILE_1}"
RESULT_VARIABLE rpm_result_
OUTPUT_VARIABLE rpm_stdout_
ERROR_VARIABLE rpm_stderr_
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(rpm_result_ OR NOT rpm_stdout_ STREQUAL "libsupplemented")
string(REPLACE "\n" "\n " rpm_stdout_ "${rpm_stdout_}")
string(REPLACE "\n" "\n " rpm_stderr_ "${rpm_stderr_}")
message(FATAL_ERROR "RPM_SUPPLEMENTED package error: no supplemented packages\n"
"result: ${rpm_result_}\n"
"stdout:\n"
" ${rpm_stdout_}\n"
"stderr:\n"
" ${rpm_stderr_}\n"
)
endif()
endif()

View File

@ -0,0 +1,3 @@
install(FILES CMakeLists.txt DESTINATION foo)
set(CPACK_RPM_PACKAGE_SUPPLEMENTS "libsupplemented")

View File

@ -0,0 +1,22 @@
# This spec file is used to check if the provided version of rpmbuild supports the "Supplements:" tag
Name: test
Version: 0
Release: 1
Summary: test
License: test
Supplements: supplemented_package
%description
%prep
%build
%configure
%install
%clean
%files
%doc
%changelog