scripts: west: add build directory to runner configuration
Add the build directory to the central runner configuration. This is commonly useful information. The first place we can use it is to eliminate guessing the current working directory when building objects to parse .config. It's not necessary to modify the build system for this, so leave the relevant command line flag among the general options. Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
This commit is contained in:
parent
5317f76dec
commit
68e5933e97
5 changed files with 18 additions and 20 deletions
|
@ -6,7 +6,7 @@
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from os import getcwd, chdir
|
from os import getcwd, path
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ def add_parser_common(parser_adder, command):
|
||||||
description=command.description)
|
description=command.description)
|
||||||
|
|
||||||
group = parser.add_argument_group(title='General Options')
|
group = parser.add_argument_group(title='General Options')
|
||||||
|
|
||||||
group.add_argument('-d', '--build-dir',
|
group.add_argument('-d', '--build-dir',
|
||||||
help='''Build directory to obtain runner information
|
help='''Build directory to obtain runner information
|
||||||
from; default is the current working directory.''')
|
from; default is the current working directory.''')
|
||||||
|
@ -90,8 +91,8 @@ def desc_common(command_name):
|
||||||
'''.format(**{'command': command_name}))
|
'''.format(**{'command': command_name}))
|
||||||
|
|
||||||
|
|
||||||
def cached_runner_config(cache):
|
def cached_runner_config(build_dir, cache):
|
||||||
'''Parse the RunnerConfig from a CMake Cache.'''
|
'''Parse the RunnerConfig from a build directory and CMake Cache.'''
|
||||||
board_dir = cache['ZEPHYR_RUNNER_CONFIG_BOARD_DIR']
|
board_dir = cache['ZEPHYR_RUNNER_CONFIG_BOARD_DIR']
|
||||||
kernel_elf = cache['ZEPHYR_RUNNER_CONFIG_KERNEL_ELF']
|
kernel_elf = cache['ZEPHYR_RUNNER_CONFIG_KERNEL_ELF']
|
||||||
kernel_hex = cache['ZEPHYR_RUNNER_CONFIG_KERNEL_HEX']
|
kernel_hex = cache['ZEPHYR_RUNNER_CONFIG_KERNEL_HEX']
|
||||||
|
@ -100,7 +101,8 @@ def cached_runner_config(cache):
|
||||||
openocd = cache.get('ZEPHYR_RUNNER_CONFIG_OPENOCD')
|
openocd = cache.get('ZEPHYR_RUNNER_CONFIG_OPENOCD')
|
||||||
openocd_search = cache.get('ZEPHYR_RUNNER_CONFIG_OPENOCD_SEARCH')
|
openocd_search = cache.get('ZEPHYR_RUNNER_CONFIG_OPENOCD_SEARCH')
|
||||||
|
|
||||||
return RunnerConfig(board_dir, kernel_elf, kernel_hex, kernel_bin,
|
return RunnerConfig(build_dir, board_dir,
|
||||||
|
kernel_elf, kernel_hex, kernel_bin,
|
||||||
gdb=gdb, openocd=openocd,
|
gdb=gdb, openocd=openocd,
|
||||||
openocd_search=openocd_search)
|
openocd_search=openocd_search)
|
||||||
|
|
||||||
|
@ -130,21 +132,13 @@ def do_run_common(command, args, runner_args, cached_runner_var):
|
||||||
'current directory {} failed'.format(command_name,
|
'current directory {} failed'.format(command_name,
|
||||||
build_dir))
|
build_dir))
|
||||||
|
|
||||||
# Temporary hack: we need to ensure we're running from the build
|
|
||||||
# directory for now. Otherwise, the BuildConfiguration objects
|
|
||||||
# that get created by the runners look for .config in the wrong
|
|
||||||
# places.
|
|
||||||
chdir(build_dir)
|
|
||||||
|
|
||||||
# Runner creation, phase 1.
|
# Runner creation, phase 1.
|
||||||
#
|
#
|
||||||
# Get the default runner name from the cache, allowing a command
|
# Get the default runner name from the cache, allowing a command
|
||||||
# line override. Get the ZephyrBinaryRunner class by name, and
|
# line override. Get the ZephyrBinaryRunner class by name, and
|
||||||
# make sure it supports the command.
|
# make sure it supports the command.
|
||||||
|
|
||||||
# TODO: build this by joining with build_dir once the above chdir
|
cache_file = path.join(build_dir, args.cmake_cache)
|
||||||
# goes away.
|
|
||||||
cache_file = args.cmake_cache
|
|
||||||
cache = cmake.CMakeCache(cache_file)
|
cache = cmake.CMakeCache(cache_file)
|
||||||
board = cache['CACHED_BOARD']
|
board = cache['CACHED_BOARD']
|
||||||
available = cache.get_list('ZEPHYR_RUNNERS')
|
available = cache.get_list('ZEPHYR_RUNNERS')
|
||||||
|
@ -175,7 +169,7 @@ def do_run_common(command, args, runner_args, cached_runner_var):
|
||||||
# - Pull the RunnerConfig out of the cache
|
# - Pull the RunnerConfig out of the cache
|
||||||
# - Override cached values with applicable command-line options
|
# - Override cached values with applicable command-line options
|
||||||
|
|
||||||
cfg = cached_runner_config(cache)
|
cfg = cached_runner_config(build_dir, cache)
|
||||||
_override_config_from_namespace(cfg, args)
|
_override_config_from_namespace(cfg, args)
|
||||||
|
|
||||||
# Runner creation, phase 3.
|
# Runner creation, phase 3.
|
||||||
|
|
|
@ -191,16 +191,20 @@ class RunnerConfig:
|
||||||
This class's __slots__ contains exactly the configuration variables.
|
This class's __slots__ contains exactly the configuration variables.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
__slots__ = ['board_dir', 'kernel_elf', 'kernel_hex', 'kernel_bin',
|
__slots__ = ['build_dir', 'board_dir', 'kernel_elf', 'kernel_hex',
|
||||||
'gdb', 'openocd', 'openocd_search']
|
'kernel_bin', 'gdb', 'openocd', 'openocd_search']
|
||||||
|
|
||||||
# TODO: revisit whether we can get rid of some of these. Having
|
# TODO: revisit whether we can get rid of some of these. Having
|
||||||
# tool-specific configuration options here is a layering
|
# tool-specific configuration options here is a layering
|
||||||
# violation, but it's very convenient to have a single place to
|
# violation, but it's very convenient to have a single place to
|
||||||
# store the locations of tools (like gdb and openocd) that are
|
# store the locations of tools (like gdb and openocd) that are
|
||||||
# needed by multiple ZephyrBinaryRunner subclasses.
|
# needed by multiple ZephyrBinaryRunner subclasses.
|
||||||
def __init__(self, board_dir, kernel_elf, kernel_hex, kernel_bin,
|
def __init__(self, build_dir, board_dir,
|
||||||
|
kernel_elf, kernel_hex, kernel_bin,
|
||||||
gdb=None, openocd=None, openocd_search=None):
|
gdb=None, openocd=None, openocd_search=None):
|
||||||
|
self.build_dir = build_dir
|
||||||
|
'''Zephyr application build directory'''
|
||||||
|
|
||||||
self.board_dir = board_dir
|
self.board_dir = board_dir
|
||||||
'''Zephyr board directory'''
|
'''Zephyr board directory'''
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ class DfuUtilBinaryRunner(ZephyrBinaryRunner):
|
||||||
|
|
||||||
if args.dfuse:
|
if args.dfuse:
|
||||||
args.dt_flash = True # --dfuse implies --dt-flash.
|
args.dt_flash = True # --dfuse implies --dt-flash.
|
||||||
build_conf = BuildConfiguration(os.getcwd())
|
build_conf = BuildConfiguration(cfg.build_dir)
|
||||||
dcfg = DfuSeConfig(address=cls.get_flash_address(args, build_conf),
|
dcfg = DfuSeConfig(address=cls.get_flash_address(args, build_conf),
|
||||||
options=args.dfuse_modifiers)
|
options=args.dfuse_modifiers)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -68,7 +68,7 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, cfg, args):
|
def create(cls, cfg, args):
|
||||||
build_conf = BuildConfiguration(os.getcwd())
|
build_conf = BuildConfiguration(cfg.build_dir)
|
||||||
flash_addr = cls.get_flash_address(args, build_conf)
|
flash_addr = cls.get_flash_address(args, build_conf)
|
||||||
return JLinkBinaryRunner(cfg, args.device,
|
return JLinkBinaryRunner(cfg, args.device,
|
||||||
commander=args.commander,
|
commander=args.commander,
|
||||||
|
|
|
@ -86,7 +86,7 @@ class PyOcdBinaryRunner(ZephyrBinaryRunner):
|
||||||
daparg), level=log.VERBOSE_VERY)
|
daparg), level=log.VERBOSE_VERY)
|
||||||
args.daparg = daparg
|
args.daparg = daparg
|
||||||
|
|
||||||
build_conf = BuildConfiguration(os.getcwd())
|
build_conf = BuildConfiguration(cfg.build_dir)
|
||||||
flash_addr = cls.get_flash_address(args, build_conf)
|
flash_addr = cls.get_flash_address(args, build_conf)
|
||||||
|
|
||||||
return PyOcdBinaryRunner(
|
return PyOcdBinaryRunner(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue