From e6f12157a210084d1a870832107c910df792f1d9 Mon Sep 17 00:00:00 2001 From: Scott Rifenbark Date: Tue, 4 Oct 2016 09:58:44 -0700 Subject: bitbake-user-manual: Added new section on BB-style functions Fixes [YOCTO #10364] Added a new section titled "Bitbake-Style Python Functions Versus Python Functions". This section describes differences for the user between the two types of functions. Also, cleaned up a consistency problem with the terms "BitBake style" and "BitBake-style". I used the latter throughout the manual. Signed-off-by: Scott Rifenbark Signed-off-by: Richard Purdie --- .../bitbake-user-manual-metadata.xml | 99 +++++++++++++++++++++- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml b/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml index 5636a3562..53e182ba6 100644 --- a/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml +++ b/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml @@ -283,7 +283,7 @@ functions and BitBake-style Python functions. See the "Shell Functions" and - "BitBake Style Python Functions + "BitBake-Style Python Functions sections for examples. @@ -1060,7 +1060,7 @@ directly as functions, tasks, or both. They can also be called by other shell functions. - BitBake Style Python Functions: + BitBake-Style Python Functions: Functions written in Python and executed by BitBake or other Python functions using bb.build.exec_func(). @@ -1152,7 +1152,7 @@
- BitBake Style Python Functions + BitBake-Style Python Functions These functions are written in Python and executed by @@ -1261,6 +1261,99 @@
+
+ Bitbake-Style Python Functions Versus Python Functions + + + Following are some important differences between + BitBake-style Python functions and regular Python + functions defined with "def": + + + Only BitBake-style Python functions can be + tasks. + + + Overrides and override-style operators can only + be applied to BitBake-style Python functions. + + + Only regular Python functions can take arguments + and return values. + + + Variable flags + such as [dirs], + [cleandirs], and + [lockfiles] can be used + on BitBake-style Python functions, but not on + regular Python functions. + + + BitBake-style Python functions generate a separate + ${T}/run.function-name.pid + script that is executed to run the function, and also + generate a log file in + ${T}/log.function-name.pid + if they are executed as tasks. + + + Regular Python functions execute "inline" and do not + generate any files in ${T}. + + + Regular Python functions are called with the usual + Python syntax. + BitBake-style Python functions are usually tasks and + are called directly by BitBake, but can also be called + manually from Python code by using the + bb.build.exec_func() function. + Here is an example: + + bb.build.exec_func("my_bitbake_style_function", d) + + + bb.build.exec_func() can also + be used to run shell functions from Python code. + If you want to run a shell function before a Python + function within the same task, then you can use a + parent helper Python function that starts by running + the shell function with + bb.build.exec_func() and then + runs the Python code. + + + To detect errors from functions executed with + bb.build.exec_func(), you + can catch the bb.build.FuncFailed + exception. + + Functions in metadata (recipes and classes) should + not themselves raise + bb.build.FuncFailed. + Rather, bb.build.FuncFailed + should be viewed as a general indicator that the + called function failed by raising an exception. + For example, an exception raised by + bb.fatal() will be caught inside + bb.build.exec_func(), and a + bb.build.FuncFailed will be raised + in response. + + + + + + + Due to their simplicity, you should prefer regular Python functions + over BitBake-style Python functions unless you need a feature specific + to BitBake-style Python functions. + Regular Python functions in metadata are a more recent invention than + BitBake-style Python functions, and older code tends to use + bb.build.exec_func() more often. + +
+
Anonymous Python Functions -- cgit 1.2.3-korg