summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-11-02 13:30:41 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-11-02 13:31:01 (GMT)
commit0f02655bb01346cab483761bd75fa8dc6cbfe7f1 (patch)
treeb51a2341094b4aa3bb24ed0661da6dcde6ac0a99 /Tests
parent83a85264b406c5197e0ce780cd238626afa6f4ed (diff)
parent337bc5662c35acce32630bfa26e87a42d472726f (diff)
downloadCMake-0f02655bb01346cab483761bd75fa8dc6cbfe7f1.zip
CMake-0f02655bb01346cab483761bd75fa8dc6cbfe7f1.tar.gz
CMake-0f02655bb01346cab483761bd75fa8dc6cbfe7f1.tar.bz2
Merge topic 'if-check-file-permissions'
337bc5662c if(): add operators IS_READABLE, IS_WRITABLE and IS_EXECUTABLE. Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !8908
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/if/FilePermissions.cmake153
-rw-r--r--Tests/RunCMake/if/RunCMakeTest.cmake17
3 files changed, 171 insertions, 1 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index ae878c9..1b1ecb5 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -535,7 +535,7 @@ add_RunCMake_test(function)
add_RunCMake_test(block)
add_RunCMake_test(get_filename_component)
add_RunCMake_test(get_property)
-add_RunCMake_test(if)
+add_RunCMake_test(if -DMSYS=${MSYS})
add_RunCMake_test(include)
add_RunCMake_test(include_directories)
add_RunCMake_test(include_guard)
diff --git a/Tests/RunCMake/if/FilePermissions.cmake b/Tests/RunCMake/if/FilePermissions.cmake
new file mode 100644
index 0000000..7881b5f
--- /dev/null
+++ b/Tests/RunCMake/if/FilePermissions.cmake
@@ -0,0 +1,153 @@
+
+file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/readable.txt"
+ "${CMAKE_CURRENT_BINARY_DIR}/writable.txt"
+ "${CMAKE_CURRENT_BINARY_DIR}/executable.txt")
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/readable.txt" "foo")
+file(CHMOD "${CMAKE_CURRENT_BINARY_DIR}/readable.txt" PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/writable.txt" "foo")
+file(CHMOD "${CMAKE_CURRENT_BINARY_DIR}/writable.txt" PERMISSIONS OWNER_WRITE GROUP_WRITE WORLD_WRITE)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/executable.txt" "foo")
+file(CHMOD "${CMAKE_CURRENT_BINARY_DIR}/executable.txt" PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
+
+if(NOT WIN32)
+ file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/readable-dir"
+ "${CMAKE_CURRENT_BINARY_DIR}/writable-dir"
+ "${CMAKE_CURRENT_BINARY_DIR}/executable-dir")
+
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/readable-dir")
+ file(CHMOD "${CMAKE_CURRENT_BINARY_DIR}/readable-dir" PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
+
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/writable-dir")
+ file(CHMOD "${CMAKE_CURRENT_BINARY_DIR}/writable-dir" PERMISSIONS OWNER_WRITE GROUP_WRITE WORLD_WRITE)
+
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/executable-dir")
+ file(CHMOD "${CMAKE_CURRENT_BINARY_DIR}/executable-dir" PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
+endif()
+
+if(WIN32)
+ # files are always readable and executable
+ # directories are always, readable, writable and executable
+ if(NOT IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/readable.txt"
+ OR IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/readable.txt")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/readable.txt\" failed")
+ endif()
+
+ if(NOT IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/executable.txt"
+ OR IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/executable.txt")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/executable.txt\" failed")
+ endif()
+else()
+ if(NOT IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/readable.txt"
+ OR IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/readable.txt"
+ OR IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/readable.txt")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/readable.txt\" failed")
+ endif()
+
+ if(NOT IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/writable.txt"
+ OR IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/writable.txt"
+ OR IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/writable.txt")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/writable.txt\" failed")
+ endif()
+
+ if(NOT IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/executable.txt"
+ OR IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/executable.txt"
+ OR IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/executable.txt")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/executable.txt\" failed")
+ endif()
+
+
+ if(NOT IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/readable-dir"
+ OR IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/readable-dir"
+ OR IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/readable-dir")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/readable-dir\" failed")
+ endif()
+
+ if(NOT IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/writable-dir"
+ OR IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/writable-dir"
+ OR IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/writable-dir")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/writable-dir\" failed")
+ endif()
+
+ if(NOT IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/executable-dir"
+ OR IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/executable-dir"
+ OR IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/executable-dir")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/executable.txt\" failed")
+ endif()
+endif()
+
+if(UNIX)
+ #
+ # Check that file permissions are on the real file, not the symbolic link
+ #
+ file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/link-to-readable.txt"
+ "${CMAKE_CURRENT_BINARY_DIR}/link-to-writable.txt"
+ "${CMAKE_CURRENT_BINARY_DIR}/link-to-executable.txt"
+ "${CMAKE_CURRENT_BINARY_DIR}/link-to-readable-dir"
+ "${CMAKE_CURRENT_BINARY_DIR}/link-to-writable-dir"
+ "${CMAKE_CURRENT_BINARY_DIR}/link-to-executable-dir")
+
+ file(CREATE_LINK "${CMAKE_CURRENT_BINARY_DIR}/readable.txt"
+ "${CMAKE_CURRENT_BINARY_DIR}/link-to-readable.txt"
+ SYMBOLIC)
+
+ file(CREATE_LINK "${CMAKE_CURRENT_BINARY_DIR}/writable.txt"
+ "${CMAKE_CURRENT_BINARY_DIR}/link-to-writable.txt"
+ SYMBOLIC)
+
+ file(CREATE_LINK "${CMAKE_CURRENT_BINARY_DIR}/executable.txt"
+ "${CMAKE_CURRENT_BINARY_DIR}/link-to-executable.txt"
+ SYMBOLIC)
+
+
+ file(CREATE_LINK "${CMAKE_CURRENT_BINARY_DIR}/readable-dir"
+ "${CMAKE_CURRENT_BINARY_DIR}/link-to-readable-dir"
+ SYMBOLIC)
+
+ file(CREATE_LINK "${CMAKE_CURRENT_BINARY_DIR}/writable-dir"
+ "${CMAKE_CURRENT_BINARY_DIR}/link-to-writable-dir"
+ SYMBOLIC)
+
+ file(CREATE_LINK "${CMAKE_CURRENT_BINARY_DIR}/executable-dir"
+ "${CMAKE_CURRENT_BINARY_DIR}/link-to-executable-dir"
+ SYMBOLIC)
+
+ if(NOT IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-readable.txt"
+ OR IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-readable.txt"
+ OR IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-readable.txt")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/link-to-readable.txt\" failed")
+ endif()
+
+ if(NOT IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-writable.txt"
+ OR IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-writable.txt"
+ OR IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-writable.txt")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/link-to-writable.txt\" failed")
+ endif()
+
+ if(NOT IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-executable.txt"
+ OR IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-executable.txt"
+ OR IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-executable.txt")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/link-to-executable.txt\" failed")
+ endif()
+
+
+ if(NOT IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-readable-dir"
+ OR IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-readable-dir"
+ OR IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-readable-dir")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/link-to-readable-dir\" failed")
+ endif()
+
+ if(NOT IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-writable-dir"
+ OR IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-writable-dir"
+ OR IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-writable-dir")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/link-to-writable-dir\" failed")
+ endif()
+
+ if(NOT IS_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-executable-dir"
+ OR IS_READABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-executable-dir"
+ OR IS_WRITABLE "${CMAKE_CURRENT_BINARY_DIR}/link-to-executable-dir")
+ message(FATAL_ERROR "checks on \"${CMAKE_CURRENT_BINARY_DIR}/link-to-executable-dir\" failed")
+ endif()
+endif()
diff --git a/Tests/RunCMake/if/RunCMakeTest.cmake b/Tests/RunCMake/if/RunCMakeTest.cmake
index efee116..0bfff90 100644
--- a/Tests/RunCMake/if/RunCMakeTest.cmake
+++ b/Tests/RunCMake/if/RunCMakeTest.cmake
@@ -2,6 +2,23 @@ include(RunCMake)
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")
+ run_cmake(FilePermissions)
+ endif()
+endif()
run_cmake(IsDirectory)
run_cmake(IsDirectoryLong)
run_cmake(duplicate-deep-else)