为什么 yocto bblayers.conf 文件使用绝对路径?

Why does the yocto bblayers.conf file use absolute paths?

yocto project 允许在其大部分配置文件中使用相对路径,但在 ./build/conf/bblayers.conf 文件中不允许。阻止对 BBLAYERSBBLAYERS_NON_REMOVABLE 变量使用除绝对路径之外的任何内容的原因是什么?

我查看了 BitBake user manual for yocto version 2.0(当前版本),但这并不能解释原因。我还检查了一些较旧的手册版本,但在谈论 bblayers.conf 文件或 BBLAYERS 变量时,它们似乎没有提到推理。同一个文件还包含 BBPATH = "${TOPDIR}" ,它至少是动态分配的,并且离根 yotco 目录不远。

我最好的猜测是 bblayers.conf 文件特定于它所在的系统 运行。这将使它不适合通过源代码控制在开发人员之间共享,并且绝对路径会迫使人们在收到副本时编辑文件。不过,这似乎不是一个很好的理由,因此才有了这个问题。

您可以在 bblayers.conf 中使用相对路径。

你的bblayers.conf中可能有这一行:

BBPATH = "${TOPDIR}"

当你想查看这个变量的内容时,你可能会找到你构建目录的顶层目录:

bitbake -e | grep ^TOPDIR
# searches for bitbake variables

在此目录中,您可以创建层 meta-test 并使用相对路径将其添加到 bblayers.conf 中:

BBLAYERS ?= " \
  meta-test \
  [...]
  "

所以关于为什么 bblayers.conf 中有绝对路径的问题的答案是,您可以将构建目录放在系统的任何位置,而不依赖于 Yocto。

层的相对路径必须始终相对于构建目录。

我找到了使用相对路径的方法。

可以使用inline python遍历文件系统。以下脚本使用提供的 TOPDIR 变量,然后通过 python 的 os.path api.

导航到其父级
# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
LCONF_VERSION = "6"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

YOCTOROOT = "${@os.path.abspath(os.path.join("${TOPDIR}", os.pardir))}"

BBLAYERS ?= " \
  ${YOCTOROOT}/poky/meta \
  ${YOCTOROOT}/poky/meta-yocto \
  ${YOCTOROOT}/poky/meta-yocto-bsp \
"

BBLAYERS_NON_REMOVABLE ?= " \
  ${YOCTOROOT}/poky/meta \
  ${YOCTOROOT}/poky/meta-yocto \
"

参考资料

我已经设法通过替换

使 bblayers.conf 文件中的 "relative paths" 正常工作
BBLAYERS ?= " \
  /home/username/poky/meta \
  ...

BBLAYERS ?= " \
  ${TOPDIR}/../meta \
  ...

我想这种方法的一个警告是我依赖 meta-XXX 图层目录始终位于 TOPDIR 的父文件夹中。这似乎是使用 yocto 的默认方式的情况,但对于更多自定义构建设置可能并非如此。

我正在使用 Rocko 版本 我的 bblayers.conf 文件也不支持相对路径 我尝试使用 TEMPLATECONF 变量更改 bblayers.conf 文件。 TEMPLATECONF 变量指向包含 bblayers.conf.samplelayer.conflocal.conf.sample 的目录。 我导出 TEMPLATECONF 变量以在构建目录中获取所需的 bblayers.conflocal.conf 文件,但在我的 bblayers.conf.sample 中, BBLAYERS 变量是由相对路径设置的如下图:

BBLAYERS ?= " \
  ##OEROOT##/meta \
  ##OEROOT##/../meta-xilinx \
  ##OEROOT##/../meta-xilinx-tools \
  ##OEROOT##/../meta-openembedded/meta-oe \
  ##OEROOT##/../meta-openembedded/meta-perl \
  ##OEROOT##/../meta-openembedded/meta-python \
  ##OEROOT##/../meta-openembedded/meta-multimedia \
  ##OEROOT##/../meta-openembedded/meta-networking \
  ##OEROOT##/../meta-openembedded/meta-filesystems \
  ##OEROOT##/../meta-openembedded/meta-webserver"

但它似乎不起作用。OEROOT 变量无法设置正确的路径。 一个原因可能是 oe-init-build-env 脚本结束时取消设置 OEROOT 变量。 尽管如果您手动将 OEROOT 变量导出到您需要的值,它可能会有所帮助。 但是,当我从 OEROOT 更改为 TOPDIR 变量时,它就像一个魅力,如下所示:

BBLAYERS ?= " \
  ${TOPDIR}/../meta \
  ${TOPDIR}/../meta-poky \
  ${TOPDIR}/../meta-skeleton \
  ${TOPDIR}/../meta-selftest \
  ${TOPDIR}/../meta-yocto-bsp \
  ${TOPDIR}/../../meta-xilinx/meta-xilinx-bsp \
  ${TOPDIR}/../../meta-xilinx/meta-xilinx-contrib \
  ${TOPDIR}/../../meta-xilinx-tools \
  ${TOPDIR}/../../meta-openembedded/meta-oe \
  ${TOPDIR}/../../meta-openembedded/meta-perl \
  ${TOPDIR}/../../meta-openembedded/meta-python \
  ${TOPDIR}/../../meta-openembedded/meta-multimedia \
  ${TOPDIR}/../../meta-openembedded/meta-networking \
  ${TOPDIR}/../../meta-openembedded/meta-filesystems \
  ${TOPDIR}/../../meta-openembedded/meta-webserver"

这可能让我认为 oe-root-init-env 脚本取消设置 OEROOT 变量导致了问题。 另外,如果有人找到更好的解决方案,请回复。

所有现有答案都在回答 "how to use relative paths",但问题是 "why are absolute paths used"。据我所知 "why" 很简单,这样做是为了让构建目录可以移动到文件系统的任何地方。想一想:您可以从文件系统上的任何位置获取 poky/oe-init-build-env,构建目录将在那里创建,因此依赖于相对于构建目录的路径是非常脆弱的。

编辑:

也许这更清楚,我想你假设文件 bblayers.conf 总是在 poky/build/conf/bblayers.conf 中,因此你可以使用像 ../../meta-layer-foo 这样的路径来引用某个层这将在 poky/meta-layer-foo 中,但如果我在另一个路径 poky/foo/bar:

中实例化 "build",将找不到该层
etienne@ubuntu:~/repos/poky-tx2$ mkdir -p foo/bar
etienne@ubuntu:~/repos/poky-tx2$ cd foo/bar/
etienne@ubuntu:~/repos/poky-tx2/foo/bar$ ls
etienne@ubuntu:~/repos/poky-tx2/foo/bar$ source ../../oe-init-build-env 
You had no conf/local.conf file. This configuration file has therefore been
created for you with some default values. You may wish to edit it to, for
example, select a different MACHINE (target hardware). See conf/local.conf
for more information as common configuration options are commented.

You had no conf/bblayers.conf file. This configuration file has therefore been
created for you with some default values. To add additional metadata layers
into your configuration please add entries to conf/bblayers.conf.

The Yocto Project has extensive documentation about OE including a reference
manual which can be found at:
    http://yoctoproject.org/documentation

For more information about OpenEmbedded see their website:
    http://www.openembedded.org/


### Shell environment set up for builds. ###

You can now run 'bitbake <target>'

Common targets are:
    core-image-minimal
    core-image-sato
    meta-toolchain
    meta-ide-support

You can also run generated qemu images with a command like 'runqemu qemux86'
etienne@ubuntu:~/repos/poky-tx2/foo/bar/build$ ls
conf

正如您在自我评论中提到的,bblayers.conf

intended to be specific to a user on a machine and only temporary.

恕我直言,这个想法是 bblayers.conf 永远不应该在开发人员之间分发。尽管如此,如果层的绝对路径是特定于每个开发人员的系统安装的,那么将实际的层列表保留为项目的一部分似乎是合理的。

受 Kamal Pandey 的回答启发,我想出了一个利用 oe-init-build-env 脚本背后的模板文件引擎的解决方案。

通过将 conf/templateconf.cfg 的内容更改为 conf(而不是默认的 meta-poky/conf),您指示 oe-init-build-env 在您的配置目录中添加任何缺少的文件它的 .sample 对应物(现在位于您的 conf 目录中)。

这样,将 bblayers.conf 重命名为 bblayers.conf.sample 后,您就可以使用 OEROOT 变量(不幸的是,在 oe-init-build-env 调用后该变量不再可用)。

# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf                                                                                                                                      
# changes incompatibly                                                                                                                                                                                            
POKY_BBLAYERS_CONF_VERSION = "2"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

BBLAYERS ?= " \                                                                                                                                                                                                   
  ##OEROOT##/meta \                                                                                                                                                                                               
  ##OEROOT##/meta-poky \                                                                                                                                                                                          
  ##OEROOT##/meta-yocto-bsp \                                                                                                                                                                                     
  ${TOPDIR}/meta-tensorflow-lite \                                                                                                                                                                                
  "

有了这个 bblayers.conf.sample 文件,您现在可以使用 ##OEROOT## 替换变量来引用相对于您的 poky 安装目录的文件。通过删除 bblayers.conf(或不删除 versioning/ditributing),您可以确保采购 oe-init-build-env 将以正确的绝对值重新生成 bblayers.conf