Skip to content

Commit

Permalink
west: promote config_get*() functions from sign.py to the base class
Browse files Browse the repository at this point in the history
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
(zephyrproject-rtos/west#149) and this
deprecation is what prompted this commit: see zephyrproject-rtos#79240.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
  • Loading branch information
marc-hb committed Oct 10, 2024
1 parent 27456ed commit c7e25a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
23 changes: 3 additions & 20 deletions scripts/west_commands/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import pickle
import platform
import shutil
import shlex
import subprocess
import sys

Expand Down Expand Up @@ -80,22 +79,6 @@
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):
Expand Down Expand Up @@ -179,7 +162,7 @@ def do_run(self, args, ignored):
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 = []
Expand Down Expand Up @@ -507,7 +490,7 @@ def sign(self, command, build_dir, build_conf, formats):

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'

Expand Down Expand Up @@ -572,7 +555,7 @@ def sign(self, command, build_dir, build_conf, formats):
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
Expand Down
14 changes: 14 additions & 0 deletions scripts/west_commands/zephyr_ext_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
commands which specifically execute runners.'''

import os
import shlex
from pathlib import Path

from west import log
Expand Down Expand Up @@ -45,3 +46,16 @@ def check_force(self, cond, msg):
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]

0 comments on commit c7e25a7

Please sign in to comment.