bitbake

Introduction

bitbake is the primary command in the system. It facilitates executing tasks in a single .bb file, or executing a given task on a set of multiple .bb files, accounting for interdependencies amongst them.

Usage and Syntax

$ bitbake --help
usage: bitbake [options] [package ...]

Executes the specified task (default is 'build') for a given set of BitBake files.
It expects that BBFILES is defined, which is a space seperated list of files to
be executed.  BBFILES does support wildcards.
Default BBFILES are the .bb files in the current directory.

options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -b BUILDFILE, --buildfile=BUILDFILE
                        execute the task against this .bb file, rather than a
                        package from BBFILES.
  -k, --continue        continue as much as possible after an error. While the
                        target that failed, and those that depend on it,
                        cannot be remade, the other dependencies of these
                        targets can be processed all the same.
  -f, --force           force run of specified cmd, regardless of stamp status
  -i, --interactive     drop into the interactive mode.
  -c CMD, --cmd=CMD     Specify task to execute. Note that this only executes
                        the specified task for the providee and the packages
                        it depends on, i.e. 'compile' does not implicitly call
                        stage for the dependencies (IOW: use only if you know
                        what you are doing)
  -r FILE, --read=FILE  read the specified file before bitbake.conf
  -v, --verbose         output more chit-chat to the terminal
  -D, --debug           Increase the debug level
  -n, --dry-run         don't execute, just go through the motions
  -p, --parse-only      quit after parsing the BB files (developers only)
  -d, --disable-psyco   disable using the psyco just-in-time compiler (not
                        recommended)
  -s, --show-versions   show current and preferred versions of all packages
  -e, --environment     show the global or per-package environment (this is
                        what used to be bbread)

Example 4.1. Executing a task against a single .bb

Executing tasks for a single file is relatively simple. You specify the file in question, and bitbake parses it and executes the specified task (or “build” by default). It obeys intertask dependencies when doing so.

clean” task:

$ bitbake -b blah_1.0.bb -c clean

build” task:

$ bitbake -b blah_1.0.bb

Example 4.2. Executing tasks against a set of .bb files

There are a number of additional complexities introduced when one wants to manage multiple .bb files. Clearly there needs to be a way to tell bitbake what files are available, and of those, which we want to execute at this time. There also needs to be a way for each .bb to express its dependencies, both for build time and runtime. There must be a way for the user to express their preferences when multiple .bb's provide the same functionality, or when there are multiple versions of a .bb.

The next section, Metadata, outlines how one goes about specifying such things.

Note that the bitbake command, when not using --buildfile, accepts a PROVIDER, not a filename or anything else. By default, a .bb generally PROVIDES its packagename, packagename-version, and packagename-version-revision.

$ bitbake blah
$ bitbake blah-1.0
$ bitbake blah-1.0-r0
$ bitbake -c clean blah
$ bitbake virtual/whatever
$ bitbake -c clean virtual/whatever

Metadata

As you may have seen in the usage information, or in the information about .bb files, the BBFILES variable is how the bitbake tool locates its files. This variable is a space seperated list of files that are available, and supports wildcards.

Example 4.3. Setting BBFILES

BBFILES = "/path/to/bbfiles/*.bb"

With regard to dependencies, it expects the .bb to define a DEPENDS variable, which contains a space seperated list of “package names”, which themselves are the PN variable. The PN variable is, in general, by default, set to a component of the .bb filename.

Example 4.4. Depending on another .bb

a.bb:

PN = "package-a"
DEPENDS += "package-b"

b.bb:

PN = "package-b"

Example 4.5. Using PROVIDES

This example shows the usage of the PROVIDES variable, which allows a given .bb to specify what functionality it provides.

package1.bb:

PROVIDES += "virtual/package"

package2.bb:

DEPENDS += "virtual/package"

package3.bb:

PROVIDES += "virtual/package"

As you can see, here there are two different .bb's that provide the same functionality (virtual/package). Clearly, there needs to be a way for the person running bitbake to control which of those providers gets used. There is, indeed, such a way.

The following would go into a .conf file, to select package1:

PREFERRED_PROVIDER_virtual/package = "package1"

Example 4.6. Specifying version preference

When there are multiple “versions” of a given package, bitbake defaults to selecting the most recent version, unless otherwise specified. If the .bb in question has a DEFAULT_PREFERENCE set lower than the other .bb's (default is 0), then it will not be selected. This allows the person or persons maintaining the repository of .bb files to specify their preferences for the default selected version. In addition, the user can specify their preferences with regard to version.

If the first .bb is named a_1.1.bb, then the PN variable will be set to “a”, and the PV variable will be set to 1.1.

If we then have an a_1.2.bb, bitbake will choose 1.2 by default. However, if we define the following variable in a .conf that bitbake parses, we can change that.

PREFERRED_VERSION_a = "1.1"

Example 4.7. Using “bbfile collections

bbfile collections exist to allow the user to have multiple repositories of bbfiles that contain the same exact package. For example, one could easily use them to make one's own local copy of an upstream repository, but with custom modifications that one does not want upstream. Usage:

BBFILES = "/stuff/openembedded/*/*.bb /stuff/openembedded.modified/*/*.bb"
BBFILE_COLLECTIONS = "upstream local"
BBFILE_PATTERN_upstream = "^/stuff/openembedded/"
BBFILE_PATTERN_local = "^/stuff/openembedded.modified/"
BBFILE_PRIORITY_upstream = "5"
BBFILE_PRIORITY_local = "10"