From 9889a91a5b84175b91fec05b7a40234f72ac09b2 Mon Sep 17 00:00:00 2001 From: Scott Rifenbark Date: Fri, 11 Apr 2014 11:47:57 -0700 Subject: bitbake: bitbake-user-manual-metadata.xml: Edits to flexible inheritance section. Fixes [YOCTO #5472] Applied review edits from Paul Eggleton to this section. Minor edits and some re-writing. (Bitbake rev: 7259d9d40aad8254751f7674653cd362a9023054) Signed-off-by: Scott Rifenbark Signed-off-by: Richard Purdie --- .../bitbake-user-manual-metadata.xml | 63 +++++++++++++--------- 1 file changed, 37 insertions(+), 26 deletions(-) (limited to 'bitbake/doc') diff --git a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml index 41ae3b8c0a..365c4b8f97 100644 --- a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml +++ b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml @@ -793,36 +793,35 @@ -
- Automatically Mapping Functions Within the Context of a Class +
+ Flexible Inheritance for Class Functions Through coding techniques and the use of EXPORT_FUNCTIONS, BitBake supports - automatic mapping for functions within the context of - a class. + exporting a function from a class such that the + class function appears as the default implementation + of the function, but can still be called if a recipe + inheriting the class needs to define its own version of + the function. - To understand the benefits of this feature, consider the basic scenario - where a class defines a function and your recipe inherits the class. - In this basic scenario, your recipe has access to the function in the - class by way of inheritance and can freely call and use the function - as defined in the class. - However, if you need to have a modified version of that function - in your recipe you are limited to using either your modified version - of the function or using "prepend_" or "_append" operators to add - code to be executed before or after the original function in the - class. - Your recipe cannot use both versions of the fucntion. + To understand the benefits of this feature, consider + the basic scenario where a class defines a task function + and your recipe inherits the class. + In this basic scenario, your recipe inherits the task + function as defined in the class. + If desired, your recipe can add to the start and end of the + function by using the "_prepend" or "_append" operations + respectively, or it can redefine the function completely. + However, if it redefines the function, there is + no means for it to call the class version of the function. - Function mapping allows you to access both your custom function - function that is defined in the recipe and the original function that - is defined in the class. - You have this access all from within your recipe. - To accomplish this, you need some things in place: + To make use of this technique, you need the following + things in place: The class needs to define the function as follows: @@ -853,12 +852,24 @@ You need to call the function appropriately from within your recipe. - Continuing with the same example, - your recipe would call the do_foo function - from the recipe by referring to it as - bar_do_foo. - To call your modified version of the function as defined in your - recipe, call it as do_foo. + Continuing with the same example, if your recipe + needs to call the class version of the function, + it should call bar_do_foo. + Assuming do_foo was a shell function + and EXPORT_FUNCTIONS was used as above, + the recipe's function could conditionally call the + class version of the function as follows: + + do_foo() { + if [ somecondition ] ; then + bar_do_foo + else + # Do something else + fi + } + + To call your modified version of the function as defined + in your recipe, call it as do_foo. With these conditions met, your single recipe -- cgit v1.2.3-54-g00ecf