From b5d9df8b6f4158b8eddf7662ff379b917eeb7b30 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Tue, 15 Nov 2022 11:10:18 +0800 Subject: [PATCH] build_system: stop looking for sdkconfig file specified by env var `SDKCONFIG_DEFAULTS` in bootloader subproject --- tools/cmake/project.cmake | 9 ++++++++- tools/test_build_system/test_common.py | 20 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 1604b9840d..b0b8f405cb 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -396,7 +396,14 @@ macro(project project_name) # PROJECT_NAME is taken from the passed name from project() call # PROJECT_DIR is set to the current directory # PROJECT_VER is from the version text or git revision of the current repo - set(_sdkconfig_defaults "$ENV{SDKCONFIG_DEFAULTS}") + + # SDKCONFIG_DEFAULTS environment variable may specify a file name relative to the root of the project. + # When building the bootloader, ignore this variable, since: + # 1. The bootloader project uses an existing SDKCONFIG file from the top-level project + # 2. File specified by SDKCONFIG_DEFAULTS will not be found relative to the root of the bootloader project + if(NOT BOOTLOADER_BUILD) + set(_sdkconfig_defaults "$ENV{SDKCONFIG_DEFAULTS}") + endif() if(NOT _sdkconfig_defaults) if(EXISTS "${CMAKE_SOURCE_DIR}/sdkconfig.defaults") diff --git a/tools/test_build_system/test_common.py b/tools/test_build_system/test_common.py index bd50aeb8f1..2ed04639d2 100644 --- a/tools/test_build_system/test_common.py +++ b/tools/test_build_system/test_common.py @@ -5,7 +5,8 @@ import subprocess from pathlib import Path import pytest -from test_build_system_helpers import EnvDict, IdfPyFunc, get_snapshot, replace_in_file +from _pytest.monkeypatch import MonkeyPatch +from test_build_system_helpers import IdfPyFunc, get_snapshot, replace_in_file @pytest.mark.usefixtures('test_app_copy') @@ -34,7 +35,7 @@ def test_of_test_app_copy(idf_py: IdfPyFunc) -> None: @pytest.mark.usefixtures('test_app_copy') -def test_hints_no_color_output_when_noninteractive(idf_py: EnvDict) -> None: +def test_hints_no_color_output_when_noninteractive(idf_py: IdfPyFunc) -> None: """Check that idf.py hints don't include color escape codes in non-interactive builds""" # make the build fail in such a way that idf.py shows a hint @@ -55,3 +56,18 @@ def test_idf_copy(idf_copy: Path, idf_py: IdfPyFunc) -> None: # For example, we can check if idf.py build can work without the .git directory: shutil.rmtree(idf_copy / '.git', ignore_errors=True) idf_py('build') + + +def test_idf_build_with_env_var_sdkconfig_defaults( + test_app_copy: Path, + idf_py: IdfPyFunc, + monkeypatch: MonkeyPatch, +) -> None: + with open(test_app_copy / 'sdkconfig.test', 'w') as fw: + fw.write('CONFIG_BT_ENABLED=y') + + monkeypatch.setenv('SDKCONFIG_DEFAULTS', 'sdkconfig.test') + idf_py('build') + + with open(test_app_copy / 'sdkconfig') as fr: + assert 'CONFIG_BT_ENABLED=y' in fr.read()