Merge topic 'cpack-components-handle-symlinks'

26384068 CPack test symlinks in package
6949b71f CPack unify component/monolithic package symlink handling
3eb0f080 Improved CPack tests error logging

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !841
This commit is contained in:
Brad King
2017-05-15 14:55:53 +00:00
committed by Kitware Robot
9 changed files with 66 additions and 4 deletions

View File

@@ -795,6 +795,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
cmsys::Glob glA;
glA.RecurseOn();
glA.SetRecurseListDirs(true);
glA.SetRecurseThroughSymlinks(false);
glA.FindFiles(findExpr);
std::vector<std::string> filesAfter = glA.GetFiles();
std::sort(filesAfter.begin(), filesAfter.end());

View File

@@ -33,7 +33,7 @@ function(getPackageContentList FILE RESULT_VAR)
endfunction()
function(toExpectedContentList FILE_NO CONTENT_VAR)
findExpectedFile("${FILE_NO}" "file_")
findExpectedFile("${FILE_NO}" "file_" "glob_expr_")
# component and monolithic packages differ for some reason by either having
# package filename prefix in path or not

View File

@@ -24,5 +24,6 @@ run_cpack_test_subtests(SINGLE_DEBUGINFO "no_main_component;one_component;one_co
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(SYMLINKS "RPM;TGZ" false "MONOLITHIC;COMPONENT")
run_cpack_test(USER_FILELIST "RPM" false "MONOLITHIC")
run_cpack_test(MD5SUMS "DEB" false "MONOLITHIC;COMPONENT")

View File

@@ -35,7 +35,7 @@ function(getPackageContentList FILE RESULT_VAR)
endfunction()
function(toExpectedContentList FILE_NO CONTENT_VAR)
findExpectedFile("${FILE_NO}" "file_")
findExpectedFile("${FILE_NO}" "file_" "glob_expr_")
get_filename_component(prefix_ "${file_}" NAME)
# NAME_WE removes everything after the dot and dot is in version so replace instead

View File

@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION ${CMAKE_VERSION} FATAL_ERROR)
function(findExpectedFile FILE_NO RESULT_VAR)
function(findExpectedFile FILE_NO RESULT_VAR GLOBING_EXPR_VAR)
if(NOT DEFINED EXPECTED_FILE_${FILE_NO}) # explicit file name regex was not provided - construct one from other data
# set defaults if parameters are not provided
if(NOT DEFINED EXPECTED_FILE_${FILE_NO}_NAME)
@@ -21,6 +21,7 @@ function(findExpectedFile FILE_NO RESULT_VAR)
file(GLOB found_file_ RELATIVE "${bin_dir}" "${EXPECTED_FILE_${FILE_NO}}")
set(${RESULT_VAR} "${found_file_}" PARENT_SCOPE)
set(${GLOBING_EXPR_VAR} "${EXPECTED_FILE_${FILE_NO}}" PARENT_SCOPE)
endfunction()
include("${config_file}")
@@ -39,7 +40,8 @@ include("${src_dir}/tests/${RunCMake_TEST_FILE_PREFIX}/ExpectedFiles.cmake")
# check that expected generated files exist and contain expected content
if(NOT EXPECTED_FILES_COUNT EQUAL 0)
foreach(file_no_ RANGE 1 ${EXPECTED_FILES_COUNT})
findExpectedFile("${file_no_}" "FOUND_FILE_${file_no_}")
findExpectedFile("${file_no_}" "FOUND_FILE_${file_no_}"
"EXPECTED_FILE_${file_no_}")
list(APPEND foundFiles_ "${FOUND_FILE_${file_no_}}")
list(LENGTH FOUND_FILE_${file_no_} foundFilesCount_)

View File

@@ -0,0 +1,13 @@
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_CONTENT_1_LIST
"/usr"
"/usr/empty_dir"
"/usr/non_empty_dir"
"/usr/non_empty_dir/CMakeLists.txt"
"/usr/symlink_to_empty_dir"
"/usr/symlink_to_non_empty_dir")
if(PACKAGING_TYPE STREQUAL "COMPONENT")
set(EXPECTED_FILE_1_COMPONENT "links")
endif()

View File

@@ -0,0 +1,5 @@
function(get_test_prerequirements found_var config_file)
if(UNIX) # limit test to platforms that support symlinks
set(${found_var} true PARENT_SCOPE)
endif()
endfunction()

View File

@@ -0,0 +1,26 @@
set(whitespaces "[\\t\\n\\r ]*")
#######################
# verify generated symbolic links
#######################
file(GLOB_RECURSE symlink_files RELATIVE "${bin_dir}" "${bin_dir}/*/symlink_*")
foreach(check_symlink IN LISTS symlink_files)
get_filename_component(symlink_name "${check_symlink}" NAME)
execute_process(COMMAND ls -la "${check_symlink}"
WORKING_DIRECTORY "${bin_dir}"
OUTPUT_VARIABLE SYMLINK_POINT_
OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${symlink_name}" STREQUAL "symlink_to_empty_dir")
string(REGEX MATCH "^.*${whitespaces}->${whitespaces}empty_dir$" check_symlink "${SYMLINK_POINT_}")
elseif("${symlink_name}" STREQUAL "symlink_to_non_empty_dir")
string(REGEX MATCH "^.*${whitespaces}->${whitespaces}non_empty_dir$" check_symlink "${SYMLINK_POINT_}")
else()
message(FATAL_ERROR "error: unexpected rpm symbolic link '${check_symlink}'")
endif()
if(NOT check_symlink)
message(FATAL_ERROR "symlink points to unexpected location '${SYMLINK_POINT_}'")
endif()
endforeach()

View File

@@ -0,0 +1,14 @@
install(DIRECTORY DESTINATION empty_dir COMPONENT links)
install(FILES CMakeLists.txt DESTINATION non_empty_dir COMPONENT links)
# test symbolic link to an empty dir
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink empty_dir symlink_to_empty_dir)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_to_empty_dir DESTINATION "." COMPONENT links)
# test symbolic link to a non empty dir
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink non_empty_dir symlink_to_non_empty_dir)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_to_non_empty_dir DESTINATION "." COMPONENT links)
if(PACKAGING_TYPE STREQUAL "COMPONENT")
set(CPACK_COMPONENTS_ALL links)
endif()