如何按$MACHINE为Yocto原生配方追加SRC_URI补丁?
问题分析与解决方案
错误原因
你的写法不生效主要有两个核心问题:
- 补丁路径错误:
p1.patch和p2.patch分别存放在files/machine1/和files/machine2/子目录下,但配方中直接写file://p1.patch,BitBake 会默认在files根目录查找,找不到对应补丁自然不会应用。 - 需确认构建时的
${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
相关产品推荐
相关产品推荐

