You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何按$MACHINE为Yocto原生配方追加SRC_URI补丁?

问题分析与解决方案

错误原因

你的写法不生效主要有两个核心问题:

  1. 补丁路径错误:p1.patch 和 p2.patch 分别存放在 files/machine1/ 和 files/machine2/ 子目录下,但配方中直接写 file://p1.patch,BitBake 会默认在 files 根目录查找,找不到对应补丁自然不会应用。
  2. 需确认构建时的 ${MACHINE} 变量值确实是 machine1 或 machine2,否则条件覆盖规则不会触发。

修正后的实现方式

方式一:修正路径的条件覆盖写法

直接调整 SRC_URI 的补丁路径,匹配你的文件夹结构,同时保留条件覆盖逻辑:

inherit native
SRC_URI = "<some git repo>"
SRC_URI:append = " file://common.patch"
SRC_URI:append:machine1 = " file://machine1/p1.patch"
SRC_URI:append:machine2 = " file://machine2/p2.patch"

do_configure() {
    ./configure --static
}

do_compile() {
    oe_runmake tool1
}

do_install() {
    install -d ${D}${bindir}
    install -m 0755 ${S}/output/linux/${release}/tool1 ${D}/${bindir}/tool1
}

方式二:使用动态条件判断(更灵活)

如果需要更复杂的匹配逻辑,可使用 bb.utils.contains 动态添加补丁:

inherit native
SRC_URI = "<some git repo> file://common.patch"

# 根据MACHINE动态添加对应补丁
SRC_URI += "${@bb.utils.contains('MACHINE', 'machine1', ' file://machine1/p1.patch', '', d)}"
SRC_URI += "${@bb.utils.contains('MACHINE', 'machine2', ' file://machine2/p2.patch', '', d)}"

do_configure() {
    ./configure --static
}

do_compile() {
    oe_runmake tool1
}

do_install() {
    install -d ${D}${bindir}
    install -m 0755 ${S}/output/linux/${release}/tool1 ${D}/${bindir}/tool1
}

验证要点

  • 执行构建时,可通过 bitbake -e recipe-native | grep ^MACHINE= 确认当前生效的 MACHINE 值。
  • 检查构建日志(tmp/work/<arch>/recipe-native/0.1-r0/temp/log.do_patch),确认补丁是否被正确识别并应用。

内容的提问来源于stack exchange,提问作者nass

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 10:35:29