mirror of
https://github.com/Kitware/CMake.git
synced 2026-07-06 22:58:05 +00:00
CPack/RPM: Fix detection of RPM support for weak dependencies
Add a missing `find_program` call to populate `RPM_EXECUTABLE`. This was left out of two previous changes that intended to query the `rpm` executable: * In commit9b53eca317(CPack/RPM: Fix weak dep support, 2021-06-29, v3.21.0-rc2~4^2), without `RPM_EXECUTABLE` the query always failed, so we were concluding that weak dependencies are not supported even when they are. * In commit488de6294a(CPack: correctly perform querytags on old versions of RPM, 2025-01-09, v4.0.0-rc1~182^2~3), without `RPM_EXECUTABLE` the query always failed. This change has not yet been in a release anyway. Also fix the test case for the "suggests" field to verify this. Issue: #22350 Reported-by: Balazs Kosaras <balazskosaras@gmail.com>
This commit is contained in:
@@ -812,6 +812,10 @@ function(cpack_rpm_generate_package)
|
||||
message(FATAL_ERROR "RPM package requires rpmbuild executable")
|
||||
endif()
|
||||
|
||||
# rpm is used for fallback queries in some older versions,
|
||||
# but is not required in general.
|
||||
find_program(RPM_EXECUTABLE rpm)
|
||||
|
||||
# Check version of the rpmbuild tool this would be easier to
|
||||
# track bugs with users and CPackRPM debug mode.
|
||||
# We may use RPM version in order to check for available version dependent features
|
||||
@@ -1077,7 +1081,7 @@ function(cpack_rpm_generate_package)
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
# In some versions of RPM, rpmbuild does not understand --querytags parameter,
|
||||
# but rpm does.
|
||||
if(NOT RPMBUILD_QUERYTAGS_SUCCESS EQUAL 0)
|
||||
if(NOT RPMBUILD_QUERYTAGS_SUCCESS EQUAL 0 AND RPM_EXECUTABLE)
|
||||
execute_process(
|
||||
COMMAND "${RPM_EXECUTABLE}" --querytags
|
||||
OUTPUT_VARIABLE RPMBUILD_TAG_LIST
|
||||
@@ -1088,16 +1092,16 @@ function(cpack_rpm_generate_package)
|
||||
# In some versions of RPM, weak dependency tags are present in the --querytags
|
||||
# list, but unsupported by rpmbuild. A different method must be used to check
|
||||
# if they are supported.
|
||||
|
||||
execute_process(
|
||||
COMMAND ${RPM_EXECUTABLE} --suggests
|
||||
ERROR_QUIET
|
||||
RESULT_VARIABLE RPMBUILD_SUGGESTS_RESULT)
|
||||
|
||||
if(NOT RPMBUILD_SUGGESTS_RESULT EQUAL 0)
|
||||
foreach(_WEAK_DEP SUGGESTS RECOMMENDS SUPPLEMENTS ENHANCES)
|
||||
list(REMOVE_ITEM RPMBUILD_TAG_LIST ${_WEAK_DEP})
|
||||
endforeach()
|
||||
if(RPM_EXECUTABLE)
|
||||
execute_process(
|
||||
COMMAND "${RPM_EXECUTABLE}" --suggests
|
||||
ERROR_QUIET
|
||||
RESULT_VARIABLE RPM_SUGGESTS_RESULT)
|
||||
if(NOT RPM_SUGGESTS_RESULT EQUAL 0)
|
||||
foreach(_WEAK_DEP SUGGESTS RECOMMENDS SUPPLEMENTS ENHANCES)
|
||||
list(REMOVE_ITEM RPMBUILD_TAG_LIST ${_WEAK_DEP})
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CPACK_RPM_PACKAGE_EPOCH)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
execute_process(
|
||||
COMMAND ${RPMBUILD_EXECUTABLE} --nobuild test_suggests.spec
|
||||
ERROR_QUIET
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
RESULT_VARIABLE RPMBUILD_SUGGESTS_RESULT)
|
||||
|
||||
if(RPMBUILD_SUGGESTS_RESULT EQUAL 0)
|
||||
@@ -15,15 +16,20 @@ endif()
|
||||
# that tag and that was already checked by expected files test.
|
||||
if(should_contain_suggests_tag_)
|
||||
execute_process(COMMAND ${RPM_EXECUTABLE} -q --suggests -p "${FOUND_FILE_1}"
|
||||
WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
|
||||
RESULT_VARIABLE rpm_result_
|
||||
OUTPUT_VARIABLE rpm_output_
|
||||
ERROR_VARIABLE error_variable_
|
||||
OUTPUT_VARIABLE rpm_stdout_
|
||||
ERROR_VARIABLE rpm_stderr_
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
if(rpm_result_ OR NOT rpm_output_ STREQUAL "libsuggested")
|
||||
message(FATAL_ERROR "RPM_SUGGESTED package error: no suggested packages"
|
||||
" (result: '${rpm_result_}'; output: '${rpm_output_}';"
|
||||
" error: '${error_variable_}')")
|
||||
if(rpm_result_ OR NOT rpm_stdout_ STREQUAL "libsuggested")
|
||||
string(REPLACE "\n" "\n " rpm_stdout_ "${rpm_stdout_}")
|
||||
string(REPLACE "\n" "\n " rpm_stderr_ "${rpm_stderr_}")
|
||||
message(FATAL_ERROR "RPM_SUGGESTED package error: no suggested packages\n"
|
||||
"result: ${rpm_result_}\n"
|
||||
"stdout:\n"
|
||||
" ${rpm_stdout_}\n"
|
||||
"stderr:\n"
|
||||
" ${rpm_stderr_}\n"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user