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:
<workspace>/modules/foo
                    |--- zephyr
                          |--- CMakeLists.txt
                          |--- Kconfig

will be referred to as FOO in the build system, that is:
ZEPHYR_FOO_MODULE_DIR==<workspace>/modules/foo
ZEPHYR_FOO_CMAKE_DIR==<workspace>/modules/foo/zephyr

The `name` field allows the module to specify its module name,
independent of its location like:

<workspace>/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==<workspace>/modules/foo
ZEPHYR_BAR_CMAKE_DIR==<workspace>/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 <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2021-01-07 15:27:53 +01:00 committed by Carles Cufí
parent 0970e42334
commit f24f88324c

View file

@ -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: