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)
downloadpoky-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 23b3fa67d3..55b59ebcc1 100644
--- a/bitbake/doc/user-manual/user-manual-metadata.xml
+++ b/bitbake/doc/user-manual/user-manual-metadata.xml
@@ -409,22 +409,59 @@
409 </note> 409 </note>
410 </section> 410 </section>
411 411
412 <section> 412 <section id='functions'>
413 <title>Defining executable metadata</title> 413 <title>Functions</title>
414 <para><emphasis>NOTE:</emphasis> This is only supported in .bb and .bbclass files. 414
415 <note>
416 This is only supported in <filename>.bb</filename>
417 and <filename>.bbclass</filename> files.
418 </note>
419
420 <para>
421 As with most languages, functions are the building blocks
422 that define operations.
423 Bitbake supports shell and Python functions.
424 An example shell function definition is:
425 <literallayout class='monospaced'>
426 some_function () {
427 echo "Hello World"
428 }
429 </literallayout>
430 An example Python function definition is:
415 <literallayout class='monospaced'> 431 <literallayout class='monospaced'>
416do_mytask () { 432 python some_python_function () {
417 echo "Hello, world!" 433 d.setVar("TEXT", "Hello World")
418} 434 print d.getVar("TEXT", True)
435 }
419 </literallayout> 436 </literallayout>
420 This is essentially identical to setting a variable, except that this variable happens to be executable shell code. 437 In python functions, the "bb" and "os" modules are already
438 imported, there is no need to import those modules.
439 The datastore, "d" is also a global variable and always
440 available to these functions automatically.
441 </para>
442
443 <para>
444 Bitbake will execute functions of this form using
445 the <filename>bb.build.exec_func()</filename>, which can also be
446 called from Python functions to execute other functions,
447 either shell or Python based.
448 Shell functions can only execute other shell functions.
449 </para>
450
451 <para>
452 There is also a second way to declare python functions with
453 parameters which takes the form:
421 <literallayout class='monospaced'> 454 <literallayout class='monospaced'>
422python do_printdate () { 455 def some_python_function(arg1, arg2):
423 import time 456 print arg1 + " " + arg2
424 print time.strftime('%Y%m%d', time.gmtime())
425}
426 </literallayout> 457 </literallayout>
427 This is the similar to the previous, but flags it as Python so that BitBake knows it is Python code. 458 The difference is that the second form takes parameters,
459 the datastore is not available automatically
460 and must be passed as a parameter and these functions are
461 not called with the <filename>exec_func()</filename> but are
462 executed with direct Python function calls.
463 The "bb" and "os" modules are still automatically available
464 and there is no need to import them.
428 </para> 465 </para>
429 </section> 466 </section>
430 467