如何在 yocto bb 配方中有条件地安装和发送文件?
How to conditionally install and ship files in yocto bb recipe?
我的 yocto build/conf/auto.conf 文件包含一个变量:
READ_ONLY_FS ?= "true"
我想安装一个可以修改的配置文件,为此我想如果READ_ONLY_FS是"true",my.conf文件直接安装在/etc。但是如果 READ_ONLY_FS 是 "false",我希望 my.conf 文件安装在 /data/etc 中,然后软链接到 /etc。 (/data为读写分区)
目前,我的食谱中包含此内容是为了实现我想要的:
FILES_${PN} += " ${@bb.utils.contains('READ_ONLY_FS', 'true', '', '/data/${sysconfdir}/my.conf', d)}"
do_install_append() {
install -d ${D}/${sysconfdir}
if [ "${@bb.utils.contains('READ_ONLY_FS', 'true', 'true', 'false', d)} == "true" ]; then
install -d ${D}/data/${sysconfdir}
install -m 0755 ${S}/my.conf ${D}/data/${sysconfdir}/my.conf
ln -sf ${D}/data/${sysconfdir}/my.conf ${D}/${sysconfdir}/my.conf
else
install -m 0755 ${S}/my.conf ${D}/${sysconfdir}/my.conf
fi
}
但我收到错误消息:Files/directories 已安装但未发货。我做错了什么?
Bitbake 通常会告诉您哪些文件是 "installed but not shipped"。在您的情况下,您似乎安装了 /data/${sysconfdir}/my.conf
和 /${sysconfdir}/my.conf
处的符号链接,但仅将前一个路径添加到 FILES
.
顺便说一句:我认为,您可以通过删除 FILES
赋值中的条件并直接访问 READ_ONLY_FS
来简化代码。
像这样的东西应该可以工作(根本没有测试):
FILES_${PN} += "/data/${sysconfdir}/my.conf /${sysconfdir}/my.conf"
do_install_append() {
install -d ${D}/${sysconfdir}
if [ ${READ_ONLY_FS} == "true" ]; then
install -d ${D}/data/${sysconfdir}
install -m 0755 ${S}/my.conf ${D}/data/${sysconfdir}/my.conf
ln -sf ${D}/data/${sysconfdir}/my.conf ${D}/${sysconfdir}/my.conf
else
install -m 0755 ${S}/my.conf ${D}/${sysconfdir}/my.conf
fi
}
我通常在自己的层中创建一个 bbappend 以附加到 volatile-binds.bb,
例如:meta-mylayer/recipes-core/volatile-binds/volatile-binds.bbappend
包含
VOLATILE_BINDS += "\
/data/${sysconfdir}/my.conf /${sysconfdir}/my.conf\n\
"
我必须确保我的 rootfs 通过包组或 IMAGE_INSTALL
.
拉入 volatile-binds
包
安装my.conf
的配方不需要知道这个重定向,只需安装到${sysconfdir}/my.conf
。
volatile-binds
生成启动脚本,仅当 ${sysconfdir}/my.conf
为只读时才执行操作。在这种情况下,它会将 ${sysconfdir}/my.conf
复制到 /data/${sysconfdir}/my.conf
(如果它还不存在)并将后者绑定安装在前者之上。
我用
IMAGE_FEATURES += "read-only-rootfs"
在我的 'read-only image' 食谱中。
我的 yocto build/conf/auto.conf 文件包含一个变量:
READ_ONLY_FS ?= "true"
我想安装一个可以修改的配置文件,为此我想如果READ_ONLY_FS是"true",my.conf文件直接安装在/etc。但是如果 READ_ONLY_FS 是 "false",我希望 my.conf 文件安装在 /data/etc 中,然后软链接到 /etc。 (/data为读写分区)
目前,我的食谱中包含此内容是为了实现我想要的:
FILES_${PN} += " ${@bb.utils.contains('READ_ONLY_FS', 'true', '', '/data/${sysconfdir}/my.conf', d)}"
do_install_append() {
install -d ${D}/${sysconfdir}
if [ "${@bb.utils.contains('READ_ONLY_FS', 'true', 'true', 'false', d)} == "true" ]; then
install -d ${D}/data/${sysconfdir}
install -m 0755 ${S}/my.conf ${D}/data/${sysconfdir}/my.conf
ln -sf ${D}/data/${sysconfdir}/my.conf ${D}/${sysconfdir}/my.conf
else
install -m 0755 ${S}/my.conf ${D}/${sysconfdir}/my.conf
fi
}
但我收到错误消息:Files/directories 已安装但未发货。我做错了什么?
Bitbake 通常会告诉您哪些文件是 "installed but not shipped"。在您的情况下,您似乎安装了 /data/${sysconfdir}/my.conf
和 /${sysconfdir}/my.conf
处的符号链接,但仅将前一个路径添加到 FILES
.
顺便说一句:我认为,您可以通过删除 FILES
赋值中的条件并直接访问 READ_ONLY_FS
来简化代码。
像这样的东西应该可以工作(根本没有测试):
FILES_${PN} += "/data/${sysconfdir}/my.conf /${sysconfdir}/my.conf"
do_install_append() {
install -d ${D}/${sysconfdir}
if [ ${READ_ONLY_FS} == "true" ]; then
install -d ${D}/data/${sysconfdir}
install -m 0755 ${S}/my.conf ${D}/data/${sysconfdir}/my.conf
ln -sf ${D}/data/${sysconfdir}/my.conf ${D}/${sysconfdir}/my.conf
else
install -m 0755 ${S}/my.conf ${D}/${sysconfdir}/my.conf
fi
}
我通常在自己的层中创建一个 bbappend 以附加到 volatile-binds.bb,
例如:meta-mylayer/recipes-core/volatile-binds/volatile-binds.bbappend
包含
VOLATILE_BINDS += "\
/data/${sysconfdir}/my.conf /${sysconfdir}/my.conf\n\
"
我必须确保我的 rootfs 通过包组或 IMAGE_INSTALL
.
volatile-binds
包
安装my.conf
的配方不需要知道这个重定向,只需安装到${sysconfdir}/my.conf
。
volatile-binds
生成启动脚本,仅当 ${sysconfdir}/my.conf
为只读时才执行操作。在这种情况下,它会将 ${sysconfdir}/my.conf
复制到 /data/${sysconfdir}/my.conf
(如果它还不存在)并将后者绑定安装在前者之上。
我用
IMAGE_FEATURES += "read-only-rootfs"
在我的 'read-only image' 食谱中。