From f24f88324cea677cc47f006fdee81d03d90646c2 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Thu, 7 Jan 2021 15:27:53 +0100 Subject: [PATCH] scripts: module: support for name field in zephyr/module.yml The folder name of a Zephyr module is also used as its module name when integrating it into the build system. This means that a Zephyr module, BAR, located in: /modules/foo |--- zephyr |--- CMakeLists.txt |--- Kconfig will be referred to as FOO in the build system, that is: ZEPHYR_FOO_MODULE_DIR==/modules/foo ZEPHYR_FOO_CMAKE_DIR==/modules/foo/zephyr The `name` field allows the module to specify its module name, independent of its location like: /modules/foo/zephyr/module.yml ``` name: bar build: cmake: zephyr ``` will instead be referred to as BAR in the build system, that is: ZEPHYR_BAR_MODULE_DIR==/modules/foo ZEPHYR_BAR_CMAKE_DIR==/modules/foo/zephyr This allows for greater flexibility of relocating Zephyr modules in other folders and at the same time be guaranteed that other modules depending on `ZEPHYR_BAR_MODULE_DIR` is still working. If `name` field is not specified in `module.yml`, then the existing behavior of using the folder name will be used. Signed-off-by: Torsten Rasmussen --- scripts/zephyr_module.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/zephyr_module.py b/scripts/zephyr_module.py index 47c5f40d0f5..8e8ec945de2 100755 --- a/scripts/zephyr_module.py +++ b/scripts/zephyr_module.py @@ -33,6 +33,9 @@ METADATA_SCHEMA = ''' # the build system. type: map mapping: + name: + required: false + type: str build: required: false type: map @@ -124,11 +127,13 @@ def process_module(module): sys.exit('ERROR: Malformed "build" section in file: {}\n{}' .format(module_yml.as_posix(), e)) + meta['name'] = meta.get('name', module_path.name) return meta if Path(module_path.joinpath('zephyr/CMakeLists.txt')).is_file() and \ Path(module_path.joinpath('zephyr/Kconfig')).is_file(): - return {'build': {'cmake': 'zephyr', 'kconfig': 'zephyr/Kconfig'}} + return {'name': module_path.name, + 'build': {'cmake': 'zephyr', 'kconfig': 'zephyr/Kconfig'}} return None @@ -155,12 +160,12 @@ def process_cmake(module, meta): cmake_file = os.path.join(cmake_path, 'CMakeLists.txt') if os.path.isfile(cmake_file): return('\"{}\":\"{}\":\"{}\"\n' - .format(module_path.name, + .format(meta['name'], module_path.as_posix(), Path(cmake_path).resolve().as_posix())) else: return('\"{}\":\"{}\":\"\"\n' - .format(module_path.name, + .format(meta['name'], module_path.as_posix())) @@ -315,7 +320,7 @@ def main(): while start_modules: node = start_modules.pop(0) sorted_modules.append(node) - node_name = PurePath(node.project).name + node_name = node.meta['name'] to_remove = [] for module in dep_modules: if node_name in module.depends: