cmake: Add function for checking if a directory is write-able

Added a CMake extention for determining if a directory is write-able
by the build system. To determine this, we attempt to 'touch' a file
in the directory and check the return code of this command.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
This commit is contained in:
Sebastian Bøe 2018-04-17 14:37:24 +02:00 committed by Carles Cufí
commit 6c3a94c01f
2 changed files with 29 additions and 0 deletions

View file

@ -18,6 +18,7 @@ include(CheckCXXCompilerFlag)
# 3.2. *_ifndef
# 3.3. *_option compiler compatibility checks
# 3.4. Debugging CMake
# 3.5. File system management
########################################################
# 1. Zephyr-aware extensions
@ -1004,3 +1005,21 @@ macro(assert_with_usage test comment)
endif()
endmacro()
# 3.5. File system management
function(check_if_directory_is_writeable dir ok)
execute_process(
COMMAND
${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/dir_is_writeable.py
${dir}
RESULT_VARIABLE ret
)
if("${ret}" STREQUAL "0")
# The directory is write-able
set(${ok} 1 PARENT_SCOPE)
else()
set(${ok} 0 PARENT_SCOPE)
endif()
endfunction()

View file

@ -0,0 +1,10 @@
import os
import sys
def main():
is_writeable = os.access(sys.argv[1], os.W_OK)
return_code = int(not is_writeable)
sys.exit(return_code)
if __name__ == "__main__":
main()