scripts: runner: refactor run() implementation

Have the subclasses implement a do_run() method instead, which run()
delegates to. This will make it possible to handle common
functionality in the superclass before runner-specific methods are
called. It is a prerequisite for tasks like loading the build time
configuration to add device tree awareness.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
This commit is contained in:
Marti Bolivar 2017-11-16 10:41:39 -05:00 committed by Anas Nashif
commit 0fba4bf20c
12 changed files with 19 additions and 13 deletions

View file

@ -96,7 +96,7 @@ class ArcBinaryRunner(ZephyrBinaryRunner):
tcl_port=tcl_port, telnet_port=telnet_port,
gdb_port=gdb_port, debug=debug)
def run(self, command, **kwargs):
def do_run(self, command, **kwargs):
if command not in {'flash', 'debug', 'debugserver'}:
raise ValueError('{} is not supported'.format(command))

View file

@ -46,7 +46,7 @@ class BossacBinaryRunner(ZephyrBinaryRunner):
return BossacBinaryRunner(bin_name, bossac=bossac, port=port,
debug=debug)
def run(self, command, **kwargs):
def do_run(self, command, **kwargs):
if command != 'flash':
raise ValueError('only flash is supported')

View file

@ -225,9 +225,15 @@ class ZephyrBinaryRunner(abc.ABC):
environment variables expected by that script are used to build
the flasher in a backwards-compatible manner.'''
@abc.abstractmethod
def run(self, command, **kwargs):
'''Run a command ('flash', 'debug', 'debugserver').
'''Runs command ('flash', 'debug', 'debugserver').
This is the main entry point to this runner.'''
self.do_run(command, **kwargs)
@abc.abstractmethod
def do_run(self, command, **kwargs):
'''Concrete runner; run() delegates to this. Implement in subclasses.
In case of an unsupported command, raise a ValueError.'''

View file

@ -58,7 +58,7 @@ class DfuUtilBinaryRunner(ZephyrBinaryRunner):
output = output.decode(sys.getdefaultencoding())
return self.list_pattern in output
def run(self, command, **kwargs):
def do_run(self, command, **kwargs):
if command != 'flash':
raise ValueError('only flash is supported')

View file

@ -67,7 +67,7 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
flash_mode=flash_mode, espidf=espidf,
debug=debug)
def run(self, command, **kwargs):
def do_run(self, command, **kwargs):
if command != 'flash':
raise ValueError('only flash is supported')

View file

@ -79,7 +79,7 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
def print_gdbserver_message(self):
print('JLink GDB server running on port {}'.format(self.gdb_port))
def run(self, command, **kwargs):
def do_run(self, command, **kwargs):
if command not in {'debug', 'debugserver'}:
raise ValueError('{} is not supported'.format(command))

View file

@ -76,7 +76,7 @@ class Nios2BinaryRunner(ZephyrBinaryRunner):
cpu_sof=cpu_sof, zephyr_base=zephyr_base,
gdb=gdb, tui=tui, debug=debug)
def run(self, command, **kwargs):
def do_run(self, command, **kwargs):
if command not in {'flash', 'debug', 'debugserver'}:
raise ValueError('{} is not supported'.format(command))

View file

@ -60,7 +60,7 @@ class NrfJprogBinaryRunner(ZephyrBinaryRunner):
return snrs[value - 1]
def run(self, command, **kwargs):
def do_run(self, command, **kwargs):
if command != 'flash':
raise ValueError('only flash is supported')

View file

@ -134,7 +134,7 @@ class OpenOcdBinaryRunner(ZephyrBinaryRunner):
telnet_port=telnet_port, gdb_port=gdb_port,
gdb=gdb, tui=tui, debug=debug)
def run(self, command, **kwargs):
def do_run(self, command, **kwargs):
if command not in {'flash', 'debug', 'debugserver'}:
raise ValueError('{} is not supported'.format(command))

View file

@ -107,7 +107,7 @@ class PyOcdBinaryRunner(ZephyrBinaryRunner):
tui=tui, bin_name=bin_name, elf_name=elf_name,
board_id=board_id, daparg=daparg, debug=debug)
def run(self, command, **kwargs):
def do_run(self, command, **kwargs):
if command not in {'flash', 'debug', 'debugserver'}:
raise ValueError('{} is not supported'.format(command))

View file

@ -20,6 +20,6 @@ class QemuBinaryRunner(ZephyrBinaryRunner):
'''Create runner. No environment dependencies.'''
return QemuBinaryRunner()
def run(self, command, **kwargs):
def do_run(self, command, **kwargs):
if command == 'debugserver':
print('Detached GDB server')

View file

@ -35,7 +35,7 @@ class XtensaBinaryRunner(ZephyrBinaryRunner):
return XtensaBinaryRunner(xt_gdb, elf_name)
def run(self, command, **kwargs):
def do_run(self, command, **kwargs):
if command != 'debug':
raise ValueError('Only debug is supported')