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:
parent
5b0167ae79
commit
0fba4bf20c
12 changed files with 19 additions and 13 deletions
|
@ -96,7 +96,7 @@ class ArcBinaryRunner(ZephyrBinaryRunner):
|
||||||
tcl_port=tcl_port, telnet_port=telnet_port,
|
tcl_port=tcl_port, telnet_port=telnet_port,
|
||||||
gdb_port=gdb_port, debug=debug)
|
gdb_port=gdb_port, debug=debug)
|
||||||
|
|
||||||
def run(self, command, **kwargs):
|
def do_run(self, command, **kwargs):
|
||||||
if command not in {'flash', 'debug', 'debugserver'}:
|
if command not in {'flash', 'debug', 'debugserver'}:
|
||||||
raise ValueError('{} is not supported'.format(command))
|
raise ValueError('{} is not supported'.format(command))
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ class BossacBinaryRunner(ZephyrBinaryRunner):
|
||||||
return BossacBinaryRunner(bin_name, bossac=bossac, port=port,
|
return BossacBinaryRunner(bin_name, bossac=bossac, port=port,
|
||||||
debug=debug)
|
debug=debug)
|
||||||
|
|
||||||
def run(self, command, **kwargs):
|
def do_run(self, command, **kwargs):
|
||||||
if command != 'flash':
|
if command != 'flash':
|
||||||
raise ValueError('only flash is supported')
|
raise ValueError('only flash is supported')
|
||||||
|
|
||||||
|
|
|
@ -225,9 +225,15 @@ class ZephyrBinaryRunner(abc.ABC):
|
||||||
environment variables expected by that script are used to build
|
environment variables expected by that script are used to build
|
||||||
the flasher in a backwards-compatible manner.'''
|
the flasher in a backwards-compatible manner.'''
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def run(self, command, **kwargs):
|
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.'''
|
In case of an unsupported command, raise a ValueError.'''
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ class DfuUtilBinaryRunner(ZephyrBinaryRunner):
|
||||||
output = output.decode(sys.getdefaultencoding())
|
output = output.decode(sys.getdefaultencoding())
|
||||||
return self.list_pattern in output
|
return self.list_pattern in output
|
||||||
|
|
||||||
def run(self, command, **kwargs):
|
def do_run(self, command, **kwargs):
|
||||||
if command != 'flash':
|
if command != 'flash':
|
||||||
raise ValueError('only flash is supported')
|
raise ValueError('only flash is supported')
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ class Esp32BinaryRunner(ZephyrBinaryRunner):
|
||||||
flash_mode=flash_mode, espidf=espidf,
|
flash_mode=flash_mode, espidf=espidf,
|
||||||
debug=debug)
|
debug=debug)
|
||||||
|
|
||||||
def run(self, command, **kwargs):
|
def do_run(self, command, **kwargs):
|
||||||
if command != 'flash':
|
if command != 'flash':
|
||||||
raise ValueError('only flash is supported')
|
raise ValueError('only flash is supported')
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
|
||||||
def print_gdbserver_message(self):
|
def print_gdbserver_message(self):
|
||||||
print('JLink GDB server running on port {}'.format(self.gdb_port))
|
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'}:
|
if command not in {'debug', 'debugserver'}:
|
||||||
raise ValueError('{} is not supported'.format(command))
|
raise ValueError('{} is not supported'.format(command))
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ class Nios2BinaryRunner(ZephyrBinaryRunner):
|
||||||
cpu_sof=cpu_sof, zephyr_base=zephyr_base,
|
cpu_sof=cpu_sof, zephyr_base=zephyr_base,
|
||||||
gdb=gdb, tui=tui, debug=debug)
|
gdb=gdb, tui=tui, debug=debug)
|
||||||
|
|
||||||
def run(self, command, **kwargs):
|
def do_run(self, command, **kwargs):
|
||||||
if command not in {'flash', 'debug', 'debugserver'}:
|
if command not in {'flash', 'debug', 'debugserver'}:
|
||||||
raise ValueError('{} is not supported'.format(command))
|
raise ValueError('{} is not supported'.format(command))
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ class NrfJprogBinaryRunner(ZephyrBinaryRunner):
|
||||||
|
|
||||||
return snrs[value - 1]
|
return snrs[value - 1]
|
||||||
|
|
||||||
def run(self, command, **kwargs):
|
def do_run(self, command, **kwargs):
|
||||||
if command != 'flash':
|
if command != 'flash':
|
||||||
raise ValueError('only flash is supported')
|
raise ValueError('only flash is supported')
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ class OpenOcdBinaryRunner(ZephyrBinaryRunner):
|
||||||
telnet_port=telnet_port, gdb_port=gdb_port,
|
telnet_port=telnet_port, gdb_port=gdb_port,
|
||||||
gdb=gdb, tui=tui, debug=debug)
|
gdb=gdb, tui=tui, debug=debug)
|
||||||
|
|
||||||
def run(self, command, **kwargs):
|
def do_run(self, command, **kwargs):
|
||||||
if command not in {'flash', 'debug', 'debugserver'}:
|
if command not in {'flash', 'debug', 'debugserver'}:
|
||||||
raise ValueError('{} is not supported'.format(command))
|
raise ValueError('{} is not supported'.format(command))
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ class PyOcdBinaryRunner(ZephyrBinaryRunner):
|
||||||
tui=tui, bin_name=bin_name, elf_name=elf_name,
|
tui=tui, bin_name=bin_name, elf_name=elf_name,
|
||||||
board_id=board_id, daparg=daparg, debug=debug)
|
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'}:
|
if command not in {'flash', 'debug', 'debugserver'}:
|
||||||
raise ValueError('{} is not supported'.format(command))
|
raise ValueError('{} is not supported'.format(command))
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,6 @@ class QemuBinaryRunner(ZephyrBinaryRunner):
|
||||||
'''Create runner. No environment dependencies.'''
|
'''Create runner. No environment dependencies.'''
|
||||||
return QemuBinaryRunner()
|
return QemuBinaryRunner()
|
||||||
|
|
||||||
def run(self, command, **kwargs):
|
def do_run(self, command, **kwargs):
|
||||||
if command == 'debugserver':
|
if command == 'debugserver':
|
||||||
print('Detached GDB server')
|
print('Detached GDB server')
|
||||||
|
|
|
@ -35,7 +35,7 @@ class XtensaBinaryRunner(ZephyrBinaryRunner):
|
||||||
|
|
||||||
return XtensaBinaryRunner(xt_gdb, elf_name)
|
return XtensaBinaryRunner(xt_gdb, elf_name)
|
||||||
|
|
||||||
def run(self, command, **kwargs):
|
def do_run(self, command, **kwargs):
|
||||||
if command != 'debug':
|
if command != 'debug':
|
||||||
raise ValueError('Only debug is supported')
|
raise ValueError('Only debug is supported')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue