Search code examples
yoctobitbakeopenembedded

function in recipe not overridden


I want to override a function in a recipe (bb) that inherits from a bbclass, but it doesn't work -- the function from the bbclass (superclass) is executed instead of the new one.

Here is an minimal (non-)working example.

Class:

# myclass.bbclass

do_compile() {
    echo MyClass
}

Recipe:

# myrecipe.bb

do_compile() {
    echo MyRecipe
}

inherit myclass

After I compile the recipe, the log file looks like this:

$ cat temp/log.do_compile
DEBUG: Executing shell function do_compile
MyClass
DEBUG: Shell function do_compile finished

Why doesn't overriding of do_compile work?


Solution

  • The position of inherit in the recipe file is important. If you put it in the beginning of the file (before the function do_compile is defined in the (subclass) recipe), it works.

    Recipe:

    # myrecipe.bb
    
    inherit myclass
    
    do_compile() {
        echo MyRecipe
    }
    

    After compiling the recipe the log file looks like this:

    $ cat temp/log.do_compile
    DEBUG: Executing shell function do_compile
    MyRecipe
    DEBUG: Shell function do_compile finished