diff --git a/scripts/west_commands/sign.py b/scripts/west_commands/sign.py index 5efbfa5e731..0b71e9b708b 100644 --- a/scripts/west_commands/sign.py +++ b/scripts/west_commands/sign.py @@ -9,7 +9,6 @@ import pathlib import pickle import platform import shutil -import shlex import subprocess import sys @@ -80,22 +79,6 @@ when invoking west sign _indirectly_ through CMake/ninja. See how at https://docs.zephyrproject.org/latest/develop/west/sign.html ''' - -def config_get_words(west_config, section_key, fallback=None): - unparsed = west_config.get(section_key) - log.dbg(f'west config {section_key}={unparsed}') - return fallback if unparsed is None else shlex.split(unparsed) - - -def config_get(west_config, section_key, fallback=None): - words = config_get_words(west_config, section_key) - if words is None: - return fallback - if len(words) != 1: - log.die(f'Single word expected for: {section_key}={words}. Use quotes?') - return words[0] - - class ToggleAction(argparse.Action): def __call__(self, parser, args, ignored, option): @@ -179,7 +162,7 @@ schema (rimage "target") is not defined in board.cmake.''') build_conf = BuildConfiguration(build_dir) if not args.tool: - args.tool = config_get(self.config, 'sign.tool') + args.tool = self.config_get('sign.tool') # Decide on output formats. formats = [] @@ -507,7 +490,7 @@ class RimageSigner(Signer): tool_path = ( args.tool_path if args.tool_path else - config_get(command.config, 'rimage.path', None) + self.command.config_get('rimage.path', None) ) err_prefix = '--tool-path' if args.tool_path else 'west config' @@ -572,7 +555,7 @@ class RimageSigner(Signer): components = [ ] if bootloader is None else [ bootloader ] components += [ kernel ] - sign_config_extra_args = config_get_words(command.config, 'rimage.extra-args', []) + sign_config_extra_args = self.command.config_get_words('rimage.extra-args', []) if '-k' not in sign_config_extra_args + args.tool_args: # rimage requires a key argument even when it does not sign diff --git a/scripts/west_commands/zephyr_ext_common.py b/scripts/west_commands/zephyr_ext_common.py index 8403bab44a3..d2d31a620d1 100644 --- a/scripts/west_commands/zephyr_ext_common.py +++ b/scripts/west_commands/zephyr_ext_common.py @@ -9,6 +9,7 @@ commands are in run_common -- that's for common code used by commands which specifically execute runners.''' import os +import shlex from pathlib import Path from west import log @@ -45,3 +46,16 @@ class Forceable(WestCommand): if not (cond or self.args.force): log.err(msg) log.die('refusing to proceed without --force due to above error') + + def config_get_words(self, section_key, fallback=None): + unparsed = self.config.get(section_key) + self.dbg(f'west config {section_key}={unparsed}') + return fallback if unparsed is None else shlex.split(unparsed) + + def config_get(self, section_key, fallback=None): + words = self.config_get_words(section_key) + if words is None: + return fallback + if len(words) != 1: + self.die(f'Single word expected for: {section_key}={words}. Use quotes?') + return words[0]