All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* Not able to set env var from anon function
@ 2015-07-09 12:12 Nithyakala Sainath
  2015-07-09 13:40 ` Burton, Ross
  2015-07-10  8:08 ` Richard Purdie
  0 siblings, 2 replies; 5+ messages in thread
From: Nithyakala Sainath @ 2015-07-09 12:12 UTC (permalink / raw
  To: poky

[-- Attachment #1: Type: text/plain, Size: 660 bytes --]

Hello all,

I was playing with environmental variables and datastore that I fell into
this situation:

In a reccipe a.bb

export TEMPDIR = "temp"

python() {
        os.environ["TEMPDIR"] = "randomvalue"
}

do_compile() {
        echo ${TEMPDIR }
}

gives me "temp" as the answer. I was expecting "randomvalue". Can I not
modify the environmental variables and create new ones in anon functions ?

But d.setVar("TEMPDIR", "randomvalue") in place of os.environ does the
mgic. Why can't we manipulate the environmental variable using os.environ ?

In bitbake.conf, we see that we can get env vars using os.getenv.

Thanks,
Nithyakala.

[-- Attachment #2: Type: text/html, Size: 1032 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Not able to set env var from anon function
  2015-07-09 12:12 Not able to set env var from anon function Nithyakala Sainath
@ 2015-07-09 13:40 ` Burton, Ross
  2015-07-10  5:21   ` Nithyakala Sainath
  2015-07-10  8:08 ` Richard Purdie
  1 sibling, 1 reply; 5+ messages in thread
From: Burton, Ross @ 2015-07-09 13:40 UTC (permalink / raw
  To: Nithyakala Sainath; +Cc: Poky Project

[-- Attachment #1: Type: text/plain, Size: 338 bytes --]

On 9 July 2015 at 13:12, Nithyakala Sainath <nithisai@gmail.com> wrote:

> But d.setVar("TEMPDIR", "randomvalue") in place of os.environ does the
> mgic. Why can't we manipulate the environmental variable using os.environ ?


Because in "echo ${TEMPDIR}" the variable is expanded by bitbake, not the
shell.  Use $TEMPDIR.

Ross

[-- Attachment #2: Type: text/html, Size: 714 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Not able to set env var from anon function
  2015-07-09 13:40 ` Burton, Ross
@ 2015-07-10  5:21   ` Nithyakala Sainath
  0 siblings, 0 replies; 5+ messages in thread
From: Nithyakala Sainath @ 2015-07-10  5:21 UTC (permalink / raw
  To: Burton, Ross; +Cc: Poky Project

[-- Attachment #1: Type: text/plain, Size: 609 bytes --]

Thanks for your answer Ross.

But no, I already did that and tried again. The "randomvalue" is not
getting reflected. The variable still has "temp" in it.

Nithya.

On Thu, Jul 9, 2015 at 7:10 PM, Burton, Ross <ross.burton@intel.com> wrote:

>
> On 9 July 2015 at 13:12, Nithyakala Sainath <nithisai@gmail.com> wrote:
>
>> But d.setVar("TEMPDIR", "randomvalue") in place of os.environ does the
>> mgic. Why can't we manipulate the environmental variable using os.environ ?
>
>
> Because in "echo ${TEMPDIR}" the variable is expanded by bitbake, not the
> shell.  Use $TEMPDIR.
>
> Ross
>

[-- Attachment #2: Type: text/html, Size: 1390 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Not able to set env var from anon function
  2015-07-09 12:12 Not able to set env var from anon function Nithyakala Sainath
  2015-07-09 13:40 ` Burton, Ross
@ 2015-07-10  8:08 ` Richard Purdie
  2015-07-10 11:33   ` Nithyakala Sainath
  1 sibling, 1 reply; 5+ messages in thread
From: Richard Purdie @ 2015-07-10  8:08 UTC (permalink / raw
  To: Nithyakala Sainath; +Cc: poky

On Thu, 2015-07-09 at 17:42 +0530, Nithyakala Sainath wrote:
> I was playing with environmental variables and datastore that I fell
> into this situation:
>
> In a reccipe a.bb
>
> export TEMPDIR = "temp"
>
> python() {
>         os.environ["TEMPDIR"] = "randomvalue"
> }
>
> do_compile() {
>         echo ${TEMPDIR } 
> }
>
> gives me "temp" as the answer. I was expecting "randomvalue". Can I
> not modify the environmental variables and create new ones in anon
> functions ?
>
> But d.setVar("TEMPDIR", "randomvalue") in place of os.environ does the
> mgic. Why can't we manipulate the environmental variable using
> os.environ ?
>
> In bitbake.conf, we see that we can get env vars using os.getenv.

bitbake tightly controls the task execution environment. Only variables
marked as "export" will be exported and the value used for them is that
from the datastore. Therefore, os.environ set in anonymous python will
simply get overwritten. You can't have one value in the datastore and
another in the environment.

As Ross points out, ${TEMPDIR} will get expanded by bitbake anyway so it
would print the datastore value anyway.

Cheers,

Richard




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Not able to set env var from anon function
  2015-07-10  8:08 ` Richard Purdie
@ 2015-07-10 11:33   ` Nithyakala Sainath
  0 siblings, 0 replies; 5+ messages in thread
From: Nithyakala Sainath @ 2015-07-10 11:33 UTC (permalink / raw
  To: Richard Purdie; +Cc: Poky Project

[-- Attachment #1: Type: text/plain, Size: 1429 bytes --]

Thanks Richard and Ross. That answers my question.

Nithya.

On Fri, Jul 10, 2015 at 1:38 PM, Richard Purdie <
richard.purdie@linuxfoundation.org> wrote:

> On Thu, 2015-07-09 at 17:42 +0530, Nithyakala Sainath wrote:
> > I was playing with environmental variables and datastore that I fell
> > into this situation:
> >
> > In a reccipe a.bb
> >
> > export TEMPDIR = "temp"
> >
> > python() {
> >         os.environ["TEMPDIR"] = "randomvalue"
> > }
> >
> > do_compile() {
> >         echo ${TEMPDIR }
> > }
> >
> > gives me "temp" as the answer. I was expecting "randomvalue". Can I
> > not modify the environmental variables and create new ones in anon
> > functions ?
> >
> > But d.setVar("TEMPDIR", "randomvalue") in place of os.environ does the
> > mgic. Why can't we manipulate the environmental variable using
> > os.environ ?
> >
> > In bitbake.conf, we see that we can get env vars using os.getenv.
>
> bitbake tightly controls the task execution environment. Only variables
> marked as "export" will be exported and the value used for them is that
> from the datastore. Therefore, os.environ set in anonymous python will
> simply get overwritten. You can't have one value in the datastore and
> another in the environment.
>
> As Ross points out, ${TEMPDIR} will get expanded by bitbake anyway so it
> would print the datastore value anyway.
>
> Cheers,
>
> Richard
>
>
>

[-- Attachment #2: Type: text/html, Size: 2114 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-07-10 11:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-09 12:12 Not able to set env var from anon function Nithyakala Sainath
2015-07-09 13:40 ` Burton, Ross
2015-07-10  5:21   ` Nithyakala Sainath
2015-07-10  8:08 ` Richard Purdie
2015-07-10 11:33   ` Nithyakala Sainath

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.