diff options
author | Domen Vrankar <domen.vrankar@gmail.com> | 2017-03-13 22:17:24 (GMT) |
---|---|---|
committer | Domen Vrankar <domen.vrankar@gmail.com> | 2017-03-13 22:22:55 (GMT) |
commit | 598400a3e7148c75f83e1adf995cd6c1a3857d58 (patch) | |
tree | a202c96b7d7e7f01e9d19619c163c29b500e172d | |
parent | ccec62c6aa8ac44aaa9908ca5d72c396c5f068c0 (diff) | |
download | CMake-598400a3e7148c75f83e1adf995cd6c1a3857d58.zip CMake-598400a3e7148c75f83e1adf995cd6c1a3857d58.tar.gz CMake-598400a3e7148c75f83e1adf995cd6c1a3857d58.tar.bz2 |
CPack/RPM: handle extra slashes
Extra slashes in some locations can
cause errors during package generation
and can also be present in generated
rpm packages causing issues for the
package user.
Closes #16619
5 files changed, 76 insertions, 0 deletions
diff --git a/Modules/CPackRPM.cmake b/Modules/CPackRPM.cmake index b32feb5..7a7c170 100644 --- a/Modules/CPackRPM.cmake +++ b/Modules/CPackRPM.cmake @@ -958,10 +958,20 @@ function(cpack_rpm_prepare_relocation_paths) foreach(RELOCATION_PATH ${RPM_RELOCATION_PATHS}) if(IS_ABSOLUTE "${RELOCATION_PATH}") set(PREPARED_RELOCATION_PATH "${RELOCATION_PATH}") + elseif(PATH_PREFIX STREQUAL "/") + # don't prefix path with a second slash as "//" is treated as network path + # by get_filename_component() so it remains in path even inside rpm + # package where it may cause problems with relocation + set(PREPARED_RELOCATION_PATH "/${RELOCATION_PATH}") else() set(PREPARED_RELOCATION_PATH "${PATH_PREFIX}/${RELOCATION_PATH}") endif() + # handle cases where path contains extra slashes (e.g. /a//b/ instead of + # /a/b) + get_filename_component(PREPARED_RELOCATION_PATH + "${PREPARED_RELOCATION_PATH}" ABSOLUTE) + if(EXISTS "${WDIR}/${PREPARED_RELOCATION_PATH}") string(APPEND TMP_RPM_PREFIXES "Prefix: ${PREPARED_RELOCATION_PATH}\n") list(APPEND RPM_USED_PACKAGE_PREFIXES "${PREPARED_RELOCATION_PATH}") @@ -2130,6 +2140,11 @@ function(cpack_rpm_generate_package) set(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX "/usr/src/debug/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}") endif() + # handle cases where path contains extra slashes (e.g. /a//b/ instead of + # /a/b) + get_filename_component(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX + "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}" ABSOLUTE) + if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND GENERATE_SPEC_PARTS) file(WRITE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_COMPONENT}.files" "${CPACK_RPM_INSTALL_FILES}") diff --git a/Tests/RunCMake/CPack/RunCMakeTest.cmake b/Tests/RunCMake/CPack/RunCMakeTest.cmake index 65399db..8ca7126 100644 --- a/Tests/RunCMake/CPack/RunCMakeTest.cmake +++ b/Tests/RunCMake/CPack/RunCMakeTest.cmake @@ -21,6 +21,7 @@ run_cpack_test_subtests(PACKAGE_CHECKSUM "invalid;MD5;SHA1;SHA224;SHA256;SHA384; run_cpack_test(PARTIALLY_RELOCATABLE_WARNING "RPM" false "COMPONENT") run_cpack_test(PER_COMPONENT_FIELDS "RPM;DEB" false "COMPONENT") run_cpack_test_subtests(SINGLE_DEBUGINFO "no_main_component;one_component;one_component_main;no_debuginfo;one_component_no_debuginfo;no_components;valid" "RPM" true "CUSTOM") +run_cpack_test(EXTRA_SLASH_IN_PATH "RPM" true "COMPONENT") run_cpack_source_test(SOURCE_PACKAGE "RPM") run_cpack_test(SUGGESTS "RPM" false "MONOLITHIC") run_cpack_test(USER_FILELIST "RPM" false "MONOLITHIC") diff --git a/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/ExpectedFiles.cmake new file mode 100644 index 0000000..a45b38d --- /dev/null +++ b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/ExpectedFiles.cmake @@ -0,0 +1,16 @@ +set(whitespaces_ "[\t\n\r ]*") + +set(EXPECTED_FILES_COUNT "5") +set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE) + +set(EXPECTED_FILE_1_COMPONENT "applications") +set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog") +set(EXPECTED_FILE_2 "extra_slash_in_path*-headers.rpm") +set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt") +set(EXPECTED_FILE_3 "extra_slash_in_path*-libs.rpm") +set(EXPECTED_FILE_CONTENT_3_LIST "/bas;/bas/libtest_lib.so") + +set(EXPECTED_FILE_4_COMPONENT "applications-debuginfo") +set(EXPECTED_FILE_CONTENT_4 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*") +set(EXPECTED_FILE_5_COMPONENT "libs-debuginfo") +set(EXPECTED_FILE_CONTENT_5 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/test_lib.cpp.*") diff --git a/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/VerifyResult.cmake new file mode 100644 index 0000000..bfef720 --- /dev/null +++ b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/VerifyResult.cmake @@ -0,0 +1,7 @@ +# check that relocation path is /foo and not //foo +getPackageInfo("${FOUND_FILE_1}" "FILE_INFO_") +set(whitespaces_ "[\t\n\r ]*") +if(NOT FILE_INFO_ MATCHES "Relocations${whitespaces_}:${whitespaces_}/${whitespaces_}/foo") + message(FATAL_ERROR "Unexpected relocation path in file '${FOUND_FILE_1}';" + " file info: '${FILE_INFO_}'") +endif() diff --git a/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/test.cmake b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/test.cmake new file mode 100644 index 0000000..4fd1e81 --- /dev/null +++ b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/test.cmake @@ -0,0 +1,37 @@ +set(CMAKE_BUILD_WITH_INSTALL_RPATH 1) + +# PGI compiler doesn't add build id to binaries by default +if(CMAKE_CXX_COMPILER_ID STREQUAL "PGI") + string(APPEND CMAKE_EXE_LINKER_FLAGS "-Wl,--build-id") + string(APPEND CMAKE_SHARED_LINKER_FLAGS "-Wl,--build-id") +endif() + +set(CMAKE_BUILD_TYPE Debug) + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.hpp" + "int test_lib();\n") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp" + "#include \"test_lib.hpp\"\nint test_lib() {return 0;}\n") +add_library(test_lib SHARED "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp") + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + "#include \"test_lib.hpp\"\nint main() {return test_lib();}\n") +add_executable(test_prog "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +target_link_libraries(test_prog test_lib) + +install(TARGETS test_prog DESTINATION foo COMPONENT applications) +install(FILES CMakeLists.txt DESTINATION bar COMPONENT headers) +install(TARGETS test_lib DESTINATION bas COMPONENT libs) + +set(CPACK_RPM_APPLICATIONS_FILE_NAME "RPM-DEFAULT") +set(CPACK_RPM_APPLICATIONS_DEBUGINFO_PACKAGE ON) +set(CPACK_RPM_LIBS_DEBUGINFO_PACKAGE ON) + +# extra trailing slash at the end that should be removed +set(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX "/src/") + +# combination should not cause //foo to apper as an relocation path +# should be only /foo (extra slashes cause path comparisons to fail) +set(CPACK_PACKAGING_INSTALL_PREFIX "/") +# extra trailing slash at the end that should be removed +set(CPACK_RPM_RELOCATION_PATHS "foo/") |