Skip to content

Commit 68e5933

Browse files
Marti Bolivarnashif
authored andcommitted
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 <[email protected]>
1 parent 5317f76 commit 68e5933

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

scripts/meta/west/cmd/run_common.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'''
77

88
import argparse
9-
from os import getcwd, chdir
9+
from os import getcwd, path
1010
from subprocess import CalledProcessError
1111
from textwrap import dedent
1212

@@ -24,6 +24,7 @@ def add_parser_common(parser_adder, command):
2424
description=command.description)
2525

2626
group = parser.add_argument_group(title='General Options')
27+
2728
group.add_argument('-d', '--build-dir',
2829
help='''Build directory to obtain runner information
2930
from; default is the current working directory.''')
@@ -90,8 +91,8 @@ def desc_common(command_name):
9091
'''.format(**{'command': command_name}))
9192

9293

93-
def cached_runner_config(cache):
94-
'''Parse the RunnerConfig from a CMake Cache.'''
94+
def cached_runner_config(build_dir, cache):
95+
'''Parse the RunnerConfig from a build directory and CMake Cache.'''
9596
board_dir = cache['ZEPHYR_RUNNER_CONFIG_BOARD_DIR']
9697
kernel_elf = cache['ZEPHYR_RUNNER_CONFIG_KERNEL_ELF']
9798
kernel_hex = cache['ZEPHYR_RUNNER_CONFIG_KERNEL_HEX']
@@ -100,7 +101,8 @@ def cached_runner_config(cache):
100101
openocd = cache.get('ZEPHYR_RUNNER_CONFIG_OPENOCD')
101102
openocd_search = cache.get('ZEPHYR_RUNNER_CONFIG_OPENOCD_SEARCH')
102103

103-
return RunnerConfig(board_dir, kernel_elf, kernel_hex, kernel_bin,
104+
return RunnerConfig(build_dir, board_dir,
105+
kernel_elf, kernel_hex, kernel_bin,
104106
gdb=gdb, openocd=openocd,
105107
openocd_search=openocd_search)
106108

@@ -130,21 +132,13 @@ def do_run_common(command, args, runner_args, cached_runner_var):
130132
'current directory {} failed'.format(command_name,
131133
build_dir))
132134

133-
# Temporary hack: we need to ensure we're running from the build
134-
# directory for now. Otherwise, the BuildConfiguration objects
135-
# that get created by the runners look for .config in the wrong
136-
# places.
137-
chdir(build_dir)
138-
139135
# Runner creation, phase 1.
140136
#
141137
# Get the default runner name from the cache, allowing a command
142138
# line override. Get the ZephyrBinaryRunner class by name, and
143139
# make sure it supports the command.
144140

145-
# TODO: build this by joining with build_dir once the above chdir
146-
# goes away.
147-
cache_file = args.cmake_cache
141+
cache_file = path.join(build_dir, args.cmake_cache)
148142
cache = cmake.CMakeCache(cache_file)
149143
board = cache['CACHED_BOARD']
150144
available = cache.get_list('ZEPHYR_RUNNERS')
@@ -175,7 +169,7 @@ def do_run_common(command, args, runner_args, cached_runner_var):
175169
# - Pull the RunnerConfig out of the cache
176170
# - Override cached values with applicable command-line options
177171

178-
cfg = cached_runner_config(cache)
172+
cfg = cached_runner_config(build_dir, cache)
179173
_override_config_from_namespace(cfg, args)
180174

181175
# Runner creation, phase 3.

scripts/meta/west/runner/core.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,20 @@ class RunnerConfig:
191191
This class's __slots__ contains exactly the configuration variables.
192192
'''
193193

194-
__slots__ = ['board_dir', 'kernel_elf', 'kernel_hex', 'kernel_bin',
195-
'gdb', 'openocd', 'openocd_search']
194+
__slots__ = ['build_dir', 'board_dir', 'kernel_elf', 'kernel_hex',
195+
'kernel_bin', 'gdb', 'openocd', 'openocd_search']
196196

197197
# TODO: revisit whether we can get rid of some of these. Having
198198
# tool-specific configuration options here is a layering
199199
# violation, but it's very convenient to have a single place to
200200
# store the locations of tools (like gdb and openocd) that are
201201
# needed by multiple ZephyrBinaryRunner subclasses.
202-
def __init__(self, board_dir, kernel_elf, kernel_hex, kernel_bin,
202+
def __init__(self, build_dir, board_dir,
203+
kernel_elf, kernel_hex, kernel_bin,
203204
gdb=None, openocd=None, openocd_search=None):
205+
self.build_dir = build_dir
206+
'''Zephyr application build directory'''
207+
204208
self.board_dir = board_dir
205209
'''Zephyr board directory'''
206210

scripts/meta/west/runner/dfu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def create(cls, cfg, args):
7373

7474
if args.dfuse:
7575
args.dt_flash = True # --dfuse implies --dt-flash.
76-
build_conf = BuildConfiguration(os.getcwd())
76+
build_conf = BuildConfiguration(cfg.build_dir)
7777
dcfg = DfuSeConfig(address=cls.get_flash_address(args, build_conf),
7878
options=args.dfuse_modifiers)
7979
else:

scripts/meta/west/runner/jlink.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def do_add_parser(cls, parser):
6868

6969
@classmethod
7070
def create(cls, cfg, args):
71-
build_conf = BuildConfiguration(os.getcwd())
71+
build_conf = BuildConfiguration(cfg.build_dir)
7272
flash_addr = cls.get_flash_address(args, build_conf)
7373
return JLinkBinaryRunner(cfg, args.device,
7474
commander=args.commander,

scripts/meta/west/runner/pyocd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def create(cls, cfg, args):
8686
daparg), level=log.VERBOSE_VERY)
8787
args.daparg = daparg
8888

89-
build_conf = BuildConfiguration(os.getcwd())
89+
build_conf = BuildConfiguration(cfg.build_dir)
9090
flash_addr = cls.get_flash_address(args, build_conf)
9191

9292
return PyOcdBinaryRunner(

0 commit comments

Comments
 (0)