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>
diff --git a/scripts/west_commands/zephyr_ext_common.py b/scripts/west_commands/zephyr_ext_common.py
index fa6dcde..fe81f0e 100644
--- a/scripts/west_commands/zephyr_ext_common.py
+++ b/scripts/west_commands/zephyr_ext_common.py
@@ -8,6 +8,9 @@
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 @@
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')