From dc28a9b33fa65915f9e9a4d973c61768824f7b76 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Tue, 28 Jun 2022 12:00:11 +0800 Subject: [PATCH] build&config: lift property IDF_COMPONENT_MANAGER to root level --- tools/cmake/build.cmake | 30 ++++++++++++++++++++++++++ tools/cmake/component.cmake | 2 +- tools/cmake/project.cmake | 42 +++++++------------------------------ 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index ce49c6ef54..7e2323179b 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -138,6 +138,7 @@ function(__build_init idf_path) idf_build_set_property(__PREFIX idf) idf_build_set_property(__CHECK_PYTHON 1) + idf_build_set_property(IDF_COMPONENT_MANAGER 0) __build_set_default_build_specifications() @@ -404,6 +405,35 @@ macro(idf_build_process target) idf_build_set_property(__COMPONENT_REQUIRES_COMMON ${target} APPEND) + idf_build_get_property(idf_component_manager IDF_COMPONENT_MANAGER) + if(idf_component_manager EQUAL "1") + set(managed_components_list_file ${CMAKE_BINARY_DIR}/managed_components_list.temp.cmake) + + # Call for package manager to prepare remote dependencies + execute_process(COMMAND ${PYTHON} + "-m" + "idf_component_manager.prepare_components" + "--project_dir=${CMAKE_CURRENT_LIST_DIR}" + "prepare_dependencies" + "--managed_components_list_file=${managed_components_list_file}" + RESULT_VARIABLE result + ERROR_VARIABLE error) + + if(NOT result EQUAL 0) + message(FATAL_ERROR "${error}") + endif() + + # Include managed components + include(${managed_components_list_file}) + file(REMOVE ${managed_components_list_file}) + else() + message(VERBOSE "IDF Component manager was explicitly disabled by setting IDF_COMPONENT_MANAGER=0") + if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/idf_project.yml") + message(WARNING "\"idf_project.yml\" file is found in project directory, " + "but component manager is not enabled. Please set IDF_COMPONENT_MANAGER environment variable.") + endif() + endif() + # Perform early expansion of component CMakeLists.txt in CMake scripting mode. # It is here we retrieve the public and private requirements of each component. # It is also here we add the common component requirements to each component's diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index 47c2ecef0b..257adc4d5e 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -222,7 +222,7 @@ function(__component_get_requirements) endif() idf_build_get_property(idf_component_manager IDF_COMPONENT_MANAGER) - if(idf_component_manager AND idf_component_manager EQUAL "1") + if(idf_component_manager EQUAL 1) # Call for component manager once again to inject dependencies idf_build_get_property(python PYTHON) execute_process(COMMAND ${python} diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index af7a461098..8c47b1545a 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -37,6 +37,13 @@ endif() # value passed externally. __target_init() +# Enable the component manager for regular projects if not explicitly disabled. +if(NOT "$ENV{IDF_COMPONENT_MANAGER}" EQUAL "0") + idf_build_set_property(IDF_COMPONENT_MANAGER 1) +endif() +# Set component manager interface version +idf_build_set_property(__COMPONENT_MANAGER_INTERFACE_VERSION 0) + # # Get the project version from either a version file or the Git revision. This is passed # to the idf_build_process call. Dependencies are also set here for when the version file @@ -173,8 +180,6 @@ function(__project_init components_var test_components_var) endif() endfunction() - idf_build_set_property(IDF_COMPONENT_MANAGER "$ENV{IDF_COMPONENT_MANAGER}") - # Add component directories to the build, given the component filters, exclusions # extra directories, etc. passed from the root CMakeLists.txt. if(COMPONENT_DIRS) @@ -189,39 +194,6 @@ function(__project_init components_var test_components_var) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/idf_project.yml") set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/dependencies.lock") - idf_build_get_property(idf_component_manager IDF_COMPONENT_MANAGER) - if(idf_component_manager) - if(idf_component_manager EQUAL "0") - message(VERBOSE "IDF Component manager was explicitly disabled by setting IDF_COMPONENT_MANAGER=0") - elseif(idf_component_manager EQUAL "1") - set(managed_components_list_file ${CMAKE_BINARY_DIR}/managed_components_list.temp.cmake) - - # Call for package manager to prepare remote dependencies - execute_process(COMMAND ${PYTHON} - "-m" - "idf_component_manager.prepare_components" - "--project_dir=${CMAKE_CURRENT_LIST_DIR}" - "prepare_dependencies" - "--managed_components_list_file=${managed_components_list_file}" - RESULT_VARIABLE result - ERROR_VARIABLE error) - - if(NOT result EQUAL 0) - message(FATAL_ERROR "${error}") - endif() - - # Include managed components - include(${managed_components_list_file}) - file(REMOVE ${managed_components_list_file}) - else() - message(WARNING "IDF_COMPONENT_MANAGER environment variable is set to unknown value " - "\"${idf_component_manager}\". If you want to use component manager set it to 1.") - endif() - elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/idf_project.yml") - message(WARNING "\"idf_project.yml\" file is found in project directory, " - "but component manager is not enabled. Please set IDF_COMPONENT_MANAGER environment variable.") - endif() - # Look for components in the usual places: CMAKE_CURRENT_LIST_DIR/main, # CMAKE_CURRENT_LIST_DIR/components, and the extra component dirs if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/main")