bitbake: user-manual-metadata: Rework section about shell/python functions
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 18 Jan 2014 14:26:07 +0000 (14:26 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 27 Jan 2014 21:03:21 +0000 (21:03 +0000)
(Bitbake rev: c2bcb5364ff7c702bc1ec2726169f608b445f979)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
bitbake/doc/user-manual/user-manual-metadata.xml

index 23b3fa6..55b59eb 100644 (file)
         </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>