Skip to content

Commit 640a8b9

Browse files
pdgendthenrikbrixandersen
authored andcommitted
scripts: west_commands: Support out-of-tree runners
Add runners entry to the module schema and import the file specified. Every class that inherits from ZephyrBinaryRunner will be discovered and added to runners list. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent 96a9a5e commit 640a8b9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

scripts/west_commands/run_common.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'''Common code used by commands which execute runners.
77
'''
88

9+
import importlib.util
910
import re
1011
import argparse
1112
import logging
@@ -28,7 +29,8 @@
2829
from runners.core import BuildConfiguration
2930
import yaml
3031

31-
from zephyr_ext_common import ZEPHYR_SCRIPTS
32+
import zephyr_module
33+
from zephyr_ext_common import ZEPHYR_BASE, ZEPHYR_SCRIPTS
3234

3335
# Runners depend on edtlib. Make sure the copy in the tree is
3436
# available to them before trying to import any.
@@ -107,6 +109,13 @@ class SocBoardFilesProcessing:
107109
priority: int = IGNORED_RUN_ONCE_PRIORITY
108110
yaml: object = None
109111

112+
def import_from_path(module_name, file_path):
113+
spec = importlib.util.spec_from_file_location(module_name, file_path)
114+
module = importlib.util.module_from_spec(spec)
115+
sys.modules[module_name] = module
116+
spec.loader.exec_module(module)
117+
return module
118+
110119
def command_verb(command):
111120
return "flash" if command.name == "flash" else "debug"
112121

@@ -197,6 +206,14 @@ def do_run_common(command, user_args, user_runner_args, domain_file=None):
197206
dump_context(command, user_args, user_runner_args)
198207
return
199208

209+
# Import external module runners
210+
for module in zephyr_module.parse_modules(ZEPHYR_BASE, command.manifest):
211+
runners_ext = module.meta.get("runners", [])
212+
for runner in runners_ext:
213+
import_from_path(
214+
module.meta.get("name", "runners_ext"), Path(module.project) / runner["file"]
215+
)
216+
200217
build_dir = get_build_dir(user_args)
201218
if not user_args.skip_rebuild:
202219
rebuild(command, build_dir, user_args)

scripts/zephyr_module.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@
174174
type: seq
175175
sequence:
176176
- type: str
177+
runners:
178+
required: false
179+
type: seq
180+
sequence:
181+
- type: map
182+
mapping:
183+
file:
184+
required: true
185+
type: str
177186
'''
178187

179188
MODULE_YML_PATH = PurePath('zephyr/module.yml')

0 commit comments

Comments
 (0)