mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 19:13:21 +00:00
Merge branch 'test/fix_cmakev2_import_lib' into 'master'
fix(cmakev2): propagate IDF_TOOLCHAIN selection to sdkconfig generation Closes IDFCI-10438 See merge request espressif/esp-idf!47590
This commit is contained in:
@@ -317,6 +317,13 @@ function(__init_toolchain)
|
||||
idf_die("Toolchain file ${toolchain_file} not found")
|
||||
endif()
|
||||
|
||||
# IDF_TOOLCHAIN applies to Espressif targets only; on linux (host build)
|
||||
# it must stay empty so Kconfig leaves both CONFIG_IDF_TOOLCHAIN_GCC and
|
||||
# CONFIG_IDF_TOOLCHAIN_CLANG unset.
|
||||
if(NOT "${idf_target}" STREQUAL "linux")
|
||||
set(IDF_TOOLCHAIN "${toolchain}" CACHE STRING "IDF Build Toolchain Type" FORCE)
|
||||
endif()
|
||||
|
||||
set(CMAKE_TOOLCHAIN_FILE "${toolchain_file}" PARENT_SCOPE)
|
||||
idf_build_set_property(IDF_TOOLCHAIN_FILE "${toolchain_file}")
|
||||
endfunction()
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
# SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import logging
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from test_build_system_helpers import EnvDict
|
||||
from test_build_system_helpers import file_contains
|
||||
from test_build_system_helpers import run_idf_py
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('test_app_copy')
|
||||
def test_idf_toolchain_gcc_propagation(default_idf_env: EnvDict) -> None:
|
||||
"""IDF_TOOLCHAIN=gcc is propagated to the CMake cache and to sdkconfig."""
|
||||
logging.info('Testing IDF_TOOLCHAIN=gcc propagation')
|
||||
|
||||
default_idf_env.pop('IDF_TOOLCHAIN', None)
|
||||
run_idf_py('reconfigure', env=default_idf_env)
|
||||
|
||||
assert file_contains('build/CMakeCache.txt', 'IDF_TOOLCHAIN:STRING=gcc'), (
|
||||
'IDF_TOOLCHAIN CMake cache variable must be "gcc" when building with the default toolchain'
|
||||
)
|
||||
|
||||
sdkconfig_h = Path('build/config/sdkconfig.h').read_text()
|
||||
assert '#define CONFIG_IDF_TOOLCHAIN "gcc"' in sdkconfig_h, (
|
||||
'CONFIG_IDF_TOOLCHAIN must be "gcc" in sdkconfig.h for the default toolchain'
|
||||
)
|
||||
assert '#define CONFIG_IDF_TOOLCHAIN_GCC 1' in sdkconfig_h, (
|
||||
'CONFIG_IDF_TOOLCHAIN_GCC must be set in sdkconfig.h for the default toolchain'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('test_app_copy')
|
||||
def test_idf_toolchain_clang_propagation(default_idf_env: EnvDict) -> None:
|
||||
"""IDF_TOOLCHAIN=clang is propagated to the CMake cache and to sdkconfig,
|
||||
and selects a libc implementation that is compatible with clang."""
|
||||
clang_path = shutil.which('clang')
|
||||
if clang_path is None or 'esp-clang' not in str(Path(clang_path).resolve()):
|
||||
pytest.skip('Espressif clang (esp-clang) not available in PATH')
|
||||
|
||||
logging.info('Testing IDF_TOOLCHAIN=clang propagation')
|
||||
|
||||
default_idf_env['IDF_TOOLCHAIN'] = 'clang'
|
||||
run_idf_py('reconfigure', env=default_idf_env)
|
||||
|
||||
assert file_contains('build/CMakeCache.txt', 'IDF_TOOLCHAIN:STRING=clang'), (
|
||||
'IDF_TOOLCHAIN CMake cache variable must be "clang" when IDF_TOOLCHAIN=clang is set'
|
||||
)
|
||||
|
||||
sdkconfig_h = Path('build/config/sdkconfig.h').read_text()
|
||||
assert '#define CONFIG_IDF_TOOLCHAIN "clang"' in sdkconfig_h, (
|
||||
'CONFIG_IDF_TOOLCHAIN must be "clang" in sdkconfig.h when IDF_TOOLCHAIN=clang is set'
|
||||
)
|
||||
assert '#define CONFIG_IDF_TOOLCHAIN_CLANG 1' in sdkconfig_h, (
|
||||
'CONFIG_IDF_TOOLCHAIN_CLANG must be set in sdkconfig.h when IDF_TOOLCHAIN=clang is set'
|
||||
)
|
||||
assert '#define CONFIG_LIBC_NEWLIB 1' in sdkconfig_h, 'CONFIG_LIBC_NEWLIB must be selected for clang builds'
|
||||
Reference in New Issue
Block a user