[meta-zephy][PATCH 12/14] zephyr-flash-pyocd.bbclass: Handle import error for pyocd modules


Andrei Gherzan
 

From: Andrei Gherzan <andrei.gherzan@huawei.com>

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
---
classes/zephyr-flash-pyocd.bbclass | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/classes/zephyr-flash-pyocd.bbclass b/classes/zephyr-flash-pyocd.bbclass
index df3b631..4d24e6a 100644
--- a/classes/zephyr-flash-pyocd.bbclass
+++ b/classes/zephyr-flash-pyocd.bbclass
@@ -1,8 +1,11 @@
CONNECT_TIMEOUT_SECONDS ?= "30"

python do_flash_usb() {
- from pyocd.core.helpers import ConnectHelper
- from pyocd.flash.file_programmer import FileProgrammer
+ try:
+ from pyocd.core.helpers import ConnectHelper
+ from pyocd.flash.file_programmer import FileProgrammer
+ except ImportError:
+ bb.fatal("Flashing with pyocd needs the relevant python package. Make sure your host provides it or consult your distribution packages for how to install this prerequisite.")

timeout = int(d.getVar('CONNECT_TIMEOUT_SECONDS'))
image = f"{d.getVar('DEPLOY_DIR_IMAGE')}/{d.getVar('PN')}.elf"
--
2.30.1

Join yocto@lists.yoctoproject.org to automatically receive all group messages.