From c6f367d25112afcaa3f657993df9f2007ecea70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Thu, 4 Jan 2018 17:36:02 +0100 Subject: [PATCH] cmake: Give descriptive error to user when cloned with core.autocrlf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Windows users have on multiple occasions cloned Zephyr using a Windows git client. It seems that the windows git client defaults to converting line endings from LF to CRLF when cloning repo's. This breaks at least one of Zephyr's tools (Kconfig). This patch introduces a sanity check of the environment for MSYS users. Signed-off-by: Sebastian Bøe --- cmake/app/boilerplate.cmake | 12 ++++++++++++ scripts/check_host_is_ok.py | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 scripts/check_host_is_ok.py diff --git a/cmake/app/boilerplate.cmake b/cmake/app/boilerplate.cmake index 0bc1a3f499..160648d6d0 100644 --- a/cmake/app/boilerplate.cmake +++ b/cmake/app/boilerplate.cmake @@ -105,6 +105,18 @@ add_custom_target( # Equivalent to rm -rf build/* ) +# Must be run before kconfig.cmake +if(MSYS) + execute_process( + COMMAND + ${PYTHON_EXECUTABLE} $ENV{ZEPHYR_BASE}/scripts/check_host_is_ok.py + RESULT_VARIABLE ret + ) + if(NOT "${ret}" STREQUAL "0") + message(FATAL_ERROR "command failed with return code: ${ret}") + endif() +endif() + # The BOARD can be set by 3 sources. Through environment variables, # through the cmake CLI, and through CMakeLists.txt. # diff --git a/scripts/check_host_is_ok.py b/scripts/check_host_is_ok.py new file mode 100644 index 0000000000..89dc48f42f --- /dev/null +++ b/scripts/check_host_is_ok.py @@ -0,0 +1,16 @@ +import os + + +def crash_if_zephyr_was_cloned_with_wrong_line_endings(): + f = open('{}/Kconfig'.format(os.environ["ZEPHYR_BASE"]), 'U') + f.readline() + + error_msg = "Re-clone with autocrlf false. $ git config --global core.autocrlf false" + + assert f.newlines == '\n', error_msg + +def main(): + crash_if_zephyr_was_cloned_with_wrong_line_endings() + +if __name__ == "__main__": + main()