* Using anonymous python function to define variables
@ 2014-12-07 11:22 Ulf Winberg
2014-12-08 9:41 ` Paul Eggleton
0 siblings, 1 reply; 4+ messages in thread
From: Ulf Winberg @ 2014-12-07 11:22 UTC (permalink / raw)
To: yocto
[-- Attachment #1: Type: text/plain, Size: 1016 bytes --]
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-manual.html>,
it seems to me it should work. Could someone please explain to me why it
doesn't?
Thank you in advance!
Ulf
[-- Attachment #2: Type: text/html, Size: 1388 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Using anonymous python function to define variables
2014-12-07 11:22 Using anonymous python function to define variables Ulf Winberg
@ 2014-12-08 9:41 ` Paul Eggleton
2014-12-12 15:19 ` Ulf Winberg
0 siblings, 1 reply; 4+ messages in thread
From: Paul Eggleton @ 2014-12-08 9:41 UTC (permalink / raw)
To: Ulf Winberg; +Cc: yocto
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Using anonymous python function to define variables
2014-12-08 9:41 ` Paul Eggleton
@ 2014-12-12 15:19 ` Ulf Winberg
2014-12-15 13:28 ` Paul Eggleton
0 siblings, 1 reply; 4+ messages in thread
From: Ulf Winberg @ 2014-12-12 15:19 UTC (permalink / raw)
To: Paul Eggleton; +Cc: yocto
[-- Attachment #1: Type: text/plain, Size: 2959 bytes --]
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@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
>
[-- Attachment #2: Type: text/html, Size: 4106 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Using anonymous python function to define variables
2014-12-12 15:19 ` Ulf Winberg
@ 2014-12-15 13:28 ` Paul Eggleton
0 siblings, 0 replies; 4+ messages in thread
From: Paul Eggleton @ 2014-12-15 13:28 UTC (permalink / raw)
To: Ulf Winberg; +Cc: yocto
On Friday 12 December 2014 16:19:39 Ulf Winberg wrote:
> Thanks! Using python as a function with return value solved it.
Great!
> 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?
SkipPackage (or SkipRecipe which should really now be used instead) just marks
the recipe as skipped - you only see the message when you try to build that
recipe.
> 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.
No, that should work for any variable (and you can see existing examples where
we do that, e.g.
meta/recipes-core/packagegroups/packagegroup-core-tools-profile.bb )
Cheers,
Paul
--
Paul Eggleton
Intel Open Source Technology Centre
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-12-15 13:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-07 11:22 Using anonymous python function to define variables Ulf Winberg
2014-12-08 9:41 ` Paul Eggleton
2014-12-12 15:19 ` Ulf Winberg
2014-12-15 13:28 ` Paul Eggleton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.