|
6 | 6 | '''Common code used by commands which execute runners.
|
7 | 7 | '''
|
8 | 8 |
|
| 9 | +import importlib.util |
9 | 10 | import re
|
10 | 11 | import argparse
|
11 | 12 | import logging
|
|
28 | 29 | from runners.core import BuildConfiguration
|
29 | 30 | import yaml
|
30 | 31 |
|
31 |
| -from zephyr_ext_common import ZEPHYR_SCRIPTS |
| 32 | +import zephyr_module |
| 33 | +from zephyr_ext_common import ZEPHYR_BASE, ZEPHYR_SCRIPTS |
32 | 34 |
|
33 | 35 | # Runners depend on edtlib. Make sure the copy in the tree is
|
34 | 36 | # available to them before trying to import any.
|
@@ -107,6 +109,13 @@ class SocBoardFilesProcessing:
|
107 | 109 | priority: int = IGNORED_RUN_ONCE_PRIORITY
|
108 | 110 | yaml: object = None
|
109 | 111 |
|
| 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 | + |
110 | 119 | def command_verb(command):
|
111 | 120 | return "flash" if command.name == "flash" else "debug"
|
112 | 121 |
|
@@ -197,6 +206,14 @@ def do_run_common(command, user_args, user_runner_args, domain_file=None):
|
197 | 206 | dump_context(command, user_args, user_runner_args)
|
198 | 207 | return
|
199 | 208 |
|
| 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 | + |
200 | 217 | build_dir = get_build_dir(user_args)
|
201 | 218 | if not user_args.skip_rebuild:
|
202 | 219 | rebuild(command, build_dir, user_args)
|
|
0 commit comments