【问题标题】:Handling failed task in Yocto recipe处理 Yocto 配方中的失败任务
【发布时间】:2019-04-29 09:35:14
【问题描述】:

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

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失败时,退出任务,剩下的任务不执行。没看到

失败

在我的构建日志中。

我开始研究 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 事件,但从未收到。有人对如何处理这个问题有一些建议吗?

【问题讨论】:

    标签: yocto bitbake openembedded


    【解决方案1】:

    你不能出现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文件),终于结束了退出 1

    66 bbfatal_log() {
    67     if [ -p ${LOGFIFO} ] ; then
    68         printf "%b\0" "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
    

    【讨论】:

    • 这对我有用,但我仍然想知道为什么这些事件不起作用
    【解决方案2】:

    为什么不重写 die 函数,让它检查 env-var 的动作?

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

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

    INHERIT += "no-die'
    

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

    inherit no-die
    

    然后在其他地方,可能在食谱或课程中:

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

    然后

    die_action="fixup"
    

    我没有测试过这个

    【讨论】:

      猜你喜欢
      • 2017-05-12
      • 1970-01-01
      • 2019-12-24
      • 2015-05-02
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多