Skip to content

Commit c6a0d91

Browse files
committed
change: Support misspelled Kconfig[.projbuild] file names
If the name is misspelled, CMake prints out a warning. Original issue: espressif/esp-idf-kconfig#14
1 parent 44895c0 commit c6a0d91

File tree

3 files changed

+89
-23
lines changed

3 files changed

+89
-23
lines changed

tools/cmake/kconfig.cmake

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,37 @@ endfunction()
1515
#
1616
function(__kconfig_component_init component_target)
1717
__component_get_property(component_dir ${component_target} COMPONENT_DIR)
18-
file(GLOB kconfig "${component_dir}/Kconfig")
18+
file(GLOB all_files "${component_dir}/*")
19+
20+
set(kconfig "")
21+
set(kconfig_projbuild "")
22+
23+
foreach(_file IN LISTS all_files)
24+
get_filename_component(_fname ${_file} NAME)
25+
string(TOLOWER "${_fname}" _fname_lowercase)
26+
if(_fname_lowercase STREQUAL "kconfig")
27+
list(APPEND kconfig "${_file}")
28+
if(NOT _fname STREQUAL "Kconfig")
29+
message(WARNING
30+
"${_fname} file should be named 'Kconfig' (uppercase K, the rest lowercase)."
31+
" Full path to the file: ${_file}")
32+
endif()
33+
elseif(_fname_lowercase STREQUAL "kconfig.projbuild")
34+
list(APPEND kconfig_projbuild "${_file}")
35+
if(NOT _fname STREQUAL "Kconfig.projbuild")
36+
message(WARNING
37+
"${_fname} file should be named 'Kconfig.projbuild' (uppercase K, the rest lowercase)."
38+
" Full path to the file: ${_file}")
39+
endif()
40+
endif()
41+
endforeach()
42+
1943
list(SORT kconfig)
2044
__component_set_property(${component_target} KCONFIG "${kconfig}")
21-
file(GLOB kconfig "${component_dir}/Kconfig.projbuild")
22-
list(SORT kconfig)
23-
__component_set_property(${component_target} KCONFIG_PROJBUILD "${kconfig}")
45+
46+
list(SORT kconfig_projbuild)
47+
__component_set_property(${component_target} KCONFIG_PROJBUILD "${kconfig_projbuild}")
48+
2449
file(GLOB sdkconfig_rename "${component_dir}/sdkconfig.rename")
2550
file(GLOB sdkconfig_rename_target "${component_dir}/sdkconfig.rename.${IDF_TARGET}")
2651

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Misspelled Kconfig file checks whether it is picked up by the build system
2+
config FROM_MISSPELLED_KCONFIG
3+
bool "From misspelled Kconfig"
4+
default y

tools/test_build_system/test_build.py

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
1+
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
22
# SPDX-License-Identifier: Apache-2.0
33
import logging
44
import os
@@ -12,12 +12,12 @@
1212

1313
import pytest
1414
from test_build_system_helpers import APP_BINS
15-
from test_build_system_helpers import append_to_file
1615
from test_build_system_helpers import BOOTLOADER_BINS
16+
from test_build_system_helpers import PARTITION_BIN
17+
from test_build_system_helpers import IdfPyFunc
18+
from test_build_system_helpers import append_to_file
1719
from test_build_system_helpers import file_contains
1820
from test_build_system_helpers import get_idf_build_env
19-
from test_build_system_helpers import IdfPyFunc
20-
from test_build_system_helpers import PARTITION_BIN
2121
from test_build_system_helpers import replace_in_file
2222
from test_build_system_helpers import run_cmake_and_build
2323

@@ -35,7 +35,9 @@ def test_build_alternative_directories(idf_py: IdfPyFunc, func_work_dir: Path, t
3535
assert os.listdir(alt_build_dir) != [], 'No files found in new build directory!'
3636
default_build_dir = test_app_copy / 'build'
3737
if default_build_dir.exists():
38-
assert os.listdir(default_build_dir) == [], f'Some files were incorrectly put into the default build directory: {default_build_dir}'
38+
assert os.listdir(default_build_dir) == [], (
39+
f'Some files were incorrectly put into the default build directory: {default_build_dir}'
40+
)
3941
except Exception:
4042
raise
4143
else:
@@ -146,10 +148,17 @@ def test_build_with_sdkconfig_build_abspath(idf_py: IdfPyFunc, test_app_copy: Pa
146148

147149
def test_build_fail_on_build_time(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
148150
logging.info('Fail on build time works')
149-
append_to_file(test_app_copy / 'CMakeLists.txt', '\n'.join(['',
150-
'if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/hello.txt")',
151-
'fail_at_build_time(test_file "hello.txt does not exists")',
152-
'endif()']))
151+
append_to_file(
152+
test_app_copy / 'CMakeLists.txt',
153+
'\n'.join(
154+
[
155+
'',
156+
'if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/hello.txt")',
157+
'fail_at_build_time(test_file "hello.txt does not exists")',
158+
'endif()',
159+
]
160+
),
161+
)
153162
ret = idf_py('build', check=False)
154163
assert ret.returncode != 0, 'Build should fail if requirements are not satisfied'
155164
(test_app_copy / 'hello.txt').touch()
@@ -160,10 +169,14 @@ def test_build_fail_on_build_time(idf_py: IdfPyFunc, test_app_copy: Path) -> Non
160169
def test_build_dfu(idf_py: IdfPyFunc) -> None:
161170
logging.info('DFU build works')
162171
ret = idf_py('dfu', check=False)
163-
assert 'command "dfu" is not known to idf.py and is not a Ninja target' in ret.stderr, 'DFU build should fail for default chip target'
172+
assert 'command "dfu" is not known to idf.py and is not a Ninja target' in ret.stderr, (
173+
'DFU build should fail for default chip target'
174+
)
164175
idf_py('set-target', 'esp32s2')
165176
ret = idf_py('dfu')
166-
assert 'build/dfu.bin" has been written. You may proceed with DFU flashing.' in ret.stdout, 'DFU build should succeed for esp32s2'
177+
assert 'build/dfu.bin" has been written. You may proceed with DFU flashing.' in ret.stdout, (
178+
'DFU build should succeed for esp32s2'
179+
)
167180
assert_built(BOOTLOADER_BINS + APP_BINS + PARTITION_BIN + ['build/dfu.bin'])
168181

169182

@@ -174,23 +187,35 @@ def test_build_uf2(idf_py: IdfPyFunc) -> None:
174187
assert 'build/uf2.bin, ready to be flashed with any ESP USB Bridge' in ret.stdout, 'UF2 build should work for esp32'
175188
assert_built(BOOTLOADER_BINS + APP_BINS + PARTITION_BIN + ['build/uf2.bin'])
176189
ret = idf_py('uf2-app')
177-
assert 'build/uf2-app.bin, ready to be flashed with any ESP USB Bridge' in ret.stdout, 'UF2 build should work for application binary'
190+
assert 'build/uf2-app.bin, ready to be flashed with any ESP USB Bridge' in ret.stdout, (
191+
'UF2 build should work for application binary'
192+
)
178193
assert_built(['build/uf2-app.bin'])
179194
idf_py('set-target', 'esp32s2')
180195
ret = idf_py('uf2')
181-
assert 'build/uf2.bin, ready to be flashed with any ESP USB Bridge' in ret.stdout, 'UF2 build should work for esp32s2'
196+
assert 'build/uf2.bin, ready to be flashed with any ESP USB Bridge' in ret.stdout, (
197+
'UF2 build should work for esp32s2'
198+
)
182199
assert_built(BOOTLOADER_BINS + APP_BINS + PARTITION_BIN + ['build/uf2.bin'])
183200

184201

185202
def test_build_loadable_elf(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
186203
logging.info('Loadable ELF build works')
187-
(test_app_copy / 'sdkconfig').write_text('\n'.join(['CONFIG_APP_BUILD_TYPE_RAM=y',
188-
'CONFIG_VFS_SUPPORT_TERMIOS=n',
189-
'CONFIG_NEWLIB_NANO_FORMAT=y',
190-
'CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y',
191-
'CONFIG_ESP_ERR_TO_NAME_LOOKUP=n']))
204+
(test_app_copy / 'sdkconfig').write_text(
205+
'\n'.join(
206+
[
207+
'CONFIG_APP_BUILD_TYPE_RAM=y',
208+
'CONFIG_VFS_SUPPORT_TERMIOS=n',
209+
'CONFIG_NEWLIB_NANO_FORMAT=y',
210+
'CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y',
211+
'CONFIG_ESP_ERR_TO_NAME_LOOKUP=n',
212+
]
213+
)
214+
)
192215
idf_py('reconfigure')
193-
assert (test_app_copy / 'build' / 'flasher_args.json').exists(), 'flasher_args.json should be generated in a loadable ELF build'
216+
assert (test_app_copy / 'build' / 'flasher_args.json').exists(), (
217+
'flasher_args.json should be generated in a loadable ELF build'
218+
)
194219
idf_py('build')
195220

196221

@@ -221,3 +246,15 @@ def test_build_cmake_executable_suffix(idf_py: IdfPyFunc, test_app_copy: Path) -
221246
append_to_file((test_app_copy / 'CMakeLists.txt'), 'set(CMAKE_EXECUTABLE_SUFFIX_CXX ".ext")')
222247
ret = idf_py('build')
223248
assert 'Project build complete' in ret.stdout, 'Build with CMAKE_EXECUTABLE_SUFFIX set failed'
249+
250+
251+
def test_build_with_misspelled_kconfig(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
252+
logging.info('idf.py can build with misspelled Kconfig file')
253+
ret = idf_py('build')
254+
assert " file should be named 'Kconfig.projbuild'" in ret.stderr, 'Misspelled Kconfig file should be detected'
255+
assert_built(BOOTLOADER_BINS + APP_BINS + PARTITION_BIN)
256+
with open(test_app_copy / 'sdkconfig', 'r') as f:
257+
sdkconfig = f.read()
258+
assert 'CONFIG_FROM_MISSPELLED_KCONFIG=y' in sdkconfig, (
259+
'There should be a config from the misspelled Kconfig file in sdkconfig'
260+
)

0 commit comments

Comments
 (0)