Skip to content

Commit a580b3d

Browse files
committed
west: Fix handling of modules in the boards command
The boards command was not properly using the zephyr_module functionality to obtain the board roots of all modules. Fix that by moving the functionality required to the core zephyr_module file and reuse it from external scripts. Signed-off-by: Carles Cufi <[email protected]>
1 parent 95cae9b commit a580b3d

File tree

4 files changed

+28
-35
lines changed

4 files changed

+28
-35
lines changed

doc/_extensions/zephyr/kconfig/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@
7171
def kconfig_load(app: Sphinx) -> Tuple[kconfiglib.Kconfig, Dict[str, str]]:
7272
"""Load Kconfig"""
7373
with TemporaryDirectory() as td:
74-
projects = zephyr_module.west_projects()
75-
projects = [p.posixpath for p in projects["projects"]] if projects else None
76-
modules = zephyr_module.parse_modules(ZEPHYR_BASE, projects)
74+
modules = zephyr_module.parse_modules(ZEPHYR_BASE)
7775

7876
# generate Kconfig.modules file
7977
kconfig = ""

scripts/pylib/twister/twisterlib/testplan.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from twisterlib.testinstance import TestInstance
3131

3232

33-
from zephyr_module import west_projects, parse_modules
33+
from zephyr_module import parse_modules
3434

3535
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
3636
if not ZEPHYR_BASE:
@@ -226,10 +226,7 @@ def generate_subset(self, subset, sets):
226226

227227
def handle_modules(self):
228228
# get all enabled west projects
229-
west_proj = west_projects()
230-
modules_meta = parse_modules(ZEPHYR_BASE,
231-
[p.posixpath for p in west_proj['projects']]
232-
if west_proj else None, None)
229+
modules_meta = parse_modules(ZEPHYR_BASE)
233230
self.modules = [module.meta.get('name') for module in modules_meta]
234231

235232

scripts/west_commands/boards.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def do_run(self, args, _):
7373

7474
modules_board_roots = []
7575

76-
for module in zephyr_module.parse_modules(ZEPHYR_BASE):
76+
for module in zephyr_module.parse_modules(ZEPHYR_BASE, self.manifest):
7777
board_root = module.meta.get('build', {}).get('settings', {}).get('board_root')
7878
if board_root is not None:
7979
modules_board_roots.append(Path(module.project) / board_root)

scripts/zephyr_module.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def process_twister(module, meta):
247247
return out
248248

249249

250-
def process_meta(zephyr_base, west_projects, modules, extra_modules=None,
250+
def process_meta(zephyr_base, west_projs, modules, extra_modules=None,
251251
propagate_state=False):
252252
# Process zephyr_base, projects, and modules and create a dictionary
253253
# with meta information for each input.
@@ -299,16 +299,16 @@ def git_revision(path):
299299
meta['workspace'] = {}
300300
workspace_dirty |= zephyr_dirty
301301

302-
if west_projects is not None:
302+
if west_projs is not None:
303303
from west.manifest import MANIFEST_REV_BRANCH
304-
projects = west_projects['projects']
304+
projects = west_projs['projects']
305305
meta_projects = []
306306

307307
# Special treatment of manifest project.
308-
manifest_path = PurePath(projects[0].posixpath).as_posix()
309-
manifest_revision, manifest_dirty = git_revision(manifest_path)
308+
manifest_proj_path = PurePath(projects[0].posixpath).as_posix()
309+
manifest_revision, manifest_dirty = git_revision(manifest_proj_path)
310310
workspace_dirty |= manifest_dirty
311-
manifest_project = {'path': manifest_path,
311+
manifest_project = {'path': manifest_proj_path,
312312
'revision': manifest_revision}
313313
meta_projects.append(manifest_project)
314314

@@ -323,7 +323,7 @@ def git_revision(path):
323323
'revision': revision}
324324
meta_projects.append(meta_project)
325325

326-
meta.update({'west': {'manifest': west_projects['manifest'],
326+
meta.update({'west': {'manifest': west_projs['manifest_path'],
327327
'projects': meta_projects}})
328328
meta['workspace'].update({'off': workspace_off})
329329

@@ -350,7 +350,7 @@ def git_revision(path):
350350
zephyr_revision += '-off'
351351
zephyr_project.update({'revision': zephyr_revision})
352352

353-
if west_projects is not None:
353+
if west_projs is not None:
354354
if workspace_dirty and not manifest_dirty:
355355
manifest_revision += '-dirty'
356356
if workspace_extra:
@@ -362,8 +362,8 @@ def git_revision(path):
362362
return meta
363363

364364

365-
def west_projects():
366-
manifest_file = None
365+
def west_projects(manifest = None):
366+
manifest_path = None
367367
projects = []
368368
# West is imported here, as it is optional
369369
# (and thus maybe not installed)
@@ -378,14 +378,15 @@ def west_projects():
378378

379379
from packaging import version
380380
try:
381-
manifest = Manifest.from_file()
381+
if not manifest:
382+
manifest = Manifest.from_file()
382383
if version.parse(WestVersion) >= version.parse('0.9.0'):
383384
projects = [p for p in manifest.get_projects([])
384385
if manifest.is_active(p)]
385386
else:
386387
projects = manifest.get_projects([])
387-
manifest_file = manifest.path
388-
return {'manifest': manifest_file, 'projects': projects}
388+
manifest_path = manifest.path
389+
return {'manifest_path': manifest_path, 'projects': projects}
389390
except WestNotFound:
390391
# Only accept WestNotFound, meaning we are not in a west
391392
# workspace. Such setup is allowed, as west may be installed
@@ -394,9 +395,13 @@ def west_projects():
394395
return None
395396

396397

397-
def parse_modules(zephyr_base, modules=None, extra_modules=None):
398+
def parse_modules(zephyr_base, manifest=None, west_projs=None, modules=None,
399+
extra_modules=None):
400+
398401
if modules is None:
399-
modules = []
402+
west_projs = west_projs or west_projects(manifest)
403+
modules = ([p.posixpath for p in west_projs['projects']]
404+
if west_projs else [])
400405

401406
if extra_modules is None:
402407
extra_modules = []
@@ -498,16 +503,9 @@ def main():
498503
settings = ""
499504
twister = ""
500505

501-
west_proj = None
502-
if args.modules is None:
503-
west_proj = west_projects()
504-
modules = parse_modules(args.zephyr_base,
505-
[p.posixpath for p in west_proj['projects']]
506-
if west_proj else None,
507-
args.extra_modules)
508-
else:
509-
modules = parse_modules(args.zephyr_base, args.modules,
510-
args.extra_modules)
506+
west_projs = west_projects()
507+
modules = parse_modules(args.zephyr_base, None, west_projs,
508+
args.modules, args.extra_modules)
511509

512510
for module in modules:
513511
kconfig += process_kconfig(module.project, module.meta)
@@ -542,7 +540,7 @@ def main():
542540
fp.write(twister)
543541

544542
if args.meta_out:
545-
meta = process_meta(args.zephyr_base, west_proj, modules,
543+
meta = process_meta(args.zephyr_base, west_projs, modules,
546544
args.extra_modules, args.meta_state_propagate)
547545

548546
with open(args.meta_out, 'w', encoding="utf-8") as fp:

0 commit comments

Comments
 (0)