diff options
author | Brad King <brad.king@kitware.com> | 2023-11-30 22:04:37 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-11-30 22:05:00 (GMT) |
commit | d91c02e40ff515fa2f5765bc2bea55b3c2da713c (patch) | |
tree | 9161a2b56245a69605823ecd980d7ec34ebd7312 /Tests | |
parent | 5799d0e78879ee60a4efa3ecbeae1076d2bef15f (diff) | |
download | CMake-d91c02e40ff515fa2f5765bc2bea55b3c2da713c.zip CMake-d91c02e40ff515fa2f5765bc2bea55b3c2da713c.tar.gz CMake-d91c02e40ff515fa2f5765bc2bea55b3c2da713c.tar.bz2 |
Tests: Factor out RunCMake helper to get UNIX user id
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/RunCMake.cmake | 16 | ||||
-rw-r--r-- | Tests/RunCMake/if/RunCMakeTest.cmake | 15 |
2 files changed, 19 insertions, 12 deletions
diff --git a/Tests/RunCMake/RunCMake.cmake b/Tests/RunCMake/RunCMake.cmake index fcf904e..179c80e 100644 --- a/Tests/RunCMake/RunCMake.cmake +++ b/Tests/RunCMake/RunCMake.cmake @@ -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}) diff --git a/Tests/RunCMake/if/RunCMakeTest.cmake b/Tests/RunCMake/if/RunCMakeTest.cmake index 0bfff90..43dfd3c 100644 --- a/Tests/RunCMake/if/RunCMakeTest.cmake +++ b/Tests/RunCMake/if/RunCMakeTest.cmake @@ -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() |