From 60e9ec429d87664822e3002dbb04b2efe2dd750f Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Fri, 22 Aug 2025 15:11:14 +0200 Subject: [PATCH] fix: kconfig optional dependency in transitive dependency --- tools/cmake/component.cmake | 1 + .../test_component_manager.py | 48 ++++++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index 653533d3e9..37721f5555 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -243,6 +243,7 @@ function(__component_get_requirements) "idf_component_manager.prepare_components" "--project_dir=${project_dir}" "--lock_path=${DEPENDENCIES_LOCK}" + "--sdkconfig_json_file=${build_dir}/config/sdkconfig.json" "--interface_version=${component_manager_interface_version}" "inject_requirements" "--idf_path=${idf_path}" diff --git a/tools/test_build_system/test_component_manager.py b/tools/test_build_system/test_component_manager.py index e0b0d10ff1..5434bc6745 100644 --- a/tools/test_build_system/test_component_manager.py +++ b/tools/test_build_system/test_component_manager.py @@ -1,5 +1,6 @@ # SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 +import json import os.path from pathlib import Path @@ -40,7 +41,7 @@ def test_trimmed_components_still_passed_to_cmake(idf_py: IdfPyFunc, test_app_co idf_py('reconfigure') - with open('dependencies.lock', 'r') as f: + with open('dependencies.lock') as f: fs = f.read() assert ' example/cmp:' in fs @@ -58,7 +59,7 @@ class TestOptionalDependencyWithKconfig: idf_py('reconfigure') - with open('dependencies.lock', 'r') as f: + with open('dependencies.lock') as f: fs = f.read() assert ' example/cmp:' in fs @@ -72,7 +73,7 @@ class TestOptionalDependencyWithKconfig: idf_py('reconfigure') - with open('dependencies.lock', 'r') as f: + with open('dependencies.lock') as f: fs = f.read() assert ' example/cmp:' not in fs @@ -90,7 +91,7 @@ class TestOptionalDependencyWithKconfig: idf_py('reconfigure') - with open('dependencies.lock', 'r') as f: + with open('dependencies.lock') as f: fs = f.read() assert ' example/cmp:' in fs @@ -110,7 +111,7 @@ class TestOptionalDependencyWithKconfig: idf_py('reconfigure') - with open('dependencies.lock', 'r') as f: + with open('dependencies.lock') as f: fs = f.read() assert ' example/cmp:' in fs @@ -132,7 +133,7 @@ class TestOptionalDependencyWithKconfig: idf_py('reconfigure') - with open('dependencies.lock', 'r') as f: + with open('dependencies.lock') as f: fs = f.read() assert ' example/cmp:' in fs @@ -156,3 +157,38 @@ class TestOptionalDependencyWithKconfig: f'defined in {str(test_app_copy / "main" / "idf_component.yml")}' in res.stderr ) assert 'Missing required kconfig option after retry.' in res.stderr + + def test_kconfig_in_transitive_dependency(self, idf_py: IdfPyFunc, test_app_copy: Path) -> None: + idf_py('create-component', 'foo') + (test_app_copy / 'foo' / 'idf_component.yml').write_text(""" + dependencies: + example/cmp: + version: "*" + rules: + - if: $CONFIG{WHO_AM_I} == "foo" + + espressif/mdns: + version: "*" + require: public + rules: + - if: $CONFIG{WHO_AM_I} == "foo" + """) + (test_app_copy / 'foo' / 'Kconfig').write_text(""" + menu "foo component config" + config WHO_AM_I + string "Who am I" + default "foo" + endmenu + """) + + replace_in_file( + (test_app_copy / 'CMakeLists.txt'), + '# placeholder_before_include_project_cmake', + 'set(EXTRA_COMPONENT_DIRS foo)', + ) + + idf_py('reconfigure') + + data = json.load(open(test_app_copy / 'build' / 'project_description.json')) + assert ['example__cmp'] == data['build_component_info']['foo']['priv_reqs'] + assert ['espressif__mdns'] == data['build_component_info']['foo']['reqs']