[poky] Not able to set env var from anon function
Richard Purdie
richard.purdie at linuxfoundation.org
Fri Jul 10 01:08:33 PDT 2015
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
More information about the poky
mailing list