Search code examples
yocto

yocto how to add a error handler for a specified task?


I want to add a error handler for do_image_* tasks of core-image-minimal(e.g., when do_image_* failed, execute my handler).

I tried bb.build.TaskFailed, but it seems to be for all tasks. What should I do?


Solution

  • I found a solution that works. If there are other more suitable solutions, please let me know, thank you. Everyone is welcome to discuss.

    I use the bb.build.TaskFailed event, although it's global, not specific to a recipe. In the handler body, I use e.getTask() to determine whether the specified task failed, and if so, execute my code.

    addhandler cjlhandler
    python cjlhandler() {
        bb.warn("TaskName is %s" % e.getTask())
        # you should add if statement to determine whether the specified task failed
    }
    cjlhandler[eventmask] = "bb.build.TaskFailed"