构建 core-image-minimal.bb 时如何包含 poky/meta/lib/oe/image.py?

How does poky/meta/lib/oe/image.py get included when building core-image-minimal.bb?

我正在使用 Yocto 项目,Jethro 版本。但是,我认为这个问题也适用于其他版本。

我需要修改图像创建过程。我已经阅读了 BitBake 手册,但我仍然不知道完整的 python 脚本或多个脚本是如何包含的。

这是我目前的发现:

bitbake core-image-mininmal

bitbake 读取所有配置文件并解析后 bblayers.conf,它会在所有图层目录中搜索配方 core-image-minimal.bb

core-image-minimal.bb中,我们有:

inherit core-image

这继承了 class core-image.bbclass 又继承了 image.bbclass包含 bitbake 代码:

fakeroot python do_rootfs () {
    from oe.rootfs import create_rootfs
    from oe.image import create_image
    from oe.manifest import create_manifest

    # generate the initial manifest
    create_manifest(d)

    # generate rootfs
    create_rootfs(d)

    # generate final images
    create_image(d)
}

搜索文本 create_image 的源代码树,我在 image.py 中找到以下内容:

def create_image(d):
    Image(d).create()

还有:

def create(self):
    bb.note("###### Generate images #######")
    pre_process_cmds = self.d.getVar("IMAGE_PREPROCESS_COMMAND", True)
    post_process_cmds = self.d.getVar("IMAGE_POSTPROCESS_COMMAND", True)

我还创建了自己的 class my-class.bbclass 并在其中放入以下内容:

fakeroot python do_rootfs_prepend () {
    print("==> do_rootfs_prepend")
}

fakeroot python do_rootfs_append () {
    print("==> do_rootfs_append")
}

并且我在日志文件中看到了消息,所以我知道这可以将我的 python 代码添加到 do_rootfs 函数中 image.bbclass.

但是,我仍然想知道如何包含 image.py 和一大堆其他 *.py 文件(例如 rootfs.py) 来自 poky/meta/lib/oe 目录。

首先,请注意 rootfs/image 代码在 Jethro 发布后进行了大量重构:最新版本没有您示例中提到的一些功能。

库函数使用中没有 Yocto 特有的魔法:它们通过标准 python 模块导入使用,只需在模块搜索路径中使用 meta/lib/,例如

from oe.image import create_image

将使 meta/lib/oe/image.py 中的 create_image() 函数在当前范围内可用。