Skip to content

Commit

Permalink
scripts: west_commands: refactor run_common.py
Browse files Browse the repository at this point in the history
Pull out some more common functionality we will need elsewhere into a
separate file.

Signed-off-by: Marti Bolivar <[email protected]>
  • Loading branch information
Marti Bolivar committed Feb 7, 2019
1 parent afb9f25 commit d0a63d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
22 changes: 2 additions & 20 deletions scripts/west_commands/run_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from west.commands import CommandContextError

from runners import get_runner_cls, ZephyrBinaryRunner
from runners.core import RunnerConfig

from zephyr_ext_common import cached_runner_config

# Context-sensitive help indentation.
# Don't change this, or output from argparse won't match up.
Expand Down Expand Up @@ -113,25 +114,6 @@ def desc_common(command_name):
'''.format(**{'command': command_name}))


def cached_runner_config(build_dir, cache):
'''Parse the RunnerConfig from a build directory and CMake Cache.'''
board_dir = cache['ZEPHYR_RUNNER_CONFIG_BOARD_DIR']
elf_file = cache.get('ZEPHYR_RUNNER_CONFIG_ELF_FILE',
cache['ZEPHYR_RUNNER_CONFIG_KERNEL_ELF'])
hex_file = cache.get('ZEPHYR_RUNNER_CONFIG_HEX_FILE',
cache['ZEPHYR_RUNNER_CONFIG_KERNEL_HEX'])
bin_file = cache.get('ZEPHYR_RUNNER_CONFIG_BIN_FILE',
cache['ZEPHYR_RUNNER_CONFIG_KERNEL_BIN'])
gdb = cache.get('ZEPHYR_RUNNER_CONFIG_GDB')
openocd = cache.get('ZEPHYR_RUNNER_CONFIG_OPENOCD')
openocd_search = cache.get('ZEPHYR_RUNNER_CONFIG_OPENOCD_SEARCH')

return RunnerConfig(build_dir, board_dir,
elf_file, hex_file, bin_file,
gdb=gdb, openocd=openocd,
openocd_search=openocd_search)


def _override_config_from_namespace(cfg, namespace):
'''Override a RunnerConfig's contents with command-line values.'''
for var in cfg.__slots__:
Expand Down
21 changes: 21 additions & 0 deletions scripts/west_commands/zephyr_ext_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from west.build import DEFAULT_BUILD_DIR, is_zephyr_build
from west.commands import WestCommand

from runners.core import RunnerConfig

BUILD_DIR_DESCRIPTION = '''\
Explicitly sets the build directory. If not given and the current
directory is a Zephyr build directory, it will be used; otherwise,
Expand Down Expand Up @@ -58,3 +60,22 @@ def check_force(self, cond, msg):
if not (cond or self.args.force):
log.err(msg)
log.die('refusing to proceed without --force due to above error')


def cached_runner_config(build_dir, cache):
'''Parse the RunnerConfig from a build directory and CMake Cache.'''
board_dir = cache['ZEPHYR_RUNNER_CONFIG_BOARD_DIR']
elf_file = cache.get('ZEPHYR_RUNNER_CONFIG_ELF_FILE',
cache['ZEPHYR_RUNNER_CONFIG_KERNEL_ELF'])
hex_file = cache.get('ZEPHYR_RUNNER_CONFIG_HEX_FILE',
cache['ZEPHYR_RUNNER_CONFIG_KERNEL_HEX'])
bin_file = cache.get('ZEPHYR_RUNNER_CONFIG_BIN_FILE',
cache['ZEPHYR_RUNNER_CONFIG_KERNEL_BIN'])
gdb = cache.get('ZEPHYR_RUNNER_CONFIG_GDB')
openocd = cache.get('ZEPHYR_RUNNER_CONFIG_OPENOCD')
openocd_search = cache.get('ZEPHYR_RUNNER_CONFIG_OPENOCD_SEARCH')

return RunnerConfig(build_dir, board_dir,
elf_file, hex_file, bin_file,
gdb=gdb, openocd=openocd,
openocd_search=openocd_search)

0 comments on commit d0a63d2

Please sign in to comment.