blob: fd252760487b923eb394a3c33fed7bba5941be4b [file] [log] [blame]
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +01001#!/usr/bin/env python3
2#
3# Copyright (c) 2019, Nordic Semiconductor ASA
4#
5# SPDX-License-Identifier: Apache-2.0
6
7'''Tool for parsing a list of projects to determine if they are Zephyr
8projects. If no projects are given then the output from `west list` will be
9used as project list.
10
11Include file is generated for Kconfig using --kconfig-out.
12A <name>:<path> text file is generated for use with CMake using --cmake-out.
Anas Nashif286a9ed2019-12-11 10:13:23 -050013
Anas Nashif54713982020-12-07 14:52:10 -050014Using --twister-out <filename> an argument file for twister script will
Anas Nashif286a9ed2019-12-11 10:13:23 -050015be generated which would point to test and sample roots available in modules
Anas Nashif54713982020-12-07 14:52:10 -050016that can be included during a twister run. This allows testing code
Anas Nashif286a9ed2019-12-11 10:13:23 -050017maintained in modules in addition to what is available in the main Zephyr tree.
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +010018'''
19
20import argparse
21import os
Torsten Rasmussen3d880832021-01-19 12:01:38 +010022import re
Torsten Rasmussenfffaf052021-10-12 23:08:36 +020023import subprocess
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +010024import sys
25import yaml
26import pykwalify.core
Torsten Rasmussenb3da9ef2019-12-13 09:42:13 +010027from pathlib import Path, PurePath
Torsten Rasmussen3917ee52020-05-18 22:34:49 +020028from collections import namedtuple
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +010029
30METADATA_SCHEMA = '''
31## A pykwalify schema for basic validation of the structure of a
32## metadata YAML file.
33##
34# The zephyr/module.yml file is a simple list of key value pairs to be used by
35# the build system.
36type: map
37mapping:
Torsten Rasmussenf24f8832021-01-07 15:27:53 +010038 name:
39 required: false
40 type: str
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +010041 build:
Anas Nashif286a9ed2019-12-11 10:13:23 -050042 required: false
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +010043 type: map
44 mapping:
45 cmake:
46 required: false
47 type: str
48 kconfig:
49 required: false
50 type: str
Torsten Rasmussen3673e282020-12-17 11:27:42 +010051 cmake-ext:
52 required: false
53 type: bool
54 default: false
55 kconfig-ext:
56 required: false
57 type: bool
58 default: false
Torsten Rasmussen3917ee52020-05-18 22:34:49 +020059 depends:
60 required: false
61 type: seq
62 sequence:
63 - type: str
Torsten Rasmussen25d57ba2020-07-07 17:29:56 +020064 settings:
65 required: false
66 type: map
67 mapping:
68 board_root:
69 required: false
70 type: str
71 dts_root:
72 required: false
73 type: str
74 soc_root:
75 required: false
76 type: str
77 arch_root:
78 required: false
79 type: str
Torsten Rasmussen3673e282020-12-17 11:27:42 +010080 module_ext_root:
81 required: false
82 type: str
Anas Nashif286a9ed2019-12-11 10:13:23 -050083 tests:
84 required: false
85 type: seq
86 sequence:
87 - type: str
88 samples:
89 required: false
90 type: seq
91 sequence:
92 - type: str
93 boards:
94 required: false
95 type: seq
96 sequence:
97 - type: str
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +010098'''
99
100schema = yaml.safe_load(METADATA_SCHEMA)
101
102
103def validate_setting(setting, module_path, filename=None):
104 if setting is not None:
105 if filename is not None:
106 checkfile = os.path.join(module_path, setting, filename)
107 else:
108 checkfile = os.path.join(module_path, setting)
109 if not os.path.isfile(checkfile):
110 return False
111 return True
112
113
Anas Nashif286a9ed2019-12-11 10:13:23 -0500114def process_module(module):
Torsten Rasmussenb3da9ef2019-12-13 09:42:13 +0100115 module_path = PurePath(module)
116 module_yml = module_path.joinpath('zephyr/module.yml')
Anas Nashif286a9ed2019-12-11 10:13:23 -0500117
Sebastian Bøebb95dce2019-12-19 15:49:22 +0100118 # The input is a module if zephyr/module.yml is a valid yaml file
119 # or if both zephyr/CMakeLists.txt and zephyr/Kconfig are present.
120
Torsten Rasmussenb3da9ef2019-12-13 09:42:13 +0100121 if Path(module_yml).is_file():
122 with Path(module_yml).open('r') as f:
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +0100123 meta = yaml.safe_load(f.read())
124
125 try:
126 pykwalify.core.Core(source_data=meta, schema_data=schema)\
127 .validate()
128 except pykwalify.errors.SchemaError as e:
Ulf Magnusson50b9b122019-09-07 14:41:01 +0200129 sys.exit('ERROR: Malformed "build" section in file: {}\n{}'
Torsten Rasmussenb3da9ef2019-12-13 09:42:13 +0100130 .format(module_yml.as_posix(), e))
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +0100131
Torsten Rasmussenf24f8832021-01-07 15:27:53 +0100132 meta['name'] = meta.get('name', module_path.name)
Torsten Rasmussen3d880832021-01-19 12:01:38 +0100133 meta['name-sanitized'] = re.sub('[^a-zA-Z0-9]', '_', meta['name'])
Anas Nashif286a9ed2019-12-11 10:13:23 -0500134 return meta
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +0100135
Sebastian Bøebb95dce2019-12-19 15:49:22 +0100136 if Path(module_path.joinpath('zephyr/CMakeLists.txt')).is_file() and \
137 Path(module_path.joinpath('zephyr/Kconfig')).is_file():
Torsten Rasmussenf24f8832021-01-07 15:27:53 +0100138 return {'name': module_path.name,
Torsten Rasmussen3d880832021-01-19 12:01:38 +0100139 'name-sanitized': re.sub('[^a-zA-Z0-9]', '_', module_path.name),
Torsten Rasmussenf24f8832021-01-07 15:27:53 +0100140 'build': {'cmake': 'zephyr', 'kconfig': 'zephyr/Kconfig'}}
Sebastian Bøebb95dce2019-12-19 15:49:22 +0100141
Anas Nashif286a9ed2019-12-11 10:13:23 -0500142 return None
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +0100143
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +0100144
Anas Nashif286a9ed2019-12-11 10:13:23 -0500145def process_cmake(module, meta):
146 section = meta.get('build', dict())
147 module_path = PurePath(module)
148 module_yml = module_path.joinpath('zephyr/module.yml')
Torsten Rasmussen3673e282020-12-17 11:27:42 +0100149
150 cmake_extern = section.get('cmake-ext', False)
151 if cmake_extern:
152 return('\"{}\":\"{}\":\"{}\"\n'
Andrzej Głąbek02819482021-01-19 07:39:47 +0100153 .format(meta['name'],
Torsten Rasmussen3673e282020-12-17 11:27:42 +0100154 module_path.as_posix(),
Torsten Rasmussen3d880832021-01-19 12:01:38 +0100155 "${ZEPHYR_" + meta['name-sanitized'].upper() + "_CMAKE_DIR}"))
Torsten Rasmussen3673e282020-12-17 11:27:42 +0100156
Anas Nashif286a9ed2019-12-11 10:13:23 -0500157 cmake_setting = section.get('cmake', None)
158 if not validate_setting(cmake_setting, module, 'CMakeLists.txt'):
159 sys.exit('ERROR: "cmake" key in {} has folder value "{}" which '
Torsten Rasmussen25c3f8e2020-08-25 14:02:04 +0200160 'does not contain a CMakeLists.txt file.'
161 .format(module_yml.as_posix(), cmake_setting))
Anas Nashif286a9ed2019-12-11 10:13:23 -0500162
163 cmake_path = os.path.join(module, cmake_setting or 'zephyr')
164 cmake_file = os.path.join(cmake_path, 'CMakeLists.txt')
165 if os.path.isfile(cmake_file):
Torsten Rasmussenab7ec172020-08-25 13:32:33 +0200166 return('\"{}\":\"{}\":\"{}\"\n'
Torsten Rasmussenf24f8832021-01-07 15:27:53 +0100167 .format(meta['name'],
Torsten Rasmussenab7ec172020-08-25 13:32:33 +0200168 module_path.as_posix(),
Torsten Rasmussen25c3f8e2020-08-25 14:02:04 +0200169 Path(cmake_path).resolve().as_posix()))
Anas Nashif286a9ed2019-12-11 10:13:23 -0500170 else:
Torsten Rasmussenab7ec172020-08-25 13:32:33 +0200171 return('\"{}\":\"{}\":\"\"\n'
Torsten Rasmussenf24f8832021-01-07 15:27:53 +0100172 .format(meta['name'],
Torsten Rasmussenab7ec172020-08-25 13:32:33 +0200173 module_path.as_posix()))
Torsten Rasmussen25c3f8e2020-08-25 14:02:04 +0200174
Torsten Rasmussen3673e282020-12-17 11:27:42 +0100175
Torsten Rasmussen25d57ba2020-07-07 17:29:56 +0200176def process_settings(module, meta):
177 section = meta.get('build', dict())
178 build_settings = section.get('settings', None)
179 out_text = ""
180
181 if build_settings is not None:
Torsten Rasmussen3673e282020-12-17 11:27:42 +0100182 for root in ['board', 'dts', 'soc', 'arch', 'module_ext']:
Torsten Rasmussen25d57ba2020-07-07 17:29:56 +0200183 setting = build_settings.get(root+'_root', None)
184 if setting is not None:
185 root_path = PurePath(module) / setting
Torsten Rasmussen3673e282020-12-17 11:27:42 +0100186 out_text += f'"{root.upper()}_ROOT":'
187 out_text += f'"{root_path.as_posix()}"\n'
Torsten Rasmussen25d57ba2020-07-07 17:29:56 +0200188
189 return out_text
190
Torsten Rasmussen25c3f8e2020-08-25 14:02:04 +0200191
Torsten Rasmussen3d880832021-01-19 12:01:38 +0100192def kconfig_snippet(meta, path, kconfig_file=None):
193 name = meta['name']
194 name_sanitized = meta['name-sanitized']
195
Trond Einar Snekvik6a8326f2021-12-02 15:44:36 +0100196 snippet = (f'menu "{name} ({path.as_posix()})"',
Torsten Rasmussen3673e282020-12-17 11:27:42 +0100197 f'osource "{kconfig_file.resolve().as_posix()}"' if kconfig_file
Torsten Rasmussen3d880832021-01-19 12:01:38 +0100198 else f'osource "$(ZEPHYR_{name_sanitized.upper()}_KCONFIG)"',
199 f'config ZEPHYR_{name_sanitized.upper()}_MODULE',
Torsten Rasmussen3673e282020-12-17 11:27:42 +0100200 ' bool',
201 ' default y',
202 'endmenu\n')
203 return '\n'.join(snippet)
204
205
Anas Nashif286a9ed2019-12-11 10:13:23 -0500206def process_kconfig(module, meta):
207 section = meta.get('build', dict())
208 module_path = PurePath(module)
209 module_yml = module_path.joinpath('zephyr/module.yml')
Torsten Rasmussen3673e282020-12-17 11:27:42 +0100210 kconfig_extern = section.get('kconfig-ext', False)
211 if kconfig_extern:
Torsten Rasmussen3d880832021-01-19 12:01:38 +0100212 return kconfig_snippet(meta, module_path)
Anas Nashif286a9ed2019-12-11 10:13:23 -0500213
214 kconfig_setting = section.get('kconfig', None)
215 if not validate_setting(kconfig_setting, module):
216 sys.exit('ERROR: "kconfig" key in {} has value "{}" which does '
Torsten Rasmussen25c3f8e2020-08-25 14:02:04 +0200217 'not point to a valid Kconfig file.'
218 .format(module_yml, kconfig_setting))
Anas Nashif286a9ed2019-12-11 10:13:23 -0500219
220 kconfig_file = os.path.join(module, kconfig_setting or 'zephyr/Kconfig')
221 if os.path.isfile(kconfig_file):
Torsten Rasmussen3d880832021-01-19 12:01:38 +0100222 return kconfig_snippet(meta, module_path, Path(kconfig_file))
Anas Nashif286a9ed2019-12-11 10:13:23 -0500223 else:
224 return ""
225
Torsten Rasmussen3673e282020-12-17 11:27:42 +0100226
Anas Nashif54713982020-12-07 14:52:10 -0500227def process_twister(module, meta):
Anas Nashif286a9ed2019-12-11 10:13:23 -0500228
229 out = ""
230 tests = meta.get('tests', [])
231 samples = meta.get('samples', [])
232 boards = meta.get('boards', [])
233
234 for pth in tests + samples:
235 if pth:
236 dir = os.path.join(module, pth)
Torsten Rasmussen25c3f8e2020-08-25 14:02:04 +0200237 out += '-T\n{}\n'.format(PurePath(os.path.abspath(dir))
238 .as_posix())
Anas Nashif286a9ed2019-12-11 10:13:23 -0500239
240 for pth in boards:
241 if pth:
242 dir = os.path.join(module, pth)
Torsten Rasmussen25c3f8e2020-08-25 14:02:04 +0200243 out += '--board-root\n{}\n'.format(PurePath(os.path.abspath(dir))
244 .as_posix())
Anas Nashif286a9ed2019-12-11 10:13:23 -0500245
246 return out
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +0100247
248
Torsten Rasmussen1a519932021-11-04 18:35:50 +0100249def process_meta(zephyr_base, west_projects, modules, extra_modules=None,
250 propagate_state=False):
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200251 # Process zephyr_base, projects, and modules and create a dictionary
252 # with meta information for each input.
253 #
254 # The dictionary will contain meta info in the following lists:
255 # - zephyr: path and revision
256 # - modules: name, path, and revision
257 # - west-projects: path and revision
258 #
259 # returns the dictionary with said lists
260
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100261 meta = {'zephyr': None, 'modules': None, 'workspace': None}
262
263 workspace_dirty = False
264 workspace_extra = extra_modules is not None
265 workspace_off = False
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200266
267 def git_revision(path):
268 rc = subprocess.Popen(['git', 'rev-parse', '--is-inside-work-tree'],
269 stdout=subprocess.PIPE,
270 stderr=subprocess.PIPE,
271 cwd=path).wait()
272 if rc == 0:
273 # A git repo.
274 popen = subprocess.Popen(['git', 'rev-parse', 'HEAD'],
275 stdout=subprocess.PIPE,
276 stderr=subprocess.PIPE,
277 cwd=path)
278 stdout, stderr = popen.communicate()
279 stdout = stdout.decode('utf-8')
280
281 if not (popen.returncode or stderr):
282 revision = stdout.rstrip()
283
284 rc = subprocess.Popen(['git', 'diff-index', '--quiet', 'HEAD',
285 '--'],
286 stdout=None,
287 stderr=None,
288 cwd=path).wait()
289 if rc:
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100290 return revision + '-dirty', True
291 return revision, False
292 return None, False
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200293
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100294 zephyr_revision, zephyr_dirty = git_revision(zephyr_base)
295 zephyr_project = {'path': zephyr_base,
296 'revision': zephyr_revision}
297 meta['zephyr'] = zephyr_project
298 meta['workspace'] = {}
299 workspace_dirty |= zephyr_dirty
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200300
301 if west_projects is not None:
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100302 from west.manifest import MANIFEST_REV_BRANCH
303 projects = west_projects['projects']
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200304 meta_projects = []
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100305
306 # Special treatment of manifest project.
307 manifest_path = PurePath(projects[0].posixpath).as_posix()
308 manifest_revision, manifest_dirty = git_revision(manifest_path)
309 workspace_dirty |= manifest_dirty
310 manifest_project = {'path': manifest_path,
311 'revision': manifest_revision}
312 meta_projects.append(manifest_project)
313
314 for project in projects[1:]:
315 project_path = PurePath(project.posixpath).as_posix()
316 revision, dirty = git_revision(project_path)
317 workspace_dirty |= dirty
318 if project.sha(MANIFEST_REV_BRANCH) != revision:
319 revision += '-off'
320 workspace_off = True
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200321 meta_project = {'path': project_path,
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100322 'revision': revision}
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200323 meta_projects.append(meta_project)
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100324
325 meta.update({'west': {'manifest': west_projects['manifest'],
326 'projects': meta_projects}})
327 meta['workspace'].update({'off': workspace_off})
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200328
329 meta_projects = []
330 for module in modules:
331 module_path = PurePath(module.project).as_posix()
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100332 revision, dirty = git_revision(module_path)
333 workspace_dirty |= dirty
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200334 meta_project = {'name': module.meta['name'],
335 'path': module_path,
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100336 'revision': revision}
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200337 meta_projects.append(meta_project)
338 meta['modules'] = meta_projects
339
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100340 meta['workspace'].update({'dirty': workspace_dirty,
341 'extra': workspace_extra})
342
Torsten Rasmussen1a519932021-11-04 18:35:50 +0100343 if propagate_state:
344 if workspace_dirty and not zephyr_dirty:
345 zephyr_revision += '-dirty'
346 if workspace_extra:
347 zephyr_revision += '-extra'
348 if workspace_off:
349 zephyr_revision += '-off'
350 zephyr_project.update({'revision': zephyr_revision})
351
352 if west_projects is not None:
353 if workspace_dirty and not manifest_dirty:
354 manifest_revision += '-dirty'
355 if workspace_extra:
356 manifest_revision += '-extra'
357 if workspace_off:
358 manifest_revision += '-off'
359 manifest_project.update({'revision': manifest_revision})
360
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200361 return meta
362
363
364def west_projects():
365 manifest_file = None
366 projects = []
367 # West is imported here, as it is optional
368 # (and thus maybe not installed)
369 # if user is providing a specific modules list.
370 from west.manifest import Manifest
371 from west.util import WestNotFound
372 from west.version import __version__ as WestVersion
373 from packaging import version
374 try:
375 manifest = Manifest.from_file()
376 if version.parse(WestVersion) >= version.parse('0.9.0'):
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100377 projects = [p for p in manifest.get_projects([])
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200378 if manifest.is_active(p)]
379 else:
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100380 projects = manifest.get_projects([])
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200381 manifest_file = manifest.path
382 return {'manifest': manifest_file, 'projects': projects}
383 except WestNotFound:
384 # Only accept WestNotFound, meaning we are not in a west
385 # workspace. Such setup is allowed, as west may be installed
386 # but the project is not required to use west.
387 pass
388 return None
389
390
Marcin Niestroj248d25d2021-05-08 16:56:34 +0200391def parse_modules(zephyr_base, modules=None, extra_modules=None):
392 if modules is None:
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200393 modules = []
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +0100394
Marcin Niestroj248d25d2021-05-08 16:56:34 +0200395 if extra_modules is None:
396 extra_modules = []
Anas Nashif286a9ed2019-12-11 10:13:23 -0500397
Torsten Rasmussen3917ee52020-05-18 22:34:49 +0200398 Module = namedtuple('Module', ['project', 'meta', 'depends'])
399 # dep_modules is a list of all modules that has an unresolved dependency
400 dep_modules = []
401 # start_modules is a list modules with no depends left (no incoming edge)
402 start_modules = []
403 # sorted_modules is a topological sorted list of the modules
404 sorted_modules = []
405
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200406 for project in modules + extra_modules:
Anas Nashif286a9ed2019-12-11 10:13:23 -0500407 # Avoid including Zephyr base project as module.
Marcin Niestroj248d25d2021-05-08 16:56:34 +0200408 if project == zephyr_base:
Anas Nashif286a9ed2019-12-11 10:13:23 -0500409 continue
410
411 meta = process_module(project)
412 if meta:
Torsten Rasmussen3917ee52020-05-18 22:34:49 +0200413 section = meta.get('build', dict())
414 deps = section.get('depends', [])
415 if not deps:
416 start_modules.append(Module(project, meta, []))
417 else:
418 dep_modules.append(Module(project, meta, deps))
Martí Bolívar34346c42020-01-29 12:38:58 -0800419 elif project in extra_modules:
420 sys.exit(f'{project}, given in ZEPHYR_EXTRA_MODULES, '
421 'is not a valid zephyr module')
Anas Nashif286a9ed2019-12-11 10:13:23 -0500422
Torsten Rasmussen3917ee52020-05-18 22:34:49 +0200423 # This will do a topological sort to ensure the modules are ordered
424 # according to dependency settings.
425 while start_modules:
426 node = start_modules.pop(0)
427 sorted_modules.append(node)
Torsten Rasmussenf24f8832021-01-07 15:27:53 +0100428 node_name = node.meta['name']
Torsten Rasmussen3917ee52020-05-18 22:34:49 +0200429 to_remove = []
430 for module in dep_modules:
431 if node_name in module.depends:
432 module.depends.remove(node_name)
433 if not module.depends:
434 start_modules.append(module)
435 to_remove.append(module)
436 for module in to_remove:
437 dep_modules.remove(module)
438
439 if dep_modules:
440 # If there are any modules with unresolved dependencies, then the
441 # modules contains unmet or cyclic dependencies. Error out.
442 error = 'Unmet or cyclic dependencies in modules:\n'
443 for module in dep_modules:
444 error += f'{module.project} depends on: {module.depends}\n'
445 sys.exit(error)
446
Marcin Niestroj248d25d2021-05-08 16:56:34 +0200447 return sorted_modules
448
449
450def main():
451 parser = argparse.ArgumentParser(description='''
452 Process a list of projects and create Kconfig / CMake include files for
453 projects which are also a Zephyr module''')
454
455 parser.add_argument('--kconfig-out',
456 help="""File to write with resulting KConfig import
457 statements.""")
458 parser.add_argument('--twister-out',
459 help="""File to write with resulting twister
460 parameters.""")
461 parser.add_argument('--cmake-out',
462 help="""File to write with resulting <name>:<path>
463 values to use for including in CMake""")
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200464 parser.add_argument('--meta-out',
465 help="""Write a build meta YaML file containing a list
466 of Zephyr modules and west projects.
467 If a module or project is also a git repository
468 the current SHA revision will also be written.""")
Torsten Rasmussen1a519932021-11-04 18:35:50 +0100469 parser.add_argument('--meta-state-propagate', action='store_true',
470 help="""Propagate state of modules and west projects
471 to the suffix of the Zephyr SHA and if west is
472 used, to the suffix of the manifest SHA""")
Marcin Niestroj248d25d2021-05-08 16:56:34 +0200473 parser.add_argument('--settings-out',
474 help="""File to write with resulting <name>:<value>
475 values to use for including in CMake""")
476 parser.add_argument('-m', '--modules', nargs='+',
477 help="""List of modules to parse instead of using `west
478 list`""")
479 parser.add_argument('-x', '--extra-modules', nargs='+',
480 help='List of extra modules to parse')
481 parser.add_argument('-z', '--zephyr-base',
482 help='Path to zephyr repository')
483 args = parser.parse_args()
484
485 kconfig = ""
486 cmake = ""
487 settings = ""
488 twister = ""
489
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200490 west_proj = None
491 if args.modules is None:
492 west_proj = west_projects()
493 modules = parse_modules(args.zephyr_base,
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100494 [p.posixpath for p in west_proj['projects']]
495 if west_proj else None,
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200496 args.extra_modules)
497 else:
498 modules = parse_modules(args.zephyr_base, args.modules,
499 args.extra_modules)
Marcin Niestroj248d25d2021-05-08 16:56:34 +0200500
501 for module in modules:
Torsten Rasmussen3917ee52020-05-18 22:34:49 +0200502 kconfig += process_kconfig(module.project, module.meta)
503 cmake += process_cmake(module.project, module.meta)
Torsten Rasmussen25d57ba2020-07-07 17:29:56 +0200504 settings += process_settings(module.project, module.meta)
Anas Nashif54713982020-12-07 14:52:10 -0500505 twister += process_twister(module.project, module.meta)
Torsten Rasmussen3917ee52020-05-18 22:34:49 +0200506
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +0100507 if args.kconfig_out:
Anas Nashif286a9ed2019-12-11 10:13:23 -0500508 with open(args.kconfig_out, 'w', encoding="utf-8") as fp:
509 fp.write(kconfig)
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +0100510
511 if args.cmake_out:
Anas Nashif286a9ed2019-12-11 10:13:23 -0500512 with open(args.cmake_out, 'w', encoding="utf-8") as fp:
513 fp.write(cmake)
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +0100514
Torsten Rasmussen25d57ba2020-07-07 17:29:56 +0200515 if args.settings_out:
516 with open(args.settings_out, 'w', encoding="utf-8") as fp:
Martí Bolívar361956b2021-08-09 10:46:17 -0700517 fp.write('''\
518# WARNING. THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!
519#
520# This file contains build system settings derived from your modules.
521#
522# Modules may be set via ZEPHYR_MODULES, ZEPHYR_EXTRA_MODULES,
523# and/or the west manifest file.
524#
525# See the Modules guide for more information.
526''')
Torsten Rasmussen25d57ba2020-07-07 17:29:56 +0200527 fp.write(settings)
528
Anas Nashif54713982020-12-07 14:52:10 -0500529 if args.twister_out:
530 with open(args.twister_out, 'w', encoding="utf-8") as fp:
531 fp.write(twister)
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +0100532
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200533 if args.meta_out:
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100534 meta = process_meta(args.zephyr_base, west_proj, modules,
Torsten Rasmussen1a519932021-11-04 18:35:50 +0100535 args.extra_modules, args.meta_state_propagate)
Torsten Rasmussen64ec6ee2021-11-04 14:28:21 +0100536
Torsten Rasmussenfffaf052021-10-12 23:08:36 +0200537 with open(args.meta_out, 'w', encoding="utf-8") as fp:
538 fp.write(yaml.dump(meta))
539
Torsten Rasmussen25c3f8e2020-08-25 14:02:04 +0200540
Torsten Rasmussenbd7569f2019-03-19 10:38:18 +0100541if __name__ == "__main__":
542 main()