mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-05 22:00:10 -05:00
Tests: Factor out RunCMake helper to get UNIX user id
This commit is contained in:
@@ -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})
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user