Skip to content

Commit 4e8c76c

Browse files
committed
[nrf fromlist] 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 Upstream PR #: 95049 Signed-off-by: Jamie McCrae <[email protected]>
1 parent f34df69 commit 4e8c76c

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 "$(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+
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["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
@@ -730,13 +730,15 @@ def parse_kconfig(self):
730730
os.environ["KCONFIG_BINARY_DIR"] = kconfiglib_dir
731731
os.environ['DEVICETREE_CONF'] = "dummy"
732732
os.environ['TOOLCHAIN_HAS_NEWLIB'] = "y"
733+
os.environ['ENV_FILE'] = os.path.join(kconfiglib_dir, "kconfig_module_dirs.env")
733734

734735
# Older name for DEVICETREE_CONF, for compatibility with older Zephyr
735736
# versions that don't have the renaming
736737
os.environ["GENERATED_DTS_BOARD_CONF"] = "dummy"
737738

738739
# For multi repo support
739-
self.get_modules(os.path.join(kconfiglib_dir, "Kconfig.modules"),
740+
self.get_modules(os.environ['ENV_FILE'],
741+
os.path.join(kconfiglib_dir, "Kconfig.modules"),
740742
os.path.join(kconfiglib_dir, "Kconfig.sysbuild.modules"),
741743
os.path.join(kconfiglib_dir, "settings_file.txt"))
742744
# For Kconfig.dts support
@@ -1429,13 +1431,17 @@ class KconfigBasicNoModulesCheck(KconfigBasicCheck):
14291431
"""
14301432
name = "KconfigBasicNoModules"
14311433
path_hint = "<zephyr-base>"
1434+
EMPTY_FILE_CONTENTS = "# Empty\n"
1435+
1436+
def get_modules(self, module_dirs_file, modules_file, sysbuild_modules_file, settings_file):
1437+
with open(module_dirs_file, 'w') as fp_module_file:
1438+
fp_module_file.write(self.EMPTY_FILE_CONTENTS)
14321439

1433-
def get_modules(self, modules_file, sysbuild_modules_file, settings_file):
14341440
with open(modules_file, 'w') as fp_module_file:
1435-
fp_module_file.write("# Empty\n")
1441+
fp_module_file.write(self.EMPTY_FILE_CONTENTS)
14361442

14371443
with open(sysbuild_modules_file, 'w') as fp_module_file:
1438-
fp_module_file.write("# Empty\n")
1444+
fp_module_file.write(self.EMPTY_FILE_CONTENTS)
14391445

14401446

14411447
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

@@ -861,6 +864,7 @@ def main():
861864
help='Path to zephyr repository')
862865
args = parser.parse_args()
863866

867+
kconfig_module_dirs = ""
864868
kconfig = ""
865869
cmake = ""
866870
sysbuild_kconfig = ""
@@ -873,6 +877,7 @@ def main():
873877
args.modules, args.extra_modules)
874878

875879
for module in modules:
880+
kconfig_module_dirs += process_kconfig_module_dir(module.project, module.meta)
876881
kconfig += process_kconfig(module.project, module.meta)
877882
cmake += process_cmake(module.project, module.meta)
878883
sysbuild_kconfig += process_sysbuildkconfig(
@@ -881,6 +886,16 @@ def main():
881886
settings += process_settings(module.project, module.meta)
882887
twister += process_twister(module.project, module.meta)
883888

889+
if args.kconfig_out or args.sysbuild_kconfig_out:
890+
if args.kconfig_out:
891+
kconfig_module_dirs_out = PurePath(args.kconfig_out).parent / 'kconfig_module_dirs.env'
892+
elif args.sysbuild_kconfig_out:
893+
kconfig_module_dirs_out = PurePath(args.sysbuild_kconfig_out).parent / \
894+
'kconfig_module_dirs.env'
895+
896+
with open(kconfig_module_dirs_out, 'w', encoding="utf-8") as fp:
897+
fp.write(kconfig_module_dirs)
898+
884899
if args.kconfig_out:
885900
with open(args.kconfig_out, 'w', encoding="utf-8") as fp:
886901
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 "$(ENV_FILE)"
6+
57
config BOARD
68
string
79
default "$(BOARD)"

0 commit comments

Comments
 (0)