From 69b740dc5eb71d133e7c4bc6b98b0a7d36d800ac Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 31 Mar 2021 17:35:00 +1100 Subject: [PATCH 1/3] cmake: Fix passing PYTHON path via CMake variable if using IDF as library Closes https://github.com/espressif/esp-idf/issues/6285 --- tools/cmake/build.cmake | 6 ++++-- tools/cmake/project.cmake | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 934ab8905f..8fee5d19a4 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -127,9 +127,11 @@ function(__build_init idf_path) # Must be global so as to be accessible from any subdirectory in custom projects. add_library(__idf_build_target STATIC IMPORTED GLOBAL) - set_default(python "python") + # Set the Python path (which may be passed in via -DPYTHON=) and store in a build property + set_default(PYTHON "python") + file(TO_CMAKE_PATH ${PYTHON} PYTHON) + idf_build_set_property(PYTHON ${PYTHON}) - idf_build_set_property(PYTHON ${python}) idf_build_set_property(IDF_PATH ${idf_path}) idf_build_set_property(__PREFIX idf) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 8329ed50af..3bb1be0a77 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -6,12 +6,15 @@ cmake_minimum_required(VERSION 3.5) # call. include(${CMAKE_CURRENT_LIST_DIR}/idf.cmake) +# legacy variable for compatibility set(IDFTOOL ${PYTHON} "${IDF_PATH}/tools/idf.py") -# Internally, the Python interpreter is already set to 'python'. Re-set here -# to be absolutely sure. -set_default(PYTHON "python") -file(TO_CMAKE_PATH ${PYTHON} PYTHON) -idf_build_set_property(PYTHON ${PYTHON}) + +# setting PYTHON variable here for compatibility only, new code should use +# idf_build_get_property(variable PYTHON) +idf_build_get_property(PYTHON PYTHON) +if(NOT PYTHON) + message(FATAL_ERROR "Internal error, PYTHON build property not set correctly.") +endif() # On processing, checking Python required modules can be turned off if it was # already checked externally. From 6ee835f6ea4948b17916c691793f15919cf5b8b5 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 31 Mar 2021 17:35:42 +1100 Subject: [PATCH 2/3] cmake: Set IDFTOOL variable using the correct PYTHON interpreter variable --- tools/cmake/project.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 3bb1be0a77..e350e4f49a 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -6,9 +6,6 @@ cmake_minimum_required(VERSION 3.5) # call. include(${CMAKE_CURRENT_LIST_DIR}/idf.cmake) -# legacy variable for compatibility -set(IDFTOOL ${PYTHON} "${IDF_PATH}/tools/idf.py") - # setting PYTHON variable here for compatibility only, new code should use # idf_build_get_property(variable PYTHON) idf_build_get_property(PYTHON PYTHON) @@ -16,6 +13,9 @@ if(NOT PYTHON) message(FATAL_ERROR "Internal error, PYTHON build property not set correctly.") endif() +# legacy variable for compatibility +set(IDFTOOL ${PYTHON} "${IDF_PATH}/tools/idf.py") + # On processing, checking Python required modules can be turned off if it was # already checked externally. if(PYTHON_DEPS_CHECKED) From 4c974574d72b8a35af89e75e3877ef46f0c72969 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 31 Mar 2021 17:36:50 +1100 Subject: [PATCH 3/3] cmake: Improve the error message if the Python interpreter fails to run RESULT_VARIABLE will return a string not a number in this case, so display it for the user. --- tools/cmake/build.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 8fee5d19a4..88fb0a14b0 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -272,8 +272,12 @@ function(__build_check_python) message(STATUS "Checking Python dependencies...") execute_process(COMMAND "${python}" "${idf_path}/tools/check_python_dependencies.py" RESULT_VARIABLE result) - if(NOT result EQUAL 0) + if(result EQUAL 1) + # check_python_dependencies returns error code 1 on failure message(FATAL_ERROR "Some Python dependencies must be installed. Check above message for details.") + elseif(NOT result EQUAL 0) + # means check_python_dependencies.py failed to run at all, result should be an error message + message(FATAL_ERROR "Failed to run Python dependency check. Python: ${python}, Error: ${result}") endif() endif() endfunction()