mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-03 06:10:28 +00: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()
|
endif()
|
||||||
endfunction()
|
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.
|
# Protect RunCMake tests from calling environment.
|
||||||
unset(ENV{MAKEFLAGS})
|
unset(ENV{MAKEFLAGS})
|
||||||
|
|||||||
@@ -4,18 +4,9 @@ run_cmake(InvalidArgument1)
|
|||||||
run_cmake(exists)
|
run_cmake(exists)
|
||||||
if(NOT MSYS)
|
if(NOT MSYS)
|
||||||
# permissions and symbolic links are broken on MSYS
|
# permissions and symbolic links are broken on MSYS
|
||||||
unset(uid)
|
# if real user is root, tests are irrelevant
|
||||||
unset(status)
|
get_unix_uid(uid)
|
||||||
if(UNIX)
|
if(NOT uid STREQUAL "0")
|
||||||
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")
|
|
||||||
run_cmake(FilePermissions)
|
run_cmake(FilePermissions)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user