Merge branch 'feature/enable_component_manager_by_default_for_pure_cmake_v4.4' into 'release/v4.4'

tools: Enable the component manager by default in CMake (v4.4)

See merge request espressif/esp-idf!18121
This commit is contained in:
Roland Dobai 2022-05-17 18:42:19 +08:00
commit fe1cf490b9
5 changed files with 59 additions and 62 deletions

View File

@ -6,13 +6,6 @@ The IDF Component manager is a tool that downloads dependencies for any ESP-IDF
A list of components can be found on `<https://components.espressif.com/>`_ A list of components can be found on `<https://components.espressif.com/>`_
Activating the Component Manager
================================
If CMake is started using ``idf.py`` or `ESP-IDF VSCode Extension <https://marketplace.visualstudio.com/items?itemName=espressif.esp-idf-extension>`_ then the component manager will be activated by default.
If CMake is used directly or with some CMake-based IDE like CLion, it's necessary to set the ``IDF_COMPONENT_MANAGER`` environment variable to ``1`` to enable the component manager integration with the build system.
Using with a project Using with a project
==================== ====================
@ -70,3 +63,8 @@ Defining dependencies in the manifest
# # with relative or absolute path # # with relative or absolute path
# some_local_component: # some_local_component:
# path: ../../projects/component # path: ../../projects/component
Disabling the Component Manager
===============================
The component manager can be explicitly disabled by setting ``IDF_COMPONENT_MANAGER`` environment variable to ``0``.

View File

@ -141,6 +141,7 @@ function(__build_init idf_path)
idf_build_set_property(__PREFIX idf) idf_build_set_property(__PREFIX idf)
idf_build_set_property(__CHECK_PYTHON 1) idf_build_set_property(__CHECK_PYTHON 1)
idf_build_set_property(__ENABLE_COMPONENT_MANAGER 0)
__build_set_default_build_specifications() __build_set_default_build_specifications()
@ -421,54 +422,50 @@ macro(idf_build_process target)
endif() endif()
# Call for component manager to download dependencies for all components # Call for component manager to download dependencies for all components
idf_build_set_property(IDF_COMPONENT_MANAGER "$ENV{IDF_COMPONENT_MANAGER}") idf_build_get_property(enable_component_manager __ENABLE_COMPONENT_MANAGER)
idf_build_get_property(idf_component_manager IDF_COMPONENT_MANAGER) if(enable_component_manager)
if(idf_component_manager) idf_build_get_property(build_dir BUILD_DIR)
if(idf_component_manager EQUAL "0") set(managed_components_list_file ${build_dir}/managed_components_list.temp.cmake)
message(VERBOSE "IDF Component manager was explicitly disabled by setting IDF_COMPONENT_MANAGER=0") set(local_components_list_file ${build_dir}/local_components_list.temp.yml)
elseif(idf_component_manager EQUAL "1")
set(managed_components_list_file ${build_dir}/managed_components_list.temp.cmake)
set(local_components_list_file ${build_dir}/local_components_list.temp.yml)
set(__contents "components:\n") set(__contents "components:\n")
idf_build_get_property(__component_targets __COMPONENT_TARGETS) idf_build_get_property(__component_targets __COMPONENT_TARGETS)
foreach(__component_target ${__component_targets}) foreach(__component_target ${__component_targets})
__component_get_property(__component_name ${__component_target} COMPONENT_NAME) __component_get_property(__component_name ${__component_target} COMPONENT_NAME)
__component_get_property(__component_dir ${__component_target} COMPONENT_DIR) __component_get_property(__component_dir ${__component_target} COMPONENT_DIR)
set(__contents "${__contents} - name: \"${__component_name}\"\n path: \"${__component_dir}\"\n") set(__contents "${__contents} - name: \"${__component_name}\"\n path: \"${__component_dir}\"\n")
endforeach() endforeach()
file(WRITE ${local_components_list_file} "${__contents}") file(WRITE ${local_components_list_file} "${__contents}")
# Call for the component manager to prepare remote dependencies # Call for the component manager to prepare remote dependencies
execute_process(COMMAND ${PYTHON} idf_build_get_property(python PYTHON)
"-m" execute_process(COMMAND ${python}
"idf_component_manager.prepare_components" "-m"
"--project_dir=${project_dir}" "idf_component_manager.prepare_components"
"prepare_dependencies" "--project_dir=${project_dir}"
"--local_components_list_file=${local_components_list_file}" "prepare_dependencies"
"--managed_components_list_file=${managed_components_list_file}" "--local_components_list_file=${local_components_list_file}"
RESULT_VARIABLE result "--managed_components_list_file=${managed_components_list_file}"
ERROR_VARIABLE error) RESULT_VARIABLE result
ERROR_VARIABLE error)
if(NOT result EQUAL 0) if(NOT result EQUAL 0)
message(FATAL_ERROR "${error}") message(FATAL_ERROR "${error}")
endif()
include(${managed_components_list_file})
# Add managed components to list of all components
# `managed_components` contains the list of components installed by the component manager
# It is defined in the temporary managed_components_list_file file
set(__COMPONENTS "${__COMPONENTS};${managed_components}")
file(REMOVE ${managed_components_list_file})
file(REMOVE ${local_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() endif()
include(${managed_components_list_file})
# Add managed components to list of all components
# `managed_components` contains the list of components installed by the component manager
# It is defined in the temporary managed_components_list_file file
set(__COMPONENTS "${__COMPONENTS};${managed_components}")
file(REMOVE ${managed_components_list_file})
file(REMOVE ${local_components_list_file})
else() else()
message(VERBOSE "IDF Component manager was explicitly disabled by setting IDF_COMPONENT_MANAGER=0")
idf_build_get_property(__component_targets __COMPONENT_TARGETS) idf_build_get_property(__component_targets __COMPONENT_TARGETS)
set(__components_with_manifests "") set(__components_with_manifests "")
foreach(__component_target ${__component_targets}) foreach(__component_target ${__component_targets})

View File

@ -219,8 +219,8 @@ function(__component_get_requirements)
message(FATAL_ERROR "${error}") message(FATAL_ERROR "${error}")
endif() endif()
idf_build_get_property(idf_component_manager IDF_COMPONENT_MANAGER) idf_build_get_property(enable_component_manager __ENABLE_COMPONENT_MANAGER)
if(idf_component_manager AND idf_component_manager EQUAL "1") if(enable_component_manager)
# Call for component manager once again to inject dependencies # Call for component manager once again to inject dependencies
idf_build_get_property(python PYTHON) idf_build_get_property(python PYTHON)
execute_process(COMMAND ${python} execute_process(COMMAND ${python}

View File

@ -38,6 +38,12 @@ else()
idf_build_set_property(EXTRA_CMAKE_ARGS "") idf_build_set_property(EXTRA_CMAKE_ARGS "")
endif() endif()
# Enable the component manager for regular projects if not explicitly disabled.
if(NOT "$ENV{IDF_COMPONENT_MANAGER}" EQUAL "0")
idf_build_set_property(__ENABLE_COMPONENT_MANAGER 1)
endif()
# #
# Get the project version from either a version file or the Git revision. This is passed # 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 # to the idf_build_process call. Dependencies are also set here for when the version file

View File

@ -651,6 +651,7 @@ def init_cli(verbose_output=None):
@click.option('-C', '--project-dir', default=os.getcwd(), type=click.Path()) @click.option('-C', '--project-dir', default=os.getcwd(), type=click.Path())
def parse_project_dir(project_dir): def parse_project_dir(project_dir):
return realpath(project_dir) return realpath(project_dir)
# Set `complete_var` to not existing environment variable name to prevent early cmd completion # Set `complete_var` to not existing environment variable name to prevent early cmd completion
project_dir = parse_project_dir(standalone_mode=False, complete_var='_IDF.PY_COMPLETE_NOT_EXISTING') project_dir = parse_project_dir(standalone_mode=False, complete_var='_IDF.PY_COMPLETE_NOT_EXISTING')
@ -676,16 +677,10 @@ def init_cli(verbose_output=None):
if name.endswith('_ext'): if name.endswith('_ext'):
extensions.append((name, import_module(name))) extensions.append((name, import_module(name)))
# Load component manager if available and not explicitly disabled # Load component manager idf.py extensions if not explicitly disabled
if os.getenv('IDF_COMPONENT_MANAGER', None) != '0': if os.getenv('IDF_COMPONENT_MANAGER') != '0':
try: from idf_component_manager import idf_extensions
from idf_component_manager import idf_extensions extensions.append(('component_manager_ext', idf_extensions))
extensions.append(('component_manager_ext', idf_extensions))
os.environ['IDF_COMPONENT_MANAGER'] = '1'
except ImportError:
pass
for name, extension in extensions: for name, extension in extensions:
try: try:
@ -700,7 +695,8 @@ def init_cli(verbose_output=None):
from idf_ext import action_extensions from idf_ext import action_extensions
except ImportError: except ImportError:
print_warning('Error importing extension file idf_ext.py. Skipping.') print_warning('Error importing extension file idf_ext.py. Skipping.')
print_warning("Please make sure that it contains implementation (even if it's empty) of add_action_extensions") print_warning(
"Please make sure that it contains implementation (even if it's empty) of add_action_extensions")
try: try:
all_actions = merge_action_lists(all_actions, action_extensions(all_actions, project_dir)) all_actions = merge_action_lists(all_actions, action_extensions(all_actions, project_dir))