处理 Yocto 配方中失败的任务

Handling failed task in Yocto recipe

我需要一些关于如何处理食谱任务中的错误的建议。考虑以下 Yocto 食谱的片段:

do_compile_custom() {
    oe_runmake  // oe_runmake command fails 
}
addtask compile_custom after do_compile before do_install

oe_runmake 失败时,我想执行一些自定义命令并继续构建,所以我认为这应该可行。

do_compile_custom() {
    oe_runmake || true // oe_runmake command fails 
    if [ $? -ne 0 ]; then
        bberror "MAKE FAILED"
    fi
}
addtask compile_custom after do_compile before do_install

但是当oe_runmake失败时,它退出任务,任务的其余部分不执行。我没看到

MAKE FAILED

在我的构建日志中。

我开始研究 bitbake 事件,所以我接下来要做的是在我的食谱中添加一个事件处理程序,一开始没有任何事件过滤器来查看收到的所有事件。

do_compile_custom() {
    oe_runmake  // oe_runmake command fails 
}
addtask compile_custom after do_compile before do_install

addhandler failure_eventhandler
python failure_eventhandler() {
    from bb.event import getName
    print("strtogrep The name of the Event is %s" % getName(e))
}

通过这个配方的实现,我只能从处理程序中看到打印的 3 个事件:

| The name of the Event is RecipePreFinalise
| The name of the Event is RecipeTaskPreProcess
| The name of the Event is RecipeParsed

根据 bitbake 中定义的所有事件,我期望在任务失败后得到 TaskFailed 事件,但从未收到过。有人对如何处理这个问题有什么建议吗?

你不能出现 MAKE FAILES 日志消息的原因是 oe_runmake 函数的结果。

如您所见 oe_runmake 的实现(来自 meta/classes/base.bbclass 文件),运行 die() 任何失败情况下的日志功能:

58 oe_runmake() {                                     
59     oe_runmake_call "$@" || die "oe_runmake failed"
60 }

最近在 die() 函数上使用 bbfatal_log() 函数(来自 meta/classes/logging.bbclass 文件),最后以 exit 1:

结尾
66 bbfatal_log() {
67     if [ -p ${LOGFIFO} ] ; then
68         printf "%b[=11=]" "bbfatal_log $*" > ${LOGFIFO}
69     else
70         echo "ERROR: $*"
71     fi
72     exit 1
73 }

我认为您实现目标的最简单方法是放弃使用默认 do_compile 实现任务,以便具有自定义编译任务,使用错误处理:

# disable do_compile task
do_compile[noexec] = "1"

do_compile_custom() {
    oe_runmake_custom_call() {                    
        bbnote ${MAKE} ${EXTRA_OEMAKE} "$@"
        ${MAKE} ${EXTRA_OEMAKE} "$@"       
    }                                      

    oe_runmake_custom_call || bbwarn "oe_runmake_custom failed"
    if [ $? -ne 0 ]; then
        bberror "MAKE FAILED"
    fi
}
addtask compile_custom before do_install

为什么不覆盖 die 函数以便它检查 env-var 以进行操作?

die_action ??= "bbfatal_log"
die() {
  ${die_action} "$*"
}

您可以在您自己继承的 no-die.bbclass 中定义它:

INHERIT += "no-die'

在全局配置文件中,或者可能在配方中

inherit no-die

然后在其他地方,也许在食谱或 class:

fixup() {
  bbwarn "Didn't Die: $*"
}

然后

die_action="fixup"

我没有测试过这个