Skip to content

Commit 97db13d

Browse files
JordanYatesnashif
authored andcommitted
scripts: west_commands: runners: propagate arguments
Provide a mechanism to propagate useful arguments from one runner to the next. The primary use case for this is to propagate a JLink serial number, so that if it is queried from the terminal the user only needs to make the choice once. Implements #76077. Signed-off-by: Jordan Yates <[email protected]>
1 parent c591994 commit 97db13d

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

scripts/west_commands/run_common.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,14 @@ def do_run_common(command, user_args, user_runner_args, domain_file=None):
284284
if len(entry.boards) == 0:
285285
del used_cmds[i]
286286

287+
prev_runner = None
287288
for d in domains:
288-
do_run_common_image(command, user_args, user_runner_args,
289-
used_cmds, board_image_count, d.build_dir)
289+
prev_runner = do_run_common_image(command, user_args, user_runner_args, used_cmds,
290+
board_image_count, d.build_dir, prev_runner)
290291

291292

292293
def do_run_common_image(command, user_args, user_runner_args, used_cmds,
293-
board_image_count, build_dir=None,):
294+
board_image_count, build_dir=None, prev_runner=None):
294295
global re
295296
command_name = command.name
296297
if build_dir is None:
@@ -440,6 +441,10 @@ def do_run_common_image(command, user_args, user_runner_args, used_cmds,
440441
if unknown:
441442
log.die(f'runner {runner_name} received unknown arguments: {unknown}')
442443

444+
# Propagate useful args from previous domain invocations
445+
if prev_runner is not None:
446+
runner_cls.args_from_previous_runner(prev_runner, args)
447+
443448
# Override args with any user_args. The latter must take
444449
# precedence, or e.g. --hex-file on the command line would be
445450
# ignored in favor of a board.cmake setting.
@@ -470,6 +475,7 @@ def do_run_common_image(command, user_args, user_runner_args, used_cmds,
470475
else:
471476
log.err('verbose mode enabled, dumping stack:', fatal=True)
472477
raise
478+
return runner
473479

474480
def get_build_dir(args, die_if_none=True):
475481
# Get the build directory for the given argument list and environment.

scripts/west_commands/runners/core.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,15 @@ def add_parser(cls, parser):
624624
def do_add_parser(cls, parser):
625625
'''Hook for adding runner-specific options.'''
626626

627+
@classmethod
628+
def args_from_previous_runner(cls, previous_runner,
629+
args: argparse.Namespace):
630+
'''Update arguments from a previously created runner.
631+
632+
This is intended for propagating relevant user responses
633+
between multiple runs of the same runner, for example a
634+
JTAG serial number.'''
635+
627636
@classmethod
628637
def create(cls, cfg: RunnerConfig,
629638
args: argparse.Namespace) -> 'ZephyrBinaryRunner':

scripts/west_commands/runners/nrf_common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ def do_add_parser(cls, parser):
8989

9090
parser.set_defaults(reset=True)
9191

92+
@classmethod
93+
def args_from_previous_runner(cls, previous_runner, args):
94+
# Propagate the chosen device ID to next runner
95+
if args.dev_id is None:
96+
args.dev_id = previous_runner.dev_id
97+
9298
def ensure_snr(self):
9399
if not self.dev_id or "*" in self.dev_id:
94100
self.dev_id = self.get_board_snr(self.dev_id or "*")

0 commit comments

Comments
 (0)