Skip to content

Commit 003bdfa

Browse files
committed
[nrf fromlist] scripts: Generate and 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 Upstream PR #: 95049 Signed-off-by: Jamie McCrae <[email protected]>
1 parent f1e8f49 commit 003bdfa

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

cmake/modules/kconfig.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ execute_process(
356356
${PYTHON_EXECUTABLE}
357357
${ZEPHYR_BASE}/scripts/kconfig/kconfig.py
358358
--zephyr-base=${ZEPHYR_BASE}
359+
--env-file=${KCONFIG_BINARY_DIR}/kconfig_module_dirs.env
359360
${input_configs_flags}
360361
${KCONFIG_ROOT}
361362
${DOTCONFIG}

scripts/ci/check_compliance.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import unidiff
2424
import yaml
2525

26+
from dotenv import load_dotenv
2627
from yamllint import config, linter
2728

2829
from junitparser import TestCase, TestSuite, JUnitXml, Skipped, Error, Failure
@@ -739,6 +740,10 @@ def parse_kconfig(self):
739740
self.get_modules(os.path.join(kconfiglib_dir, "Kconfig.modules"),
740741
os.path.join(kconfiglib_dir, "Kconfig.sysbuild.modules"),
741742
os.path.join(kconfiglib_dir, "settings_file.txt"))
743+
744+
# Import zephyr module paths into environmental values
745+
load_dotenv(os.path.join(kconfiglib_dir, "kconfig_module_dirs.env"))
746+
742747
# For Kconfig.dts support
743748
self.get_kconfig_dts(os.path.join(kconfiglib_dir, "Kconfig.dts"),
744749
os.path.join(kconfiglib_dir, "settings_file.txt"))

scripts/kconfig/kconfig.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import re
2121
import sys
2222
import textwrap
23+
from dotenv import load_dotenv
2324

2425
# Zephyr doesn't use tristate symbols. They're supported here just to make the
2526
# script a bit more generic.
@@ -42,6 +43,9 @@ def main():
4243
if args.zephyr_base:
4344
os.environ['ZEPHYR_BASE'] = args.zephyr_base
4445

46+
if args.env_file:
47+
load_dotenv(args.env_file)
48+
4549
print("Parsing " + args.kconfig_file)
4650
kconf = Kconfig(args.kconfig_file, warn_to_stderr=False,
4751
suppress_traceback=True)
@@ -317,6 +321,8 @@ def parse_args():
317321
" adjustments.")
318322
parser.add_argument("--zephyr-base",
319323
help="Path to current Zephyr installation")
324+
parser.add_argument("--env-file",
325+
help="Path to environment file to use")
320326
parser.add_argument("kconfig_file",
321327
help="Top-level Kconfig file")
322328
parser.add_argument("config_out",

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)

0 commit comments

Comments
 (0)