# The BitBake Command

## 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

Following is the usage and syntax for BitBake:

         $ bitbake -h
    Usage: bitbake [options] [recipename/target ...]

        Executes the specified task (default is 'build') for a given set of target recipes (.bb files).
        It is assumed there is a conf/bblayers.conf available in cwd or in BBPATH which
        will provide the layer, BBFILES and other configuration information.

    Options:
      --version             show program's version number and exit
      -h, --help            show this help message and exit
      -b BUILDFILE, --buildfile=BUILDFILE
                            Execute tasks from a specific .bb recipe directly.
                            WARNING: Does not handle any dependencies from other
                            recipes.
      -k, --continue        Continue as much as possible after an error. While the
                            target that failed and anything depending on it cannot
                            be built, as much as possible will be built before
                            stopping.
      -a, --tryaltconfigs   Continue with builds by trying to use alternative
                            providers where possible.
      -f, --force           Force the specified targets/task to run (invalidating
                            any existing stamp file).
      -c CMD, --cmd=CMD     Specify the task to execute. The exact options
                            available depend on the metadata. Some examples might
                            be 'compile' or 'populate_sysroot' or 'listtasks' may
                            give a list of the tasks available.
      -C INVALIDATE_STAMP, --clear-stamp=INVALIDATE_STAMP
                            Invalidate the stamp for the specified task such as
                            'compile' and then run the default task for the
                            specified target(s).
      -r PREFILE, --read=PREFILE
                            Read the specified file before bitbake.conf.
      -R POSTFILE, --postread=POSTFILE
                            Read the specified file after bitbake.conf.
      -v, --verbose         Output more log message data to the terminal.
      -D, --debug           Increase the debug level. You can specify this more
                            than once.
      -n, --dry-run         Don't execute, just go through the motions.
      -S, --dump-signatures
                            Don't execute, just dump out the signature
                            construction information.
      -p, --parse-only      Quit after parsing the BB recipes.
      -s, --show-versions   Show current and preferred versions of all recipes.
      -e, --environment     Show the global or per-package environment complete
                            with information about where variables were
                            set/changed.
      -g, --graphviz        Save dependency tree information for the specified
                            targets in the dot syntax.
      -I EXTRA_ASSUME_PROVIDED, --ignore-deps=EXTRA_ASSUME_PROVIDED
                            Assume these dependencies don't exist and are already
                            provided (equivalent to ASSUME_PROVIDED). Useful to
                            make dependency graphs more appealing
      -l DEBUG_DOMAINS, --log-domains=DEBUG_DOMAINS
                            Show debug logging for the specified logging domains
      -P, --profile         Profile the command and save reports.
      -u UI, --ui=UI        The user interface to use (e.g. knotty, hob, depexp).
      -t SERVERTYPE, --servertype=SERVERTYPE
                            Choose which server to use, process or xmlrpc.
      --revisions-changed   Set the exit code depending on whether upstream
                            floating revisions have changed or not.
      --server-only         Run bitbake without a UI, only starting a server
                            (cooker) process.
      -B BIND, --bind=BIND  The name/address for the bitbake server to bind to.
      --no-setscene         Do not run any setscene tasks. sstate will be ignored
                            and everything needed, built.
      --remote-server=REMOTE_SERVER
                            Connect to the specified server.
      -m, --kill-server     Terminate the remote server.
      --observe-only        Connect to a server as an observing-only client.
      --status-only         Check the status of the remote bitbake server.

## Examples

This section presents some examples showing how to use BitBake.

### Executing a Task Against a Single Recipe

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

The following command runs the clean task on the `foo_1.0.bb` recipe file:

         $ bitbake -b foo.bb -c clean

The following command runs the build task, which is the default task, on the `foo_1.0.bb` recipe file:

         $ bitbake -b foo_1.0.bb

### Executing Tasks Against a Set of Recipe 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 recipes provide the same functionality, or when there are multiple versions of a `.bb` file.

The next section, Metadata, outlines how to specify such things.

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 foo

         $ bitbake foo-1.0

         $ bitbake foo-1.0-r0

         $ bitbake -c clean foo

         $ bitbake virtual/whatever

         $ bitbake -c clean virtual/whatever

### Generating Dependency Graphs

BitBake is able to generate dependency graphs using the dot syntax. These graphs can be converted to images using the dot application from Graphviz. Two files will be written into the current working directory: `depends.dot` containing dependency information at the package level and `task-depends.dot` containing a breakdown of the dependencies at the task level. To stop depending on common depends, one can use the "-I" depend option to omit these from the graph. This can lead to more readable graphs. This way, `DEPENDS` from inherited classes such as `base.bbclass` can be removed from the graph.

         $ bitbake -g foo

         $ bitbake -g -I virtual/whatever -I bloom foo

## Special Variables

Certain variables affect BitBake operation:

### `BB_NUMBER_THREADS`

The number of threads BitBake should run at once (default: 1).

## 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-separated list of files that are available, and supports wildcards.

### Setting `BBFILES`

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

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

### Depending on Another Recipe File

         a.bb:

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

         b.bb:

         PN = "package-b"

### 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, we have two different recipes 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"

### 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 recipes (default is 0), then it will not be selected. This allows the person or persons maintaining the repository of `.bb` files to specify their preference for the default selected version. In addition, the user can specify their preferred 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` file that BitBake parses, we can change that.

         PREFERRED_VERSION_a = "1.1"

### Using Recipe File Collections

Recipe file collections exist to allow the user to have multiple repositories of `.bb` files 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. Here is an example:

        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"