west: promote config_get*() functions from sign.py to the base class
These two functions have stood the test of the time and they have absolutely nothing specific to sign.py This has the benefit of transitioning away from west's global and deprecated logging interface (https://github.com/zephyrproject-rtos/west/issues/149) and this deprecation is what prompted this commit: see #79240. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This commit is contained in:
parent
cc415bc139
commit
8b859cea2d
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue