Bitbake – reusing work

To manage complexity Bitbake supports various constructs for writing generic reusable components and using these components in user scripts. This constructs are the core of the Yocto build system and we need to become more familiar with them.

Basic building blocks

In Bitbake, files are shared through include (.inc) and class (.bbclass) files. These files are included in other recipes with include, inherit, INHERIT and require directives.

Files that are included are looked up through BBPATH variable. Additionally, Bitbake searches the current directory for include and require directives.

Also, for include and class files to be found by Bitbake, they need to be located in “classes” subdirectory that can be found in BBPATH.

inherit Directive

Use this directive when writing a class file to inherit the functionality of a base class (.bbclass).

It can be only used withing recipe or class (.bb or .bbclass).

One example use is to use the directive to create a recipe and inherit Autoconf or Automake base class thus reusing existing code and overriding only recipe specific variables.

inherit autotools rm_work

In this case, Bitbake will search for directory classes/autotools.bbclass and classes/rm_work.bbclass in BBPATH.

Advantage with inherit directive when compared to both include and require directives is that you can inherit class files conditionally. This can be done using variable expression.

inherit ${VARNAME}

And variable can be set using conditions, python tasks or inline python syntax

VARIABLE = ""
VARIABLE:someoverride = "myclass"


python () {
    if condition == value:
        d.setVar('VARIABLE', 'myclass')
    else:
        d.setVar('VARIABLE', '')
}

inherit ${@'classname' if condition else ''}
inherit ${@functionname(params)}

include Directive

The include directive causes Bitbake to parser whatever file is mentioned at specific location.

If the path is relative, it will first try to find the file within BBPATH.

It does not produce error when the file cannot be found.

require Directive

This directive is the same as include, but will fail if the file cannot be found.

INHERIT Directive

This directive is used when writing a configuration file (.conf). It’s main purpose is to inherit a class for a configuration.

INHERIT += "abc"
// or
INHERIT += "autotools pkconfig"

Useful thing about this directive is that it does not require the person to write bitbake recipes (.bb) if not needed.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *