Search code examples
yoctoyocto-recipe

Need clarification regarding when to use bb/inc file in Yocto


New to Yocto here and still getting familiar with it so might be a naive question so i have a clarification on when to create inc or bb file for a package. So let say i have a package A and my project already have a recipe bb file for it let say A.bb. Now if i am adding a new dependency to A for a different project B , than what i am still unsure is should i create a inc file for project B let say B.inc and than include it in A.bb like this require B.inc or should i create a bb file for project B instead let say B.bb and than add inherit B in A.bb.

another clarification i have is that if i understand correctly your package can override/append stuff to bb recipe like X.bb by creating bbappend file like X.bbappend, but is it true for can inc file as well and if what file does your package create etc. Thanks in advance.

I also need to ask how to apply patches in .inc file for example if i need to apply a patch in A.bb what i have found is that if the code recipe looks like this

SRC_URI = "git://foopackage;protocol=ssh;branch=mainline;/
           file://foo.patch \
           " 

All i need to do is add a foo.patch in a subfolder foo and it will be applied, is that true for inc file as well i.e if i have B.inc file and it is something like this

SRC_URI = "git://barpackage;protocol=ssh;branch=mainline;/
           file://bar.patch \
           "

Does it mean that i need to create a subfolder bar in the folder that B.inc is for the patch to apply.


Solution

  • A .bb file is a recipe, one could say that's a top level entity.

    You can literally append new information to a recipe using .bbappend files - when you build the recipe (the .bb file), all relevant .bbappend files will be merged. The .bbappend files can also contain some information that has been already declared in the .bb file, in which case the .bbappend version will take effect. You can also have multiple .bbappend files for the same recipe. When they are in different layers, the layer's priority decides the order in which they are applied. .bbappend files need to have the same name as the corresponding .bb file to take effect (version wildcard % is allowed). They are used when you need to modify the original recipe for whatever reason: delete/add a file, add a patch or change config, etc...

    .inc files are not recipes. They can be included in recipes (or even in .bbclass or even in other .inc files). They work pretty much the same way as include headers in C/C++. They are used to avoid duplication in recipes. When you include them in the recipe with include whatever.inc, the content of the include file is basically copied into the recipe instead of the include statement (just like with C/C++ during preprocessing). You can't build anything with only include files - include files must be included in other enitities. E.g. personally I use .inc files extensively with Firefox and Thunderbird: they use pretty much the same build process, lot of the sources are the same, etc... In the .bb files I specify only the differences between the applications, the common parts ar extracted into a .inc file in the same folder, and that file is used by both recipes.

    Since we are on topic, it's worth mentioning that you can use include whatever.inc or require whatever.inc in your recipe. Their effect is almost exactly the same. However when you use require, and the specified file doesn't exist, that generates a fatal error and stops the build. When using include, the build will continue even if the specified file can't be found.

    Regarding inheriting: you can't inherit other recipes nor include files. You can inherit classes (.bbclass). Classes behave in a very similar way to .inc files: when you build the recipe, their content is copied into the recipe itself, and the class' content will behave like it was part of the original recipe. Once again, the main point is to avoid duplication across recipes: common behavior is moved to bbclass classes. The main difference between include files are classes is locality: include files are usually included in the same folder as the recipe itself - you can refer to it with a relative path. Classes are more global: they are in the classes folder of the layer (though you can configure them), and they can be inherited by any recipe you are using, even from a different layer (think of cmake or autotools classes, for example). Include files are more local, you have to know where the include file is, and if you want to use an include file from a different layer, you are only looking for troubles.

    Regarding patches: any files with .patch extension that you add to the SRC_URI variable will be applied after fetching and unpacking all sources. It doesn't matter how/where you add these files, it can be in the original .bb, .bbappend, .inc or even in .bbclass files. The main point is the SRC_URI variable.

    Hope this helps.