diff options
| author | Scott Rifenbark <scott.m.rifenbark@intel.com> | 2014-04-14 09:34:39 -0700 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-04-21 23:03:19 +0100 |
| commit | ea4e822b8d6d67a7264e9f7b2930606e23d36a73 (patch) | |
| tree | 138f3f81a40a170c008782c72b1d9d4c73d45075 | |
| parent | 9889a91a5b84175b91fec05b7a40234f72ac09b2 (diff) | |
| download | poky-ea4e822b8d6d67a7264e9f7b2930606e23d36a73.tar.gz | |
bitbake: bitbake-user-manual-metadata.xml: New section on anonymous Python functions
Per Paul Eggleton's suggestion, I added a new section on
anonymous Python functions into the "Functions" section.
I also updated the intro text to account for the added
type of functions.
(Bitbake rev: 983d03c1a082e2b83187f0788e61a7941670b242)
Signed-off-by: Scott Rifenbark <scott.m.rifenbark@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml index 365c4b8f97..5304e40ce7 100644 --- a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml +++ b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml | |||
| @@ -683,7 +683,7 @@ | |||
| 683 | <para> | 683 | <para> |
| 684 | As with most languages, functions are the building blocks that | 684 | As with most languages, functions are the building blocks that |
| 685 | are used to build up operations into tasks. | 685 | are used to build up operations into tasks. |
| 686 | BitBake supports three types of functions: | 686 | BitBake supports these types of functions: |
| 687 | <itemizedlist> | 687 | <itemizedlist> |
| 688 | <listitem><para><emphasis>Shell Functions:</emphasis> | 688 | <listitem><para><emphasis>Shell Functions:</emphasis> |
| 689 | Functions written in shell script and executed either | 689 | Functions written in shell script and executed either |
| @@ -697,6 +697,10 @@ | |||
| 697 | <listitem><para><emphasis>Python Functions:</emphasis> | 697 | <listitem><para><emphasis>Python Functions:</emphasis> |
| 698 | Functions written in Python and executed by Python. | 698 | Functions written in Python and executed by Python. |
| 699 | </para></listitem> | 699 | </para></listitem> |
| 700 | <listitem><para><emphasis>Anonymous Python Functions:</emphasis> | ||
| 701 | Python functions executed automatically during | ||
| 702 | parsing. | ||
| 703 | </para></listitem> | ||
| 700 | </itemizedlist> | 704 | </itemizedlist> |
| 701 | Regardless of the type of function, you can only | 705 | Regardless of the type of function, you can only |
| 702 | define them in class (<filename>.bbclass</filename>) | 706 | define them in class (<filename>.bbclass</filename>) |
| @@ -793,6 +797,39 @@ | |||
| 793 | </para> | 797 | </para> |
| 794 | </section> | 798 | </section> |
| 795 | 799 | ||
| 800 | <section id='anonymous-python-functions'> | ||
| 801 | <title>Anonymous Python Functions</title> | ||
| 802 | |||
| 803 | <para> | ||
| 804 | Sometimes it is useful to run some code during | ||
| 805 | parsing to set variables or to perform other operations | ||
| 806 | programmatically. | ||
| 807 | To do this, you can define an anonymous Python function. | ||
| 808 | Here is an example that conditionally sets a | ||
| 809 | variable based on the value of another variable: | ||
| 810 | <literallayout class='monospaced'> | ||
| 811 | python __anonymous () { | ||
| 812 | if d.getVar('SOMEVAR', True) == 'value': | ||
| 813 | d.setVar('ANOTHERVAR', 'value2') | ||
| 814 | } | ||
| 815 | </literallayout> | ||
| 816 | The "__anonymous" function name is optional, so the | ||
| 817 | following example is functionally equivalent to the above: | ||
| 818 | <literallayout class='monospaced'> | ||
| 819 | python () { | ||
| 820 | if d.getVar('SOMEVAR', True) == 'value': | ||
| 821 | d.setVar('ANOTHERVAR', 'value2') | ||
| 822 | } | ||
| 823 | </literallayout> | ||
| 824 | Because unlike other Python functions anonymous | ||
| 825 | Python functions are executed during parsing, the | ||
| 826 | "d" variable within an anonymous Python function represents | ||
| 827 | the datastore for the entire recipe. | ||
| 828 | Consequently, you can set variable values here and | ||
| 829 | those values can be picked up by other functions. | ||
| 830 | </para> | ||
| 831 | </section> | ||
| 832 | |||
| 796 | <section id='flexible-inheritance-for-class-functions'> | 833 | <section id='flexible-inheritance-for-class-functions'> |
| 797 | <title>Flexible Inheritance for Class Functions</title> | 834 | <title>Flexible Inheritance for Class Functions</title> |
| 798 | 835 | ||
| @@ -817,6 +854,9 @@ | |||
| 817 | respectively, or it can redefine the function completely. | 854 | respectively, or it can redefine the function completely. |
| 818 | However, if it redefines the function, there is | 855 | However, if it redefines the function, there is |
| 819 | no means for it to call the class version of the function. | 856 | no means for it to call the class version of the function. |
| 857 | <filename>EXPORT_FUNCTIONS</filename> provides a mechanism | ||
| 858 | that enables the recipe's version of the function to call | ||
| 859 | the original version of the function. | ||
| 820 | </para> | 860 | </para> |
| 821 | 861 | ||
| 822 | <para> | 862 | <para> |
