How to extend BitBake class
Asked Answered
I

3

5

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?

Incitement answered 11/8, 2018 at 19:9 Comment(0)
I
8

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.

Irritate answered 11/8, 2018 at 20:48 Comment(1)
For the record, this doesn't work. I created in my meta later classes-recipe/kernel.bbclass and simply placed two lines: inherit kernel and NEW_DEFINE = "abc". The yocto kernel recipe is using by default kernel.bbclass, and since my layer has priority, it is loading my version. But, it is not inheriting kernel.bbclass from openembedded like this post suggests it would. I get a simple error that proves that: ERROR: Nothing PROVIDES 'virtual/kernel'Hexachord
C
7

@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> \
"
Cushat answered 18/2, 2021 at 1:48 Comment(0)
F
2

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.

Fifteen answered 11/8, 2018 at 21:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.