scripts: fix west sign when ZEPHYR_BASE is unset

Due to cleanups in west targeted at getting rid of zephyr-specific
code, extension commands can no longer rely on ZEPHYR_BASE being set
in the calling environment at import time (it's still set at run()
time for now, though, to keep west build working).

Add a new helper to make dealing with this easier from west sign.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2020-02-10 16:53:06 -08:00 committed by Johan Hedberg
commit 6dab163cad
2 changed files with 16 additions and 5 deletions

View file

@ -17,11 +17,11 @@ from build_helpers import find_build_dir, is_zephyr_build, \
FIND_BUILD_DIR_DESCRIPTION
from runners.core import BuildConfiguration
from zcmake import CMakeCache
from zephyr_ext_common import Forceable, cached_runner_config
from zephyr_ext_common import Forceable, cached_runner_config, \
zephyr_scripts_path
sys.path.append(os.path.join(zephyr_scripts_path(), 'dts'))
# FIXME we should think of a nicer way to manage sys.path
# for shared Zephyr code.
sys.path.append(os.path.join(os.environ['ZEPHYR_BASE'], 'scripts', 'dts'))
import edtlib
SIGN_DESCRIPTION = '''\
@ -388,6 +388,5 @@ class RimageSigner(Signer):
['-o', out_bin, '-m', 'apl', '-i', '3'] +
[bootloader, kernel])
log.inf(quote_sh_list(sign_base))
subprocess.check_call(sign_base)

View file

@ -8,6 +8,9 @@ Note that common helpers used by the flash and debug extension
commands are in run_common -- that's for common code used by
commands which specifically execute runners.'''
import os
from pathlib import Path
from west import log
from west.commands import WestCommand
@ -52,3 +55,12 @@ def cached_runner_config(build_dir, cache):
elf_file, hex_file, bin_file,
gdb=gdb, openocd=openocd,
openocd_search=openocd_search)
# FIXME we should think of a nicer way to manage sys.path
# for shared Zephyr code.
def zephyr_scripts_path():
# This relies on this file being zephyr/scripts/foo/bar.py.
zephyr_base = Path(os.environ.get('ZEPHYR_BASE',
Path(__file__).parent.parent.parent))
return str(zephyr_base / 'scripts')