Use python in variable assigment of a recipe
According to the user manual it is possible to use python code in variable assignments by using ${@...}.
I like to use a function (subprocess.check_output) here which requires an import statement. Where do i have to place this import?
And another question. Is it possible to determine the path to the recipe itself from with it?
Thx,
Steffen
Signature · 7 lines
DResearch Fahrzeugelektronik GmbH Otto-Schmirgal-Str. 3, 10319 Berlin, Germany Tel: +49 30 515932-237 mailto:[email protected] Fax: +49 30 515932-299 Geschäftsführer: Dr. Michael Weber, Werner Mögle; Amtsgericht Berlin Charlottenburg; HRB 130120 B; Ust.-IDNr. DE273952058
Quoted 5 lines · On Tuesday 28 February 2012 10:26:16 Steffen Sledz wrote:
According to the user manual it is possible to use python code in variable assignments by using ${@...}.
I like to use a function (subprocess.check_output) here which requires an import statement. Where do i have to place this import?
If you've got more than one line of Python then you should probably define a normal Python function (just use "def" as you would in a normal python script
- there are plenty of examples of this) and then call this using ${@...}.
Quoted 2 lines
And another question. Is it possible to determine the path to the recipe itself from with it?
I think you just need to get the value of the FILE variable e.g
d.getVar('FILE', True)
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
Quoted 10 lines · Paul Eggleton
Quoted 5 lines · On Tuesday 28 February 2012 10:26:16 Steffen Sledz wrote:
According to the user manual it is possible to use python code in variable assignments by using ${@...}.
I like to use a function (subprocess.check_output) here which requires an import statement. Where do i have to place this import?
If you've got more than one line of Python then you should probably define a normal Python function (just use "def" as you would in a normal python script
- there are plenty of examples of this) and then call this using ${@...}.
Works. Thx.
Quoted 6 lines
Quoted 2 lines
And another question. Is it possible to determine the path to the recipe itself from with it?
I think you just need to get the value of the FILE variable e.g
d.getVar('FILE', True)
Because i'm working with oe-classic i tried this (found in some other examples):
MYVAR = "${@my_func()}" def my_func():
bbpath = os.path.dirname(bb.data.getVar('FILE',d,1))
...But this leads to an error:
NameError: global name 'd' is not defined
:(
Signature · 7 lines
DResearch Fahrzeugelektronik GmbH Otto-Schmirgal-Str. 3, 10319 Berlin, Germany Tel: +49 30 515932-237 mailto:[email protected] Fax: +49 30 515932-299 Geschäftsführer: Dr. Michael Weber, Werner Mögle; Amtsgericht Berlin Charlottenburg; HRB 130120 B; Ust.-IDNr. DE273952058
Quoted 5 lines · On Tuesday 28 February 2012 13:11:08 Steffen Sledz wrote:
Because i'm working with oe-classic i tried this (found in some other examples):
MYVAR = "${@my_func()}"
Quoted 7 lines
def
my_func():bbpath = os.path.dirname(bb.data.getVar('FILE',d,1)) ...But this leads to an error:
NameError: global name 'd' is not defined
If you pass in d it should work, i.e.:
MYVAR = "${@my_func(d)}" def my_func(d):
bbpath = os.path.dirname(bb.data.getVar('FILE',d,1))BTW, d.getVar() should work fine in OE-Classic (or to be fully correct, it should work fine with older versions of bitbake).
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
Quoted 5 lines · Steffen Sledz
Because i'm working with oe-classic i tried this (found in some other examples):
MYVAR = "${@my_func()}"def
my_func():
Quoted 8 lines
bbpath = os.path.dirname(bb.data.getVar('FILE',d,1)) ...But this leads to an error:
NameError: global name 'd' is not defined
:(
MYVAR = "${@my_func(d)}"
def my_func(d):
...
p.