diff --git a/bitbake/doc/user-manual/user-manual-metadata.xml b/bitbake/doc/user-manual/user-manual-metadata.xml
index 7c294008c0..c2342a2236 100644
--- a/bitbake/doc/user-manual/user-manual-metadata.xml
+++ b/bitbake/doc/user-manual/user-manual-metadata.xml
@@ -677,73 +677,81 @@
Functions
-
- This is only supported in .bb
- and .bbclass files.
-
-
As with most languages, functions are the building blocks
that define operations.
- Bitbake supports shell and Python functions.
- An example shell function definition is:
-
+ BitBake supports three types of functions:
+
+ Shell Functions:
+ Functions written in a shell language and
+ executed by the shell.
+
+ BitBake Functions:
+ Functions written in Python but executed by BitBake using
+ bb.build.exec_func().
+
+ Python Functions:
+ Functions written in Python and executed by Python.
+
+
+ Regardless of the type of function, you can only
+ define them in class (.bbclass)
+ and recipe (.bb) files.
+
+
+
+ Shell Functions
+
+
+ These functions are written using a shell language and
+ executed by the shell.
+ Here is an example shell function definition:
+
some_function () {
echo "Hello World"
}
-
- An example Python function definition is:
-
+
+ When you create these types of functions in your recipe
+ or class files, you need to follow the shell programming
+ rules.
+
+
+
+
+ BitBake Functions
+
+
+ These functions are written in Python and are executed using
+ bb.build.exec_func().
+
+
+
+ An example BitBake function is:
+
python some_python_function () {
d.setVar("TEXT", "Hello World")
print d.getVar("TEXT", True)
}
-
- In python functions, the "bb" and "os" modules are already
- imported, there is no need to import those modules.
- The datastore, "d" is also a global variable and always
- available to these functions automatically.
-
+
+ Because the Python "bb" and "os" modules are already
+ imported, you do not need to import these modules.
+ Also in these types of functions, the datastore ("d")
+ is a global variable and is always automatically
+ available.
+
+
-
- Bitbake will execute functions of this form using
- the bb.build.exec_func(), which can also be
- called from Python functions to execute other functions,
- either shell or Python based.
- Shell functions can only execute other shell functions.
-
+
+ Python Functions
-
- There is also a second way to declare python functions with
- parameters which takes the form:
-
- def some_python_function(arg1, arg2):
- print arg1 + " " + arg2
-
- The difference is that the second form takes parameters,
- the datastore is not available automatically
- and must be passed as a parameter and these functions are
- not called with the exec_func() but are
- executed with direct Python function calls.
- The "bb" and "os" modules are still automatically available
- and there is no need to import them.
-
-
-
-
- Defining Pure Python functions
-
-
- This is only supported in .bb
- and .bbclass files.
-
-
-
- For utility functions that you intend to call from
- in-line Python or other Python functions, BitBake allows
- you to define these as pure Python functions.
- Here is an example:
-
+
+ These functions are written in Python but are executed by
+ Python.
+ Examples of Python functions are utility functions
+ that you intend to call from in-line Python or
+ from within other Python functions.
+ Here is an example:
+
def get_depends(d):
if d.getVar('SOMECONDITION', True):
return "dependencywithcond"
@@ -751,10 +759,28 @@
return "dependency"
SOMECONDITION = "1"
DEPENDS = "${@get_depends(d)}"
-
- This would result in DEPENDS
- containing dependencywithcond.
-
+
+ This would result in DEPENDS
+ containing dependencywithcond.
+
+
+
+ Here are some things to know about Python functions:
+
+ Python functions take parameters.
+
+ The BitBake datastore is not
+ automatically available.
+ Consequently, you must pass it in as a
+ parameter to the function.
+
+ The "bb" and "os" Python modules are
+ automatically available.
+ You do not need to import them.
+
+
+
+