[yocto] Using anonymous python function to define variables
Paul Eggleton
paul.eggleton at linux.intel.com
Mon Dec 8 01:41:14 PST 2014
Hi Ulf,
On Sunday 07 December 2014 12:22:06 Ulf Winberg wrote:
> I'm struggling with trying to dynamically set a file name, to be used with
> "require". See code below:
>
> python () {
> TA = d.getVar('TARGET_ARCH', True)
> if TA == "arm":
> javaPkg = "oracle-jse-ejre-arm-vfp-hflt-client-headless"
> elif TA == "i586":
> javaPkg = "oracle-jse-jre-i586"
> elif TA == "x86_64":
> javaPkg = "oracle-jse-jre-x86-64"
> else:
> raise Exception("Target architecture '%s' is not supported
> by the meta-oracle-java layer" %TA)
> d.setVar('JAVA_PKG', javaPkg)
> }
>
> require ${JAVA_PKG}.inc
>
> The python function executes properly (if I print javaPkg, it shows up
> correctly) but the "JAVA_PKG" variable does not become available for
> "require". From what I can read in section 3.4.4 in this link
> <http://www.yoctoproject.org/docs/1.6/bitbake-user-manual/bitbake-user-manua
> l.html>, it seems to me it should work. Could someone please explain to me
> why it doesn't?
I'm pretty sure this is because anonymous functions don't get executed until
finalize() is called, which is towards the end of parsing; the "require"
statement must be handled immediately. Try this instead:
---------------- snip ----------------
def get_java_package(d):
TA = d.getVar('TARGET_ARCH', True)
if TA == "arm":
javaPkg = "oracle-jse-ejre-arm-vfp-hflt-client-headless"
elif TA == "i586":
javaPkg = "oracle-jse-jre-i586"
elif TA == "x86_64":
javaPkg = "oracle-jse-jre-x86-64"
else:
raise bb.parse.SkipPackage("Target architecture '%s' is not supported
by the meta-oracle-java layer" % TA)
return javaPkg
JAVA_PKG = "${@get_java_package(d)}"
require ${JAVA_PKG}.inc
---------------- snip ----------------
The question is though, do you really need a separate inc file for each
architecture? You can use overrides for this sort of thing e.g.:
---------------- snip ----------------
SOMEVAR = "default value"
SOMEVAR_arm = "value if arm"
SOMEVAR_x86-64 = "value if x86-64"
---------------- snip ----------------
Cheers,
Paul
--
Paul Eggleton
Intel Open Source Technology Centre
More information about the yocto
mailing list