1# Copyright (c) 2017 Linaro Limited. 2# 3# SPDX-License-Identifier: Apache-2.0 4 5import importlib 6import logging 7 8from runners.core import ZephyrBinaryRunner, MissingProgram 9 10_logger = logging.getLogger('runners') 11 12def _import_runner_module(runner_name): 13 try: 14 importlib.import_module(f'runners.{runner_name}') 15 except ImportError as ie: 16 # Runners are supposed to gracefully handle failures when they 17 # import anything outside of stdlib, but they sometimes do 18 # not. Catch ImportError to handle this. 19 _logger.warning(f'The module for runner "{runner_name}" ' 20 f'could not be imported ({ie}). This most likely ' 21 'means it is not handling its dependencies properly. ' 22 'Please report this to the zephyr developers.') 23 24# We import these here to ensure the ZephyrBinaryRunner subclasses are 25# defined; otherwise, ZephyrBinaryRunner.get_runners() won't work. 26 27_names = [ 28 'blackmagicprobe', 29 'bossac', 30 'canopen_program', 31 'dediprog', 32 'dfu', 33 'esp32', 34 'ezflashcli', 35 'gd32isp', 36 'hifive1', 37 'intel_adsp', 38 'intel_cyclonev', 39 'jlink', 40 'linkserver', 41 'mdb', 42 'misc', 43 'native', 44 'nios2', 45 'nrfjprog', 46 'nrfutil', 47 'nsim', 48 'nxp_s32dbg', 49 'openocd', 50 'probe_rs', 51 'pyocd', 52 'renode', 53 'renode-robot', 54 'qemu', 55 'silabs_commander', 56 'spi_burn', 57 'stm32cubeprogrammer', 58 'stm32flash', 59 'teensy', 60 'trace32', 61 'uf2', 62 'xtensa', 63 # Keep this list sorted by runner name; don't add to the end. 64] 65 66for _name in _names: 67 _import_runner_module(_name) 68 69def get_runner_cls(runner): 70 '''Get a runner's class object, given its name.''' 71 for cls in ZephyrBinaryRunner.get_runners(): 72 if cls.name() == runner: 73 return cls 74 raise ValueError('unknown runner "{}"'.format(runner)) 75 76__all__ = ['ZephyrBinaryRunner', 'get_runner_cls'] 77