On Wed, Jun 20, 2012 at 8:46 AM, Joshua Immanuel <j...@hipro.co.in> wrote:
> Hello,
>
> Considering the following code snippet variants of a recipe which does
> the same job, I would like to clarify certain doubts regarding this.
>
> python __anonymous () {
>        pn_split = d.getVar('PN', True).split('-')
>        ...
> }
>
> python __anonymous () {
>        import bb
>        pn_split = bb.data.getVar('PN', d, True).split('-')
>        ...
> }
>
> In some .bbclass, 'bb' library is used without importing it. I find that
> the 'd' variable is an instance of DataSmart class in the bitbake
> library. Will this 'bb' and 'd' variables be available to all python
> tasks and functions?

'bb' and 'os' are always imported, automatically, by bitbake itself,
and as such are available in all python contexts. 'd' is available in
python tasks and anonymous python functions and in inline python
snippets, but *not* in event handlers. event handlers get their event
passed as 'e'.

> I also find that in global python functions such as 'get_imagecmds'
> defined in image_types.bbclass 'd' is got as a parameter. Can someone
> explain when the 'd' will be initialized? Will the instance of DataSmart
> (i.e the variable 'd') in bbclass differ from that of the recipe which
> inherited that class? In bitbake manual, example of global python
> functions are shown as accepting 'bb' and 'd' variables as its
> parameters. Can someone explain the right way of doing this.

Unlike 'bb' and 'os', 'd' is not available in def'd python functions,
only in tasks and anonymous functions and in inline python snippets.
As such, it needs to be passed in by the caller.

E.g.

def foo(d):
    # do something with d

FOO = "${@foo(d)}"
-- 
Christopher Larson
_______________________________________________
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto

Reply via email to