[yocto] Using anonymous python function to define variables

Ulf Winberg ulfwin at gmail.com
Fri Dec 12 07:19:39 PST 2014


Thanks! Using python as a function with return value solved it.

When bb.parse.SkipPackage is used, there seems to be no warning when
building. Does the text I wrote end up in a log somewhere?

I was testing the SOMEVAR example you give. Am I right to assume that the
overrides only works for gobal variables, already defined elsewhere? I was
not able to define one myself and use the overrides.

Cheers,
Ulf

On Mon, Dec 8, 2014 at 10:41 AM, Paul Eggleton <
paul.eggleton at linux.intel.com> wrote:
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.yoctoproject.org/pipermail/yocto/attachments/20141212/c51d9c7e/attachment.html>


More information about the yocto mailing list