Tests: Factor out RunCMake helper to get UNIX user id

This commit is contained in:
Brad King
2023-11-30 17:04:37 -05:00
parent 5799d0e788
commit d91c02e40f
2 changed files with 19 additions and 12 deletions
+16
View File
@@ -323,5 +323,21 @@ function(ensure_files_match expected_file actual_file)
endif()
endfunction()
# Get the user id on unix if possible.
function(get_unix_uid var)
set("${var}" "" PARENT_SCOPE)
if(UNIX)
set(ID "id")
if(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND EXISTS "/usr/xpg4/bin/id")
set (ID "/usr/xpg4/bin/id")
endif()
execute_process(COMMAND ${ID} -u $ENV{USER} OUTPUT_VARIABLE uid ERROR_QUIET
RESULT_VARIABLE status OUTPUT_STRIP_TRAILING_WHITESPACE)
if(status EQUAL 0)
set("${var}" "${uid}" PARENT_SCOPE)
endif()
endif()
endfunction()
# Protect RunCMake tests from calling environment.
unset(ENV{MAKEFLAGS})
+3 -12
View File
@@ -4,18 +4,9 @@ run_cmake(InvalidArgument1)
run_cmake(exists)
if(NOT MSYS)
# permissions and symbolic links are broken on MSYS
unset(uid)
unset(status)
if(UNIX)
set(ID "id")
if (CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND EXISTS "/usr/xpg4/bin/id")
set (ID "/usr/xpg4/bin/id")
endif()
# if real user is root, tests are irrelevant
execute_process(COMMAND ${ID} -u $ENV{USER} OUTPUT_VARIABLE uid ERROR_QUIET
RESULT_VARIABLE status OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
if(NOT status AND NOT uid STREQUAL "0")
# if real user is root, tests are irrelevant
get_unix_uid(uid)
if(NOT uid STREQUAL "0")
run_cmake(FilePermissions)
endif()
endif()