[bitbake-devel] Python tasks and variable scope

Fabrice Coulon fabrice.coulon at axis.com
Mon Oct 28 08:40:03 UTC 2013


Hi,

I am new to BitBake but there is something which I really do not understand as a Python programmer.
And I was hoping somebody could help me with this problem.

I have had to write a recipe for some proprietary package which tries to do the following:

 python do_get_uid_gid() {
    # Read UID and GID from some file not shown here
    d.setVar('UID', '1')
    d.setVar('GID', '2')
    bb.warn("UID = %s" % d.getVar('UID'))
}

addtask get_uid_gid before do_compile after do_configure

python do_print_data() {
    for k in d:
        print "="*20
        print "|%s| -> |%s|" % (k, str(d.getVar(k)))
}

addtask print_data before do_compile after do_get_uid_gid

do_compile_prepend() {
    bbwarn "do_compile_prepend: UID=$UID, GID=$GID"
    bbwarn "d.getVar = "${@d.getVar('UID')}
}

When I look at the output after running bitbake <my-recipe>

WARNING: UID = 1
...

BUT In the "tmp/work/.../temp/log.do_compile",
I can read following:

DEBUG: Executing shell function do_compile
WARNING: do_compile_prepend: UID=, GID=
WARNING: d.getVar = None

I was expecting UID to be 1 and not "None" or "" in do_compile too.

As a Python programmer, if I can set a variable in a data structure called 'd' which is defined
outside of the scope of "do_get_uid_gid" why can't I retrieve the data later on with a getVar()
from another python or shell method?

I think that this is quite counter intuitive. 

I actually had to inspect the d struct in "do_print_data" to discover that UID was not among the keys.

/Fabrice



More information about the bitbake-devel mailing list