diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake index d7d01635c2a..f1881f62ae4 100644 --- a/cmake/extensions.cmake +++ b/cmake/extensions.cmake @@ -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() + diff --git a/scripts/dir_is_writeable.py b/scripts/dir_is_writeable.py new file mode 100644 index 00000000000..b087b0c7b5e --- /dev/null +++ b/scripts/dir_is_writeable.py @@ -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()