summaryrefslogtreecommitdiffstats
path: root/bitbake/doc
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2014-01-18 14:26:07 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-01-27 21:03:21 +0000
commit8705fe23834ec9a164ca21e8c141fded97af28de (patch)
tree103fdbff2650e640e1e421ffe296053b621c4d57 /bitbake/doc
parent908fdb5cbce63e097b7c3f74205796bdf2cdbd08 (diff)
downloadast2050-yocto-poky-8705fe23834ec9a164ca21e8c141fded97af28de.zip
ast2050-yocto-poky-8705fe23834ec9a164ca21e8c141fded97af28de.tar.gz
bitbake: user-manual-metadata: Rework section about shell/python functions
(Bitbake rev: c2bcb5364ff7c702bc1ec2726169f608b445f979) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/doc')
-rw-r--r--bitbake/doc/user-manual/user-manual-metadata.xml61
1 files changed, 49 insertions, 12 deletions
diff --git a/bitbake/doc/user-manual/user-manual-metadata.xml b/bitbake/doc/user-manual/user-manual-metadata.xml
index 23b3fa6..55b59eb 100644
--- a/bitbake/doc/user-manual/user-manual-metadata.xml
+++ b/bitbake/doc/user-manual/user-manual-metadata.xml
@@ -409,22 +409,59 @@
</note>
</section>
- <section>
- <title>Defining executable metadata</title>
- <para><emphasis>NOTE:</emphasis> This is only supported in .bb and .bbclass files.
+ <section id='functions'>
+ <title>Functions</title>
+
+ <note>
+ This is only supported in <filename>.bb</filename>
+ and <filename>.bbclass</filename> files.
+ </note>
+
+ <para>
+ As with most languages, functions are the building blocks
+ that define operations.
+ Bitbake supports shell and Python functions.
+ An example shell function definition is:
+ <literallayout class='monospaced'>
+ some_function () {
+ echo "Hello World"
+ }
+ </literallayout>
+ An example Python function definition is:
<literallayout class='monospaced'>
-do_mytask () {
- echo "Hello, world!"
-}
+ python some_python_function () {
+ d.setVar("TEXT", "Hello World")
+ print d.getVar("TEXT", True)
+ }
</literallayout>
- This is essentially identical to setting a variable, except that this variable happens to be executable shell code.
+ 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.
+ </para>
+
+ <para>
+ Bitbake will execute functions of this form using
+ the <filename>bb.build.exec_func()</filename>, 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.
+ </para>
+
+ <para>
+ There is also a second way to declare python functions with
+ parameters which takes the form:
<literallayout class='monospaced'>
-python do_printdate () {
- import time
- print time.strftime('%Y%m%d', time.gmtime())
-}
+ def some_python_function(arg1, arg2):
+ print arg1 + " " + arg2
</literallayout>
- This is the similar to the previous, but flags it as Python so that BitBake knows it is Python code.
+ 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 <filename>exec_func()</filename> 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.
</para>
</section>
OpenPOWER on IntegriCloud