Skip to contentSkip to conversation

runqueue: Ensure task environment is correct

PATCH Richard Purdie 2 participants 5 messages Sep 7, 2011

lore
Share & tools
lore
#0 lore raw

This fixes two problems:

a) Variables which were in the parent environment but not set as "export" variables in the datastore could end up in the task environment

b) oe.environ.update() can't cope with the generator returned by bb.data.exported_vars()

Whilst the updated code isn't as neat, it does do the expected thing, sets the environment correctly and stops unwanted values leaking into the task environment.

bitbake/lib/bb/runqueue.py +6 -1
index 5a4321f..72e6845 100644
@@ -1136,7 +1136,12 @@ class RunQueueExecute:
                 for h in self.rqdata.hash_deps:
                     the_data.setVar("BBHASHDEPS_%s" % h, self.rqdata.hash_deps[h])
 
-                os.environ.update(bb.data.exported_vars(the_data))
+                # exported_vars() returns a generator which *cannot* be passed to os.environ.update() 
+                # successfully. We also need to unset anything from the environment which shouldn't be there 
+                exports = bb.data.exported_vars(the_data)
+                bb.utils.empty_environment()
+                for e, v in exports:
+                    os.environ[e] = v
 
                 if quieterrors:
                     the_data.setVarFlag(taskname, "quieterrors", "1")
#1 lore raw
Quoted 22 lines · Richard Purdie

This fixes two problems:

a) Variables which were in the parent environment but not set as "export" variables in the datastore could end up in the task environment

b) oe.environ.update() can't cope with the generator returned by bb.data.exported_vars()

Whilst the updated code isn't as neat, it does do the expected thing, sets the environment correctly and stops unwanted values leaking into the task environment.

bitbake/lib/bb/runqueue.py +0 -0
index 5a4321f..72e6845 100644
@@ -1136,7 +1136,12 @@ class RunQueueExecute:

                for h in self.rqdata.hash_deps:
                    the_data.setVar("BBHASHDEPS_%s" % h, self.rqdata.hash_deps[h])

Quoted 7 lines

-                os.environ.update(bb.data.exported_vars(the_data))
+                # exported_vars() returns a generator which *cannot* be passed to os.environ.update()
+                # successfully. We also need to unset anything from the environment which shouldn't be there
+                exports = bb.data.exported_vars(the_data)
+                bb.utils.empty_environment()
+                for e, v in exports:
+                    os.environ[e] = v

os.environ.clear() os.environ.update(bb.data.exported_vars(the_data))

Signature · 5 lines
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
#2 lore raw
Quoted 24 lines · Chris Larson
Quoted 22 lines · Richard Purdie

This fixes two problems:

a) Variables which were in the parent environment but not set as "export" variables in the datastore could end up in the task environment

b) oe.environ.update() can't cope with the generator returned by bb.data.exported_vars()

Whilst the updated code isn't as neat, it does do the expected thing, sets the environment correctly and stops unwanted values leaking into the task environment.

bitbake/lib/bb/runqueue.py +0 -0
index 5a4321f..72e6845 100644
@@ -1136,7 +1136,12 @@ class RunQueueExecute:
                for h in self.rqdata.hash_deps:
                    the_data.setVar("BBHASHDEPS_%s" % h, self.rqdata.hash_deps[h])
 
Quoted 10 lines

bitbake/lib/bb/runqueue.py class RunQueueExecute: · line 1144

Quoted 7 lines
bitbake/lib/bb/runqueue.py +6 -1
-                os.environ.update(bb.data.exported_vars(the_data))
+                # exported_vars() returns a generator which *cannot* be passed to os.environ.update()
+                # successfully. We also need to unset anything from the environment which shouldn't be there
+                exports = bb.data.exported_vars(the_data)
+                bb.utils.empty_environment()
+                for e, v in exports:
+                    os.environ[e] = v

os.environ.clear() os.environ.update(bb.data.exported_vars(the_data))

I tried this when testing and when I read os.environ back, it was not correct. There is something odd occurring if you pass the generator into update() directly.

Cheers,

Richard

#3 lore raw
Quoted 36 lines · Richard Purdie
Quoted 24 lines · Chris Larson
Quoted 22 lines · Richard Purdie

This fixes two problems:

a) Variables which were in the parent environment but not set as "export" variables in the datastore could end up in the task environment

b) oe.environ.update() can't cope with the generator returned by bb.data.exported_vars()

Whilst the updated code isn't as neat, it does do the expected thing, sets the environment correctly and stops unwanted values leaking into the task environment.

bitbake/lib/bb/runqueue.py +0 -0
index 5a4321f..72e6845 100644
@@ -1136,7 +1136,12 @@ class RunQueueExecute:

                for h in self.rqdata.hash_deps:
                    the_data.setVar("BBHASHDEPS_%s" % h, self.rqdata.hash_deps[h])

Quoted 10 lines
Quoted 7 lines

-                os.environ.update(bb.data.exported_vars(the_data))
+                # exported_vars() returns a generator which *cannot* be passed to os.environ.update()
+                # successfully. We also need to unset anything from the environment which shouldn't be there
+                exports = bb.data.exported_vars(the_data)
+                bb.utils.empty_environment()
+                for e, v in exports:
+                    os.environ[e] = v

os.environ.clear() os.environ.update(bb.data.exported_vars(the_data))

Quoted 3 lines

I tried this when testing and when I read os.environ back, it was not correct. There is something odd occurring if you pass the generator into update() directly.

Odd. It works fine in my local testing. Maybe there's a python bug lurking -- I can't imagine it's supposed to work this way. Guess we have to do it this way, but I really think you should consider isolating the problem and reporting it upstream to the python project.

Signature · 5 lines
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
#4 lore raw
Quoted 38 lines · Chris Larson
Quoted 36 lines · Richard Purdie
Quoted 34 lines · Chris Larson
Quoted 19 lines · Richard Purdie

This fixes two problems:

a) Variables which were in the parent environment but not set as "export" variables in the datastore could end up in the task environment

b) oe.environ.update() can't cope with the generator returned by bb.data.exported_vars()

Whilst the updated code isn't as neat, it does do the expected thing, sets the environment correctly and stops unwanted values leaking into the task environment.

bitbake/lib/bb/runqueue.py +0 -0
index 5a4321f..72e6845 100644

bitbake/lib/bb/runqueue.py class RunQueueExecute: · line 1144

Quoted 10 lines
bitbake/lib/bb/runqueue.py +6 -1
@@ -1136,7 +1136,12 @@ class RunQueueExecute:
                for h in self.rqdata.hash_deps:
                    the_data.setVar("BBHASHDEPS_%s" % h, self.rqdata.hash_deps[h])
 
-                os.environ.update(bb.data.exported_vars(the_data))
+                # exported_vars() returns a generator which *cannot* be passed to os.environ.update()
+                # successfully. We also need to unset anything from the environment which shouldn't be there
+                exports = bb.data.exported_vars(the_data)
+                bb.utils.empty_environment()
+                for e, v in exports:
+                    os.environ[e] = v

os.environ.clear() os.environ.update(bb.data.exported_vars(the_data))

Quoted 8 lines
Quoted 3 lines

I tried this when testing and when I read os.environ back, it was not correct. There is something odd occurring if you pass the generator into update() directly.

Odd. It works fine in my local testing. Maybe there's a python bug lurking -- I can't imagine it's supposed to work this way. Guess we have to do it this way, but I really think you should consider isolating the problem and reporting it upstream to the python project.

Agreed, it does seem to be something about my machine/python version since this is not the first time I've had issues with os.environ :(.

Which version did you test with? I was seeing this with Ubuntu's python "2.7.1+" whatever that is. I did try and write a small test case and that works which is odd/worrying/annoying...

Cheers,

Richard