modules: introducing MODULE_EXT_ROOT to allow glue code in Zephyr repo
This commit introduces MODULE_EXT_ROOT which allows CMake and Kconfig
glue code to be placed outside of the Zephyr module repository.
This allows for placing glue code in Zephyr, but also allows users to
specify custom MODULE_EXT_ROOTs for glue code using either
`-DMODULE_EXT_ROOT` or `zephyr/module.yml` with
`build:settings:module_ext_root` settings.
MODULE_EXT_ROOT' is a list of directories, similar to other roots such
as BOARD_ROOT, DTS_ROOT, etc.
The Zephyr repo folder ${ZEPHYR_BASE} is always to the MODULE_EXT_ROOT
list as lowest priority.
For each MODULE_EXT_ROOT, the file
`<module_ext_root>/modules/modules.cmake` will be processed.
In Zephyr repo, the folder `modules/<module>/` contains CMakeLists.txt
and Kconfig glue code for the Zephyr module.
A Zephyr module can specify that CMakeLists.txt and Kconfig glue code is
placed in an external module root by specifying:
```
build:
cmake-ext: True
kconfig-ext: True
```
It is still possible to place the CMakeLists.txt and Kconfig files
directly in the Zephyr module using the existing:
```
build:
cmake: <path>
kconfig: <file>
```.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
diff --git a/scripts/zephyr_module.py b/scripts/zephyr_module.py
index 883ef89..47c5f40 100755
--- a/scripts/zephyr_module.py
+++ b/scripts/zephyr_module.py
@@ -43,6 +43,14 @@
kconfig:
required: false
type: str
+ cmake-ext:
+ required: false
+ type: bool
+ default: false
+ kconfig-ext:
+ required: false
+ type: bool
+ default: false
depends:
required: false
type: seq
@@ -64,6 +72,9 @@
arch_root:
required: false
type: str
+ module_ext_root:
+ required: false
+ type: str
tests:
required: false
type: seq
@@ -126,6 +137,14 @@
section = meta.get('build', dict())
module_path = PurePath(module)
module_yml = module_path.joinpath('zephyr/module.yml')
+
+ cmake_extern = section.get('cmake-ext', False)
+ if cmake_extern:
+ return('\"{}\":\"{}\":\"{}\"\n'
+ .format(module_path.name,
+ module_path.as_posix(),
+ "${ZEPHYR_" + module_path.name.upper() + "_CMAKE_DIR}"))
+
cmake_setting = section.get('cmake', None)
if not validate_setting(cmake_setting, module, 'CMakeLists.txt'):
sys.exit('ERROR: "cmake" key in {} has folder value "{}" which '
@@ -144,25 +163,41 @@
.format(module_path.name,
module_path.as_posix()))
+
def process_settings(module, meta):
section = meta.get('build', dict())
build_settings = section.get('settings', None)
out_text = ""
if build_settings is not None:
- for root in ['board', 'dts', 'soc', 'arch']:
+ for root in ['board', 'dts', 'soc', 'arch', 'module_ext']:
setting = build_settings.get(root+'_root', None)
if setting is not None:
root_path = PurePath(module) / setting
- out_text += f'"{root.upper()}_ROOT":"{root_path.as_posix()}"\n'
+ out_text += f'"{root.upper()}_ROOT":'
+ out_text += f'"{root_path.as_posix()}"\n'
return out_text
+def kconfig_snippet(path, kconfig_file=None):
+ snippet = (f'menu "{path.name} ({path})"',
+ f'osource "{kconfig_file.resolve().as_posix()}"' if kconfig_file
+ else f'osource "$(ZEPHYR_{path.name.upper()}_KCONFIG)"',
+ f'config ZEPHYR_{path.name.upper()}_MODULE',
+ ' bool',
+ ' default y',
+ 'endmenu\n')
+ return '\n'.join(snippet)
+
+
def process_kconfig(module, meta):
section = meta.get('build', dict())
module_path = PurePath(module)
module_yml = module_path.joinpath('zephyr/module.yml')
+ kconfig_extern = section.get('kconfig-ext', False)
+ if kconfig_extern:
+ return kconfig_snippet(module_path)
kconfig_setting = section.get('kconfig', None)
if not validate_setting(kconfig_setting, module):
@@ -172,11 +207,11 @@
kconfig_file = os.path.join(module, kconfig_setting or 'zephyr/Kconfig')
if os.path.isfile(kconfig_file):
- return 'osource "{}"\n\n'.format(Path(kconfig_file)
- .resolve().as_posix())
+ return kconfig_snippet(module_path, Path(kconfig_file))
else:
return ""
+
def process_twister(module, meta):
out = ""