Merge branch 'feature/enable_component_manager_by_default_for_pure_cmake' into 'master'

tools: Enable the component manager by default in CMake

Closes IDF-4322

See merge request espressif/esp-idf!17724
This commit is contained in:
Roland Dobai 2022-05-13 15:39:01 +08:00
commit 6cbe0ceaa7
5 changed files with 62 additions and 64 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

@ -138,6 +138,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()
@ -420,12 +421,9 @@ 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")
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 ${build_dir}/managed_components_list.temp.cmake) 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(local_components_list_file ${build_dir}/local_components_list.temp.yml)
@ -440,7 +438,8 @@ macro(idf_build_process target)
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)
execute_process(COMMAND ${python}
"-m" "-m"
"idf_component_manager.prepare_components" "idf_component_manager.prepare_components"
"--project_dir=${project_dir}" "--project_dir=${project_dir}"
@ -464,10 +463,8 @@ macro(idf_build_process target)
file(REMOVE ${managed_components_list_file}) file(REMOVE ${managed_components_list_file})
file(REMOVE ${local_components_list_file}) file(REMOVE ${local_components_list_file})
else() else()
message(WARNING "IDF_COMPONENT_MANAGER environment variable is set to unknown value " message(VERBOSE "IDF Component manager was explicitly disabled by setting IDF_COMPONENT_MANAGER=0")
"\"${idf_component_manager}\". If you want to use component manager set it to 1.")
endif()
else()
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

@ -224,8 +224,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

@ -663,6 +663,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')
@ -688,16 +689,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
# Optional load `pyclang` for additional clang-tidy related functionalities # Optional load `pyclang` for additional clang-tidy related functionalities
try: try:
@ -720,7 +715,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))
@ -804,7 +800,8 @@ def _find_usable_locale():
if __name__ == '__main__': if __name__ == '__main__':
try: try:
if 'MSYSTEM' in os.environ: if 'MSYSTEM' in os.environ:
print_warning('MSys/Mingw is no longer supported. Please follow the getting started guide of the ' print_warning(
'MSys/Mingw is no longer supported. Please follow the getting started guide of the '
'documentation in order to set up a suitiable environment, or continue at your own risk.') 'documentation in order to set up a suitiable environment, or continue at your own risk.')
elif os.name == 'posix' and not _valid_unicode_config(): elif os.name == 'posix' and not _valid_unicode_config():
# Trying to find best utf-8 locale available on the system and restart python with it # Trying to find best utf-8 locale available on the system and restart python with it