3
votes

I'm building an image with Yocto, and need to patch a BitBake class in the upstream tree. I do not want to modify the upstream sources and would prefer to add the modification to a local layer.

For a BitBake recipe, I'd use a .bbappend file. What should be used for a class?

3

3 Answers

6
votes

Create classes folder in your meta layer and create a new class, e.g. myclass.bbclass. Inherit original class with inherit original-bitbake-CLASS and add whatever functionality you need.

Then use the new bbclass instead of the original.

4
votes

@lukaszgard method works except for one minor issue. BBFILE_PRIORITY does not provide override capability for bbclass and conf files, it only works for recipes (.bb). This is based on a section of the Yocto manual, Prioritizing Your Layer where it says

Note: It is possible for a recipe with a lower version number PV in a layer that has a higher priority to take precedence. Also, the layer priority does not currently affect the precedence order of .conf or .bbclass files. Future versions of BitBake might address this.

A method I found that works is to create a bblayer, create and apply changes of the required bbclass and then in /build/conf/bblayers.conf, place the created bblayer above the layer that you are trying to override.

This is based on another section of the Yocto manual which says

Note: During a build, the OpenEmbedded build system looks in the layers from the top of the list down to the bottom in that order.

An example:

BBLAYERS ?= " \
  ${TOPDIR}/../layers/<layer with new bbclass> \
  ${TOPDIR}/../layers/<layer with old bbclass> \
"
1
votes

Generally with .bbclass files there is lack of similar approach like we have with appending recipes (.bbappends). Proposed by @Oleksandr-Kravchuk solution is good but have some limitations. When You have to modify some functions or makes more complex changes, then I would prefer to copy this class file to my metadata layer and make adaptations there. Finally bitbake based on configuration in layer (conf/layer.conf file) - BBFILE_PRIORITY will decide to take this class file comes from layer with higher priority lever - without touching recipes.