From 17224f325450a001c4744064470cb6813b1c8514 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Wed, 31 Aug 2022 16:47:36 +0800 Subject: [PATCH] component manager: add build property `DEPENDENCIES_LOCK` closes https://github.com/espressif/esp-idf/issues/9394 --- docs/en/api-guides/build-system.rst | 1 + .../tools/idf-component-manager.rst | 2 ++ docs/sphinx-known-warnings.txt | 1 + tools/cmake/build.cmake | 3 +++ tools/cmake/component.cmake | 1 + tools/cmake/project.cmake | 2 +- .../test_component_manager.py | 25 +++++++++++++++++++ 7 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tools/test_build_system/test_component_manager.py diff --git a/docs/en/api-guides/build-system.rst b/docs/en/api-guides/build-system.rst index 242fe2c5a2..f4d9cb9257 100644 --- a/docs/en/api-guides/build-system.rst +++ b/docs/en/api-guides/build-system.rst @@ -1177,6 +1177,7 @@ These are properties that describe the build. Values of build properties can be - COMPILE_OPTIONS - compile options applied to all components' source files, regardless of it being C or C++ - COMPILE_DEFINITIONS - compile definitions applied to all component source files - CXX_COMPILE_OPTIONS - compile options applied to all components' C++ source files +- DEPENDENCIES_LOCK - lock file path used in component manager. The default value is `dependencies.lock` under the project path. - EXECUTABLE - project executable; set by call to ``idf_build_executable`` - EXECUTABLE_NAME - name of project executable without extension; set by call to ``idf_build_executable`` - EXECUTABLE_DIR - path containing the output executable diff --git a/docs/en/api-guides/tools/idf-component-manager.rst b/docs/en/api-guides/tools/idf-component-manager.rst index fcd268c380..fbe42bfcc0 100644 --- a/docs/en/api-guides/tools/idf-component-manager.rst +++ b/docs/en/api-guides/tools/idf-component-manager.rst @@ -23,6 +23,8 @@ When CMake configures the project (e.g. ``idf.py reconfigure``) component manage The lock-file ``dependencies.lock`` and content of ``managed_components`` directory is not supposed to be modified by a user. When the component manager runs it always make sure they are up to date. If these files were accidentally modified it's possible to re-run the component manager by triggering CMake with ``idf.py reconfigure`` +You may set build property ``DEPENDENCIES_LOCK`` to specify the lock-file path in the top-level CMakeLists.txt. For example, adding ``idf_build_set_property(DEPENDENCIES_LOCK dependencies.lock.${IDF_TARGET})`` before ``project(PROJECT_NAME)`` could help generate different lock files for different targets. + Defining dependencies in the manifest ===================================== diff --git a/docs/sphinx-known-warnings.txt b/docs/sphinx-known-warnings.txt index e2cc29704e..757841e28a 100644 --- a/docs/sphinx-known-warnings.txt +++ b/docs/sphinx-known-warnings.txt @@ -6,6 +6,7 @@ # # Warnings in this file must be in the same overall order as the log file. # +idf-component-manager.rst: WARNING: Badly formated string substitution: {IDF_TARGET} esp_ble_mesh_defs.inc:line: WARNING: Duplicate C++ declaration, also defined at api-reference/bluetooth/esp-ble-mesh:line. Declaration is '.. cpp:member:: uint16_t model_id'. rmt_encoder.inc:line: WARNING: Duplicate C++ declaration, also defined at api-reference/peripherals/rmt:line. diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 1224cc7510..3968dae1de 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -524,10 +524,13 @@ macro(idf_build_process target) # Call for the component manager to prepare remote dependencies idf_build_get_property(python PYTHON) idf_build_get_property(component_manager_interface_version __COMPONENT_MANAGER_INTERFACE_VERSION) + idf_build_get_property(dependencies_lock_file DEPENDENCIES_LOCK) + execute_process(COMMAND ${python} "-m" "idf_component_manager.prepare_components" "--project_dir=${project_dir}" + "--lock_path=${dependencies_lock_file}" "--interface_version=${component_manager_interface_version}" "prepare_dependencies" "--local_components_list_file=${local_components_list_file}" diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index 218d1b4d0e..36132d31d0 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -237,6 +237,7 @@ function(__component_get_requirements) "-m" "idf_component_manager.prepare_components" "--project_dir=${project_dir}" + "--lock_path=${DEPENDENCIES_LOCK}" "--interface_version=${component_manager_interface_version}" "inject_requirements" "--idf_path=${idf_path}" diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 49b75bc77d..7b5e8fb7c9 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -44,7 +44,7 @@ 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 1) +idf_build_set_property(__COMPONENT_MANAGER_INTERFACE_VERSION 2) # # Get the project version from either a version file or the Git revision. This is passed diff --git a/tools/test_build_system/test_component_manager.py b/tools/test_build_system/test_component_manager.py new file mode 100644 index 0000000000..396b9c3c1a --- /dev/null +++ b/tools/test_build_system/test_component_manager.py @@ -0,0 +1,25 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 +import os.path +from pathlib import Path + +import pytest +from test_build_system_helpers import IdfPyFunc + + +@pytest.mark.test_app_copy('examples/get-started/blink') +def test_dependency_lock(idf_py: IdfPyFunc, test_app_copy: Path) -> None: + with open(test_app_copy / 'CMakeLists.txt', 'r+') as fw: + data = fw.read() + fw.seek(0) + fw.write( + data.replace( + 'project(blink)', + 'idf_build_set_property(DEPENDENCIES_LOCK dependencies.lock.${IDF_TARGET})\nproject(blink)', + ) + ) + + idf_py('fullclean') + idf_py('reconfigure') + assert os.path.isfile(test_app_copy / 'dependencies.lock.esp32') + assert not os.path.isfile(test_app_copy / 'dependencies.lock')