feat: support kconfig in component manager

This commit is contained in:
Fu Hanxi
2025-09-01 09:43:09 +02:00
parent 70a6909bef
commit d595ea9b2b
4 changed files with 175 additions and 22 deletions
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import os.path
from pathlib import Path
@@ -44,3 +44,115 @@ def test_trimmed_components_still_passed_to_cmake(idf_py: IdfPyFunc, test_app_co
fs = f.read()
assert ' example/cmp:' in fs
class TestOptionalDependencyWithKconfig:
def test_direct_kconfig(self, idf_py: IdfPyFunc, test_app_copy: Path) -> None:
(test_app_copy / 'main' / 'idf_component.yml').write_text("""
dependencies:
example/cmp:
version: "*"
rules:
- if: $CONFIG{BOOTLOADER_PROJECT_VER} == 1
""")
idf_py('reconfigure')
with open('dependencies.lock', 'r') as f:
fs = f.read()
assert ' example/cmp:' in fs
(test_app_copy / 'main' / 'idf_component.yml').write_text("""
dependencies:
example/cmp:
version: "*"
rules:
- if: $CONFIG{BOOTLOADER_PROJECT_VER} != 1
""")
idf_py('reconfigure')
with open('dependencies.lock', 'r') as f:
fs = f.read()
assert ' example/cmp:' not in fs
def test_missing_kconfig_first_round(self, idf_py: IdfPyFunc, test_app_copy: Path) -> None:
(test_app_copy / 'main' / 'idf_component.yml').write_text("""
dependencies:
espressif/mdns:
version: "*"
example/cmp:
version: "*"
rules:
- if: $CONFIG{MDNS_MAX_SERVICES} == 10 # mdns kconfig CONFIG_MDNS_MAX_SERVICES default to 10
""")
idf_py('reconfigure')
with open('dependencies.lock', 'r') as f:
fs = f.read()
assert ' example/cmp:' in fs
def test_kconfig_load_existing_sdkconfig_defaults(self, idf_py: IdfPyFunc, test_app_copy: Path) -> None:
(test_app_copy / 'main' / 'idf_component.yml').write_text("""
dependencies:
example/cmp:
version: "*"
rules:
- if: $CONFIG{BOOTLOADER_LOG_LEVEL_WARN} == True
""")
(test_app_copy / 'sdkconfig.defaults').write_text("""
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
CONFIG_LOG_DEFAULT_LEVEL_WARN=y
""")
idf_py('reconfigure')
with open('dependencies.lock', 'r') as f:
fs = f.read()
assert ' example/cmp:' in fs
def test_kconfig_load_missing_sdkconfig_defaults(self, idf_py: IdfPyFunc, test_app_copy: Path) -> None:
(test_app_copy / 'main' / 'idf_component.yml').write_text("""
dependencies:
espressif/mdns:
version: "*"
example/cmp:
version: "*"
rules:
- if: $CONFIG{MDNS_MAX_SERVICES} == 30 # mdns kconfig CONFIG_MDNS_MAX_SERVICES default to 10
""")
(test_app_copy / 'sdkconfig.defaults').write_text("""
CONFIG_MDNS_MAX_SERVICES=30
""")
idf_py('reconfigure')
with open('dependencies.lock', 'r') as f:
fs = f.read()
assert ' example/cmp:' in fs
def test_missing_kconfig_second_round(self, idf_py: IdfPyFunc, test_app_copy: Path) -> None:
(test_app_copy / 'main' / 'idf_component.yml').write_text("""
dependencies:
espressif/mdns:
version: "*"
example/cmp:
version: "*"
rules:
- if: $CONFIG{OF_COURSE_NO_ONE_USE_FOO} == "bar"
""")
res = idf_py('reconfigure', check=False)
assert res.returncode != 0
assert (
f'OF_COURSE_NO_ONE_USE_FOO, introduced by example/cmp, '
f'defined in {str(test_app_copy / "main" / "idf_component.yml")}' in res.stderr
)
assert 'Missing required kconfig option after retry.' in res.stderr