From d2542dd5c5312656ebb7215b3574e19529c614ce Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Wed, 21 Feb 2024 11:45:17 +0100 Subject: [PATCH 1/2] test: improve test_dependency_lock test case --- .../test_build_system/test_component_manager.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tools/test_build_system/test_component_manager.py b/tools/test_build_system/test_component_manager.py index 396b9c3c1a..0af140f6dd 100644 --- a/tools/test_build_system/test_component_manager.py +++ b/tools/test_build_system/test_component_manager.py @@ -3,22 +3,17 @@ 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)', - ) - ) + replace_in_file( + test_app_copy / 'CMakeLists.txt', + search='# placeholder_after_include_project_cmake', + replace='idf_build_set_property(DEPENDENCIES_LOCK dependencies.lock.${IDF_TARGET})', + ) + idf_py('add-dependency', 'example/cmp') idf_py('fullclean') idf_py('reconfigure') assert os.path.isfile(test_app_copy / 'dependencies.lock.esp32') From 74843a442bc0dcf2d979076627be09fd0302b2b2 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Tue, 30 Jan 2024 14:56:58 +0100 Subject: [PATCH 2/2] fix: component manager load all component dirs even set(COMPONENTS ...) --- tools/cmake/build.cmake | 14 ++++++++-- tools/cmake/component.cmake | 3 +- .../test_component_manager.py | 28 ++++++++++++++++++- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 6435815353..0bafd9fcb1 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -516,9 +516,17 @@ macro(idf_build_process target) set(local_components_list_file ${build_dir}/local_components_list.temp.yml) set(__contents "components:\n") - foreach(__component_name ${components}) - idf_component_get_property(__component_dir ${__component_name} COMPONENT_DIR) - set(__contents "${__contents} - name: \"${__component_name}\"\n path: \"${__component_dir}\"\n") + idf_build_get_property(build_component_targets BUILD_COMPONENT_TARGETS) + foreach(__build_component_target ${build_component_targets}) + __component_get_property(__component_name ${__build_component_target} COMPONENT_NAME) + __component_get_property(__component_dir ${__build_component_target} COMPONENT_DIR) + + # Exclude components could be passed with -DEXCLUDE_COMPONENTS + # after the call to __component_add finished in the last run. + # Need to check if the component is excluded again + if(NOT __component_name IN_LIST EXCLUDE_COMPONENTS) + set(__contents "${__contents} - name: \"${__component_name}\"\n path: \"${__component_dir}\"\n") + endif() endforeach() file(WRITE ${local_components_list_file} "${__contents}") diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index 6f5f00efbc..1046364aca 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -192,8 +192,9 @@ function(__component_add component_dir prefix) # Set Kconfig related properties on the component __kconfig_component_init(${component_target}) - # set BUILD_COMPONENT_DIRS build property + # these two properties are used to keep track of the components known to the build system idf_build_set_property(BUILD_COMPONENT_DIRS ${component_dir} APPEND) + idf_build_set_property(BUILD_COMPONENT_TARGETS ${component_target} APPEND) endfunction() # diff --git a/tools/test_build_system/test_component_manager.py b/tools/test_build_system/test_component_manager.py index 0af140f6dd..ace7f85524 100644 --- a/tools/test_build_system/test_component_manager.py +++ b/tools/test_build_system/test_component_manager.py @@ -1,9 +1,10 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 import os.path from pathlib import Path from test_build_system_helpers import IdfPyFunc +from test_build_system_helpers import replace_in_file def test_dependency_lock(idf_py: IdfPyFunc, test_app_copy: Path) -> None: @@ -18,3 +19,28 @@ def test_dependency_lock(idf_py: IdfPyFunc, test_app_copy: Path) -> None: idf_py('reconfigure') assert os.path.isfile(test_app_copy / 'dependencies.lock.esp32') assert not os.path.isfile(test_app_copy / 'dependencies.lock') + + +def test_trimmed_components_still_passed_to_cmake(idf_py: IdfPyFunc, test_app_copy: Path) -> None: + replace_in_file( + test_app_copy / 'CMakeLists.txt', + search='# placeholder_after_include_project_cmake', + replace='set(COMPONENTS main)', + ) + + replace_in_file( + test_app_copy / 'main' / 'CMakeLists.txt', + search='# placeholder_inside_idf_component_register', + replace='REQUIRES foo', + ) + + os.makedirs(test_app_copy / 'components') + idf_py('create-component', '-C', 'components', 'foo') + idf_py('add-dependency', '--component', 'foo', 'example/cmp') + + idf_py('reconfigure') + + with open('dependencies.lock', 'r') as f: + fs = f.read() + + assert ' example/cmp:' in fs