Skip to content

Commit 4977c5c

Browse files
nordicjmkartben
authored andcommitted
scripts/kconfig/cmake: Generate/use env file for zephyr module paths
Adds a output env file that lists the paths of zephyr modules which can be used in Kconfig files and uses this in Kconfig. Also updates Kconfig doc output to generate and use this Signed-off-by: Jamie McCrae <[email protected]>
1 parent 47de4d1 commit 4977c5c

File tree

6 files changed

+48
-16
lines changed

6 files changed

+48
-16
lines changed

Kconfig.zephyr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# SPDX-License-Identifier: Apache-2.0
77

88
source "Kconfig.constants"
9+
source "$(KCONFIG_ENV_FILE)"
910

1011
osource "$(APPLICATION_SOURCE_DIR)/VERSION"
1112

cmake/modules/kconfig.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ zephyr_get(APP_DIR VAR APP_DIR APPLICATION_SOURCE_DIR)
134134

135135
set(COMMON_KCONFIG_ENV_SETTINGS
136136
PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
137+
KCONFIG_ENV_FILE=${KCONFIG_BINARY_DIR}/kconfig_module_dirs.env
137138
srctree=${ZEPHYR_BASE}
138139
KERNELVERSION=${KERNELVERSION}
139140
APPVERSION=${APP_VERSION_STRING}

doc/_extensions/zephyr/kconfig/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,18 @@ def kconfig_load(app: Sphinx) -> tuple[kconfiglib.Kconfig, kconfiglib.Kconfig, d
7676
modules = zephyr_module.parse_modules(ZEPHYR_BASE)
7777

7878
# generate Kconfig.modules file
79+
kconfig_module_dirs = ""
7980
kconfig = ""
8081
sysbuild_kconfig = ""
8182
for module in modules:
83+
kconfig_module_dirs += zephyr_module.process_kconfig_module_dir(module.project,
84+
module.meta)
8285
kconfig += zephyr_module.process_kconfig(module.project, module.meta)
8386
sysbuild_kconfig += zephyr_module.process_sysbuildkconfig(module.project, module.meta)
8487

88+
with open(Path(td) / "kconfig_module_dirs.env", "w") as f:
89+
f.write(kconfig_module_dirs)
90+
8591
with open(Path(td) / "Kconfig.modules", "w") as f:
8692
f.write(kconfig)
8793

@@ -149,6 +155,7 @@ def kconfig_load(app: Sphinx) -> tuple[kconfiglib.Kconfig, kconfiglib.Kconfig, d
149155

150156
os.environ["BOARD"] = "boards"
151157
os.environ["KCONFIG_BOARD_DIR"] = str(Path(td) / "boards")
158+
os.environ["KCONFIG_ENV_FILE"] = str(Path(td) / "kconfig_module_dirs.env")
152159

153160
# Sysbuild runs first
154161
os.environ["CONFIG_"] = "SB_CONFIG_"

scripts/ci/check_compliance.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def run(self):
515515
self.check_no_undef_outside_kconfig(kconf)
516516
self.check_disallowed_defconfigs(kconf)
517517

518-
def get_modules(self, modules_file, sysbuild_modules_file, settings_file):
518+
def get_modules(self, _module_dirs_file, modules_file, sysbuild_modules_file, settings_file):
519519
"""
520520
Get a list of modules and put them in a file that is parsed by
521521
Kconfig
@@ -700,13 +700,15 @@ def parse_kconfig(self):
700700
os.environ["KCONFIG_BINARY_DIR"] = kconfiglib_dir
701701
os.environ['DEVICETREE_CONF'] = "dummy"
702702
os.environ['TOOLCHAIN_HAS_NEWLIB'] = "y"
703+
os.environ['KCONFIG_ENV_FILE'] = os.path.join(kconfiglib_dir, "kconfig_module_dirs.env")
703704

704705
# Older name for DEVICETREE_CONF, for compatibility with older Zephyr
705706
# versions that don't have the renaming
706707
os.environ["GENERATED_DTS_BOARD_CONF"] = "dummy"
707708

708709
# For multi repo support
709-
self.get_modules(os.path.join(kconfiglib_dir, "Kconfig.modules"),
710+
self.get_modules(os.environ['KCONFIG_ENV_FILE'],
711+
os.path.join(kconfiglib_dir, "Kconfig.modules"),
710712
os.path.join(kconfiglib_dir, "Kconfig.sysbuild.modules"),
711713
os.path.join(kconfiglib_dir, "settings_file.txt"))
712714
# For Kconfig.dts support
@@ -1365,13 +1367,17 @@ class KconfigBasicNoModulesCheck(KconfigBasicCheck):
13651367
"""
13661368
name = "KconfigBasicNoModules"
13671369
path_hint = "<zephyr-base>"
1370+
EMPTY_FILE_CONTENTS = "# Empty\n"
1371+
1372+
def get_modules(self, module_dirs_file, modules_file, sysbuild_modules_file, settings_file):
1373+
with open(module_dirs_file, 'w') as fp_module_file:
1374+
fp_module_file.write(self.EMPTY_FILE_CONTENTS)
13681375

1369-
def get_modules(self, modules_file, sysbuild_modules_file, settings_file):
13701376
with open(modules_file, 'w') as fp_module_file:
1371-
fp_module_file.write("# Empty\n")
1377+
fp_module_file.write(self.EMPTY_FILE_CONTENTS)
13721378

13731379
with open(sysbuild_modules_file, 'w') as fp_module_file:
1374-
fp_module_file.write("# Empty\n")
1380+
fp_module_file.write(self.EMPTY_FILE_CONTENTS)
13751381

13761382

13771383
class KconfigHWMv2Check(KconfigBasicCheck):

scripts/zephyr_module.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,22 @@ def kconfig_snippet(meta, path, kconfig_file=None, blobs=False, taint_blobs=Fals
386386
return '\n'.join(snippet)
387387

388388

389+
def process_kconfig_module_dir(module, meta):
390+
module_path = PurePath(module)
391+
name_sanitized = meta['name-sanitized']
392+
return f'ZEPHYR_{name_sanitized.upper()}_MODULE_DIR={module_path.as_posix()}\n'
393+
394+
389395
def process_kconfig(module, meta):
390396
blobs = process_blobs(module, meta)
391397
taint_blobs = any(b['status'] != BLOB_NOT_PRESENT for b in blobs)
392398
section = meta.get('build', dict())
393399
module_path = PurePath(module)
394400
module_yml = module_path.joinpath('zephyr/module.yml')
395401
kconfig_extern = section.get('kconfig-ext', False)
396-
name_sanitized = meta['name-sanitized']
397-
snippet = f'ZEPHYR_{name_sanitized.upper()}_MODULE_DIR := {module_path.as_posix()}\n'
398402

399403
if kconfig_extern:
400-
return snippet + kconfig_snippet(meta, module_path, blobs=blobs, taint_blobs=taint_blobs)
404+
return kconfig_snippet(meta, module_path, blobs=blobs, taint_blobs=taint_blobs)
401405

402406
kconfig_setting = section.get('kconfig', None)
403407
if not validate_setting(kconfig_setting, module):
@@ -407,10 +411,11 @@ def process_kconfig(module, meta):
407411

408412
kconfig_file = os.path.join(module, kconfig_setting or 'zephyr/Kconfig')
409413
if os.path.isfile(kconfig_file):
410-
return snippet + kconfig_snippet(meta, module_path, Path(kconfig_file),
411-
blobs=blobs, taint_blobs=taint_blobs)
414+
return kconfig_snippet(meta, module_path, Path(kconfig_file),
415+
blobs=blobs, taint_blobs=taint_blobs)
412416
else:
413-
return snippet + '\n'.join(kconfig_module_opts(name_sanitized, blobs, taint_blobs)) + '\n'
417+
name_sanitized = meta['name-sanitized']
418+
return '\n'.join(kconfig_module_opts(name_sanitized, blobs, taint_blobs)) + '\n'
414419

415420

416421
def process_sysbuildkconfig(module, meta):
@@ -419,10 +424,9 @@ def process_sysbuildkconfig(module, meta):
419424
module_yml = module_path.joinpath('zephyr/module.yml')
420425
kconfig_extern = section.get('sysbuild-kconfig-ext', False)
421426
name_sanitized = meta['name-sanitized']
422-
snippet = f'ZEPHYR_{name_sanitized.upper()}_MODULE_DIR := {module_path.as_posix()}\n'
423427

424428
if kconfig_extern:
425-
return snippet + kconfig_snippet(meta, module_path, sysbuild=True)
429+
return kconfig_snippet(meta, module_path, sysbuild=True)
426430

427431
kconfig_setting = section.get('sysbuild-kconfig', None)
428432
if not validate_setting(kconfig_setting, module):
@@ -433,10 +437,9 @@ def process_sysbuildkconfig(module, meta):
433437
if kconfig_setting is not None:
434438
kconfig_file = os.path.join(module, kconfig_setting)
435439
if os.path.isfile(kconfig_file):
436-
return snippet + kconfig_snippet(meta, module_path, Path(kconfig_file))
440+
return kconfig_snippet(meta, module_path, Path(kconfig_file))
437441

438-
return snippet + \
439-
(f'config ZEPHYR_{name_sanitized.upper()}_MODULE\n'
442+
return (f'config ZEPHYR_{name_sanitized.upper()}_MODULE\n'
440443
f' bool\n'
441444
f' default y\n')
442445

@@ -866,6 +869,7 @@ def main():
866869
help='Path to zephyr repository')
867870
args = parser.parse_args()
868871

872+
kconfig_module_dirs = ""
869873
kconfig = ""
870874
cmake = ""
871875
sysbuild_kconfig = ""
@@ -878,6 +882,7 @@ def main():
878882
args.modules, args.extra_modules)
879883

880884
for module in modules:
885+
kconfig_module_dirs += process_kconfig_module_dir(module.project, module.meta)
881886
kconfig += process_kconfig(module.project, module.meta)
882887
cmake += process_cmake(module.project, module.meta)
883888
sysbuild_kconfig += process_sysbuildkconfig(
@@ -886,6 +891,16 @@ def main():
886891
settings += process_settings(module.project, module.meta)
887892
twister += process_twister(module.project, module.meta)
888893

894+
if args.kconfig_out or args.sysbuild_kconfig_out:
895+
if args.kconfig_out:
896+
kconfig_module_dirs_out = PurePath(args.kconfig_out).parent / 'kconfig_module_dirs.env'
897+
elif args.sysbuild_kconfig_out:
898+
kconfig_module_dirs_out = PurePath(args.sysbuild_kconfig_out).parent / \
899+
'kconfig_module_dirs.env'
900+
901+
with open(kconfig_module_dirs_out, 'w', encoding="utf-8") as fp:
902+
fp.write(kconfig_module_dirs)
903+
889904
if args.kconfig_out:
890905
with open(args.kconfig_out, 'w', encoding="utf-8") as fp:
891906
fp.write(kconfig)

share/sysbuild/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
source "$(KCONFIG_ENV_FILE)"
6+
57
config BOARD
68
string
79
default "$(BOARD)"

0 commit comments

Comments
 (0)