tools: Enable the component manager by default in CMake

This commit is contained in:
Sergei Silnov 2022-04-08 17:58:05 +02:00
parent faed2a44aa
commit 69cf85e6a6
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/>`_
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
====================
@ -70,3 +63,8 @@ Defining dependencies in the manifest
# # with relative or absolute path
# some_local_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(__CHECK_PYTHON 1)
idf_build_set_property(__ENABLE_COMPONENT_MANAGER 0)
__build_set_default_build_specifications()
@ -421,54 +422,50 @@ macro(idf_build_process target)
endif()
# 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(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 ${build_dir}/managed_components_list.temp.cmake)
set(local_components_list_file ${build_dir}/local_components_list.temp.yml)
idf_build_get_property(enable_component_manager __ENABLE_COMPONENT_MANAGER)
if(enable_component_manager)
idf_build_get_property(build_dir BUILD_DIR)
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")
idf_build_get_property(__component_targets __COMPONENT_TARGETS)
foreach(__component_target ${__component_targets})
__component_get_property(__component_name ${__component_target} COMPONENT_NAME)
__component_get_property(__component_dir ${__component_target} COMPONENT_DIR)
set(__contents "${__contents} - name: \"${__component_name}\"\n path: \"${__component_dir}\"\n")
endforeach()
set(__contents "components:\n")
idf_build_get_property(__component_targets __COMPONENT_TARGETS)
foreach(__component_target ${__component_targets})
__component_get_property(__component_name ${__component_target} COMPONENT_NAME)
__component_get_property(__component_dir ${__component_target} COMPONENT_DIR)
set(__contents "${__contents} - name: \"${__component_name}\"\n path: \"${__component_dir}\"\n")
endforeach()
file(WRITE ${local_components_list_file} "${__contents}")
file(WRITE ${local_components_list_file} "${__contents}")
# Call for the component manager to prepare remote dependencies
execute_process(COMMAND ${PYTHON}
"-m"
"idf_component_manager.prepare_components"
"--project_dir=${project_dir}"
"prepare_dependencies"
"--local_components_list_file=${local_components_list_file}"
"--managed_components_list_file=${managed_components_list_file}"
RESULT_VARIABLE result
ERROR_VARIABLE error)
# Call for the component manager to prepare remote dependencies
idf_build_get_property(python PYTHON)
execute_process(COMMAND ${python}
"-m"
"idf_component_manager.prepare_components"
"--project_dir=${project_dir}"
"prepare_dependencies"
"--local_components_list_file=${local_components_list_file}"
"--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_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.")
if(NOT result EQUAL 0)
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(VERBOSE "IDF Component manager was explicitly disabled by setting IDF_COMPONENT_MANAGER=0")
idf_build_get_property(__component_targets __COMPONENT_TARGETS)
set(__components_with_manifests "")
foreach(__component_target ${__component_targets})

View File

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

View File

@ -38,6 +38,12 @@ else()
idf_build_set_property(EXTRA_CMAKE_ARGS "")
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
# 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())
def parse_project_dir(project_dir):
return realpath(project_dir)
# 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')
@ -688,16 +689,10 @@ def init_cli(verbose_output=None):
if name.endswith('_ext'):
extensions.append((name, import_module(name)))
# Load component manager if available and not explicitly disabled
if os.getenv('IDF_COMPONENT_MANAGER', None) != '0':
try:
from idf_component_manager import idf_extensions
extensions.append(('component_manager_ext', idf_extensions))
os.environ['IDF_COMPONENT_MANAGER'] = '1'
except ImportError:
pass
# Load component manager idf.py extensions if not explicitly disabled
if os.getenv('IDF_COMPONENT_MANAGER') != '0':
from idf_component_manager import idf_extensions
extensions.append(('component_manager_ext', idf_extensions))
# Optional load `pyclang` for additional clang-tidy related functionalities
try:
@ -720,7 +715,8 @@ def init_cli(verbose_output=None):
from idf_ext import action_extensions
except ImportError:
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:
all_actions = merge_action_lists(all_actions, action_extensions(all_actions, project_dir))
@ -804,8 +800,9 @@ def _find_usable_locale():
if __name__ == '__main__':
try:
if 'MSYSTEM' in os.environ:
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.')
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.')
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
best_locale = _find_usable_locale()