Skip to content

Commit 1d211a5

Browse files
committed
snippets: allow to use Kconfig files
This is a draft and have some limitations, WiP. Signed-off-by: Johann Fischer <[email protected]>
1 parent dbbf95a commit 1d211a5

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

Kconfig.zephyr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ osource "$(KCONFIG_BOARD_DIR)/Kconfig.defconfig"
2828
# This loads Zephyr specific SoC root defconfigs
2929
source "$(KCONFIG_BINARY_DIR)/soc/Kconfig.defconfig"
3030

31+
# This loads snippets Kconfigs
32+
osource "$(KCONFIG_BINARY_DIR)/snippets/Kconfig"
33+
3134
# This loads the toolchain defconfigs
3235
osource "$(TOOLCHAIN_KCONFIG_DIR)/Kconfig.defconfig"
3336
# This loads the testsuite defconfig

cmake/modules/snippets.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ function(zephyr_process_snippets)
100100
OUTPUT_VARIABLE snippets_target_cmd)
101101
add_custom_target(snippets ${snippets_target_cmd} USES_TERMINAL)
102102

103+
# Generate snippets Kconfig file.
104+
if (kconfig_snippets)
105+
kconfig_gen("snippets" "Kconfig" "${kconfig_snippets}" "Zephyr snippets Kconfig files")
106+
endif()
107+
103108
# If snippets were requested, print messages for each one.
104109
if(SNIPPET_AS_LIST)
105110
# Print the requested snippets.

scripts/schemas/snippet-schema.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ schema;append-schema:
1313
type: str
1414
EXTRA_CONF_FILE:
1515
type: str
16+
cmake:
17+
type: str
18+
kconfig:
19+
type: str
1620
DTS_EXTRA_CPPFLAGS:
1721
type: str
1822

scripts/snippets.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,25 @@ def process_data(self, pathobj: Path, snippet_data: dict):
5252
'''Process the data in a snippet.yml file, after it is loaded into a
5353
python object and validated by pykwalify.'''
5454
def append_value(variable, value):
55-
if variable in ('EXTRA_DTC_OVERLAY_FILE', 'EXTRA_CONF_FILE'):
55+
if variable in ('EXTRA_DTC_OVERLAY_FILE', 'EXTRA_CONF_FILE', 'kconfig'):
5656
path = pathobj.parent / value
5757
if not path.is_file():
5858
_err(f'snippet file {pathobj}: {variable}: file not found: {path}')
59+
if variable == 'kconfig':
60+
basename = os.path.basename(path)
61+
dirname = os.path.dirname(path)
62+
if basename != 'Kconfig':
63+
_err(f'snippet file {pathobj} is not a Kconfig')
64+
return f'"{path.parent.as_posix()}"'
5965
return f'"{path.as_posix()}"'
6066
if variable in ('DTS_EXTRA_CPPFLAGS'):
6167
return f'"{value}"'
68+
if variable in ('cmake'):
69+
cmake_file = os.path.join(pathobj.parent, value, "CMakeLists.txt")
70+
if not os.path.isfile(cmake_file):
71+
_err(f'snippet file {pathobj} file not found: {cmake_file}')
72+
cmake_path = os.path.join(pathobj.parent, value)
73+
return Path(cmake_path).resolve().as_posix()
6274
_err(f'unknown append variable: {variable}')
6375

6476
for variable, value in snippet_data.get('append', {}).items():
@@ -170,9 +182,15 @@ def print_appends_for_board(self, board: str, appends: Appends):
170182
def print_appends(self, appends: Appends, indent: int):
171183
space = ' ' * indent
172184
for name, values in appends.items():
173-
for value in values:
174-
self.print(f'{space}zephyr_set({name} {value} SCOPE snippets APPEND)')
175-
185+
if name in ('kconfig'):
186+
for value in values:
187+
self.print(f'list(APPEND kconfig_snippets {value})')
188+
elif name in ('cmake'):
189+
for value in values:
190+
self.print(f'#Fixme: {value})')
191+
else:
192+
for value in values:
193+
self.print(f'{space}zephyr_set({name} {value} SCOPE snippets APPEND)')
176194
def print(self, *args, **kwargs):
177195
kwargs['file'] = self.out_file
178196
print(*args, **kwargs)

0 commit comments

Comments
 (0)