Grasping the BitBake Tool
在上一章中,我们了解了元数据、元数据集合概念以及 conf/layer.conf 的重要性。在本章中,我们将更深入地研究元数据,了解配方如何相互依赖,并了解 BitBake 如何处理依赖关系。
In the previous chapter, we learned about metadata, metadata collection concepts, and the importance of
conf/layer.conf
. In this chapter, we will examine metadata more deeply, understand how recipes depend on each other, and see how BitBake deals with dependencies.
此外,我们还将涵盖从下载源代码到生成映像和其他工件的大量任务。这些任务包括将源代码存储在用于构建的目录中、打补丁、配置、编译、安装和生成软件包,以及确定软件包如何与本章将介绍的生成映像相匹配。
In addition, we will cover a massive list of tasks, from downloading source code to generating images and other artifacts. Some examples of these tasks are storing the source code in the directory used for the build, patching, configuring, compiling, installing, and generating packages, and determining how the packages fit into the generated images, which we will introduce in this chapter.
1,Parsing metadata
通常,我们的项目包括多个层,这些层提供不同的元数据,以满足特定需求。例如,当我们使用source oe-init-build-env build 初始化构建目录时,会生成如下一组文件:
Usually, our projects include multiple layers that provide different metadata to fulfill specific needs. For example, when we initialize a build directory, using
source oe-init-build-env build, a set of files is generated as follows:

[ Figure 5.1 – A list of files created with source oe-init-build-env build ]
build/conf/templateconf.cfg 文件指向用作创建 build/conf 目录模板的目录。
The
build/conf/templateconf.cfg file points to the directory used as the template to create the
build/conf directory.
注意
用户可以使用 TEMPLATECONF 环境变量提供不同的模板目录,例如
TEMPLATECONF=/some/dir source oe-init-build-env build。
Note
A user can provide a different template directory using the TEMPLATECONF environment variable – for example,
TEMPLATECONF=/some/dir source oe-init-build-env build.
build/conf/local.conf 文件是本地配置的占位符。我们在第 2 章 “构建第一个基于 Poky 的系统 ”中使用了该文件,并将在本书中继续使用。
The
build/conf/local.conf file is the placeholder for the local configurations. We used this file in Chapter 2, Baking Our First Poky-Based System, and we will use it throughout this book.
BitBake 使用 build/conf/bblayers.conf 文件列出构建环境中考虑的图层。示例如下:
BitBake uses the
build/conf/bblayers.conf file to list the layers considered in the build environment. An example is as follows:

[ Figure 5.2 – The build/conf/bblayer.conf content after the source oe-init-build-env build ]
第 8 行的 BBLAYERS 变量是一个用空格分隔的图层目录列表。BitBake 会解析每个图层,将其内容加载到元数据集合中。BitBake 使用的元数据可分为三大类。具体如下
The BBLAYERS variable, on line 8, is a space-delimited list of layer directories. BitBake parses each layer to load its content to the metadata collection. There are three major categories that the metadata used by BitBake can be classified into. They are listed as follows:
* Configuration (the .conf files)
* Classes (the .bbclass files)
* Recipes (the .bb and .bbappend files)
Tip
BitBake 在解析元数据时,会按照从左到右的顺序使用 BBLAYERS 变量中列出的图层。因此,如果你的图层需要优先解析,请将其列在 BBLAYERS 变量的正确位置。
The order of the listed layers in the
BBLAYERS variable is followed from left to right by BitBake when parsing the metadata. Therefore, if your layer needs to be parsed first, have it listed in the right place in the
BBLAYERS variable.
解析完所有可用图层后,BitBake 开始解析元数据。BitBake 首先解析的元数据是配置元数据,以 .conf 文件扩展名标识。这种元数据是全局性的,因此会影响所有已执行的配方和任务。
After parsing all the layers in use, BitBake starts to parse the metadata. The first parsed metadata in BitBake is configuration metadata, identified by the .conf file extension. This metadata is global and, therefore, affects all executed recipes and tasks.
Note
配置文件的一个典型例子是机器文件,它包含一个描述硬件的设置列表。
One typical example of the configuration file is the machine file, which has a list of settings that describes the hardware.
BitBake 首先从 BBPATH 列表中包含的路径之一加载
meta/conf/bitbake.conf。
meta/conf/bitbake.conf 文件使用 include 指令调入元数据,如特定架构元数据、机器配置文件和
build/conf/local.conf 文件。BitBake 配置文件(.conf)的一个重要限制是只允许使用变量定义和 include 指令。
BitBake first loads meta/conf/bitbake.conf from one of the paths included in the BBPATH list. The meta/conf/bitbake.conf file uses include directives to pull in metadata, such as architecture-specific metadata, machine configuration files, and the build/conf/local.conf file. One significant restriction of BitBake configuration files (.conf) is that only variable definitions and include directives are allowed.
BitBake 的类(
.bbclass)是 classes/ 目录中最基本的继承机制。当解析过程中出现继承指令时,BitBake 会立即解析链接的类。类的内容会根据 BBPATH 变量列表的顺序进行搜索。
BitBake’s classes (.bbclass) are a rudimentary inheritance mechanism in the classes/ directories. When an inherit directive appears during parsing, BitBake immediately parses the linked class. The class content is searched based on the order of the BBPATH variable list.
BBFILES 变量是以空格分隔的 .bb 和 .bbappend 文件列表,可以使用通配符。conf/layer.conf 中的每一层都需要使用该变量,这样 BitBake 才能知道在哪里查找配方。BitBake 配方(.bb)是要执行的任务的逻辑单元;通常指一个软件包。
The BBFILES variable is a space-separated list of the .bb and .bbappend files and can use wildcards. It is required in every layer inside conf/layer.conf, so BitBake knows where to look for recipes. A BitBake recipe (.bb) is a logical unit of tasks to be executed; typically, it refers to a package.
2,Dependencies
从 BitBake 的角度来看,有三种不同的依赖类型:
From the BitBake point of view, there are three different dependency types:
* Build time
* Execution time
* Tasks
应用程序如果需要其他软件包(如库),则成功编译就有一个联编依赖。联编依赖包括编译器、库和本地联编工具(如 CMake)。此外,只要应用程序只在执行时才需要,联编依赖关系就具有执行依赖关系。运行时依赖项包括字体、图标、动态打开的库和语言解释器。
An application that needs some other package, such as a library, has a build dependency for a successful compilation. Build dependencies include compilers, libraries, and native build tools (such as CMake). In addition, a build dependency has an execution dependency whenever an application is needed only during execution time. Runtime dependencies include fonts, icons, dynamically opened libraries, and language interpreters.
Tip
Poky 的惯例是在配方名称中使用 -native 后缀。这是因为这些工具的目的是在构建过程中在主机构建系统中运行,而不是部署到目标中。
The convention inside Poky is to use -native suffixes for recipe names. This is because those tools are aimed to be run during the build process, in the host building system, and are not deployed into the target.
任务依赖关系为混乱的任务执行创造了秩序,例如,要编译一个软件包,就需要下载源代码。在表面下,所有的依赖关系都是任务依赖关系。这意味着,当软件包 B 在构建时依赖于软件包 A 时,软件包 A 的任务需要在软件包 B 启动前完成。
The task d