From d0a63d27f85c641288d63fa182164235331a96c1 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Wed, 30 Jan 2019 20:30:12 -0700 Subject: [PATCH] scripts: west_commands: refactor run_common.py Pull out some more common functionality we will need elsewhere into a separate file. Signed-off-by: Marti Bolivar --- scripts/west_commands/run_common.py | 22 ++-------------------- scripts/west_commands/zephyr_ext_common.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/scripts/west_commands/run_common.py b/scripts/west_commands/run_common.py index 5167c028ce8c69..a237876f853166 100644 --- a/scripts/west_commands/run_common.py +++ b/scripts/west_commands/run_common.py @@ -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. @@ -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__: diff --git a/scripts/west_commands/zephyr_ext_common.py b/scripts/west_commands/zephyr_ext_common.py index bf9d7b7bdb7421..944c13e3e03324 100644 --- a/scripts/west_commands/zephyr_ext_common.py +++ b/scripts/west_commands/zephyr_ext_common.py @@ -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, @@ -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)