diff --git a/docs/en/api-guides/tools/idf-component-manager.rst b/docs/en/api-guides/tools/idf-component-manager.rst
index 3700256194..fcd268c380 100644
--- a/docs/en/api-guides/tools/idf-component-manager.rst
+++ b/docs/en/api-guides/tools/idf-component-manager.rst
@@ -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 ``_
-Activating the Component Manager
-================================
-
-If CMake is started using ``idf.py`` or `ESP-IDF VSCode 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``.
diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake
index 3352238ef6..52fa13ef56 100644
--- a/tools/cmake/build.cmake
+++ b/tools/cmake/build.cmake
@@ -141,6 +141,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})
diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake
index 8bdba18be2..915f1d32c2 100644
--- a/tools/cmake/component.cmake
+++ b/tools/cmake/component.cmake
@@ -219,8 +219,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}
diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake
index eed3def77a..707e3c62ab 100644
--- a/tools/cmake/project.cmake
+++ b/tools/cmake/project.cmake
@@ -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
diff --git a/tools/idf.py b/tools/idf.py
index 3e3986ac5e..f38faf5b98 100755
--- a/tools/idf.py
+++ b/tools/idf.py
@@ -651,6 +651,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')
@@ -676,16 +677,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))
for name, extension in extensions:
try:
@@ -700,7 +695,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))