Skip to contentSkip to conversation

Store a data object containing the initial environment

PATCH In review Joshua Lock 2 participants 3 messages Jul 22, 2011

lore
Share & tools
lore
#0 lore raw

cover Store a data object containing the initial environment

As discussed, take a copy of the environment in the bitbake entry point and pass it to the cooker for saving in a data store.

Tested with bitbake and bitbake-layers.

The following changes since commit abc67ed6921c98ed581f101ec1acc589fd9ce7e9:

bitbake/utils: Add contains helper function from lib.oe.utils (2011-07-22 12:11:01 +0100)

are available in the git repository at:
git://github.com/incandescant/bitbake initialenv
https://github.com/incandescant/bitbake/tree/initialenv

Joshua Lock (1):
bitbake|cooker: save a copy of the environment when BitBake is
started

 bin/bitbake      |    5 ++++-
 lib/bb/cooker.py |   11 ++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.6
#1 lore raw

PATCH 1/1 bitbake|cooker: save a copy of the environment when BitBake is started

Create a data store in the cooker containing the values of the environment from when BitBake is launched such that child processes can replicate (and/or use values from) the host environment, rather than the cleaned up environment that the main BitBake process uses.

---
 bin/bitbake      |    5 ++++-
 lib/bb/cooker.py |   11 ++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
bin/bitbake +4 -1
index 206d97b..a9dd67e 100755
@@ -197,6 +197,9 @@ Default BBFILES are the .bb files in the current directory.""")
     handler = bb.event.LogHandler()
     logger.addHandler(handler)
 
+    # Before we start modifying the environment we should take a pristine
+    # copy for possible later use
+    initialenv = os.environ.copy()
     # Clear away any spurious environment variables. But don't wipe the
     # environment totally. This is necessary to ensure the correct operation
     # of the UIs (e.g. for DISPLAY, etc.)
@@ -207,7 +210,7 @@ Default BBFILES are the .bb files in the current directory.""")
     server.initServer()
     idle = server.getServerIdleCB()
 
-    cooker = bb.cooker.BBCooker(configuration, idle)
+    cooker = bb.cooker.BBCooker(configuration, idle, initialenv)
     cooker.parseCommandLine()
 
     server.addcooker(cooker)
lib/bb/cooker.py +10 -1
index 0326b8c..079b6d3 100644
@@ -78,7 +78,7 @@ class BBCooker:
     Manages one bitbake build run
     """
 
-    def __init__(self, configuration, server_registration_cb):
+    def __init__(self, configuration, server_registration_cb, savedenv=None):
         self.status = None
         self.appendlist = {}
         self.skiplist = {}
@@ -87,6 +87,15 @@ class BBCooker:
 
         self.configuration = configuration
 
+        # Keep a datastore of the initial environment variables and their
+        # values from when BitBake was launched to enable child processes
+        # to use environment variables which have been cleaned from the
+        # BitBake processes env
+        if savedenv:
+            self.savedenv = bb.data.init()
+            for k in savedenv:
+                self.savedenv.setVar(k, savedenv[k])
+
         self.caches_array = []
         # Currently, only Image Creator hob ui needs extra cache.
         # So, we save Extra Cache class name and container file
Signature · 1 line
1.7.6
#2 lore raw

Re: [PATCH 1/1] bitbake|cooker: save a copy of the environment when BitBake is started

Quoted 39 lines · Joshua Lock

Create a data store in the cooker containing the values of the environment from when BitBake is launched such that child processes can replicate (and/or use values from) the host environment, rather than the cleaned up environment that the main BitBake process uses.

---
 bin/bitbake      |    5 ++++-
 lib/bb/cooker.py |   11 ++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
bin/bitbake +4 -1
index 206d97b..a9dd67e 100755
@@ -197,6 +197,9 @@ Default BBFILES are the .bb files in the current directory.""")
     handler = bb.event.LogHandler()
     logger.addHandler(handler)
 
+    # Before we start modifying the environment we should take a pristine
+    # copy for possible later use
+    initialenv = os.environ.copy()
     # Clear away any spurious environment variables. But don't wipe the
     # environment totally. This is necessary to ensure the correct operation
     # of the UIs (e.g. for DISPLAY, etc.)
@@ -207,7 +210,7 @@ Default BBFILES are the .bb files in the current directory.""")
     server.initServer()
     idle = server.getServerIdleCB()
 
-    cooker = bb.cooker.BBCooker(configuration, idle)
+    cooker = bb.cooker.BBCooker(configuration, idle, initialenv)
     cooker.parseCommandLine()
 
     server.addcooker(cooker)
lib/bb/cooker.py +0 -0
index 0326b8c..079b6d3 100644

lib/bb/cooker.py class BBCooker: · line 81

Quoted 5 lines
lib/bb/cooker.py +1 -1
@@ -78,7 +78,7 @@ class BBCooker:
     Manages one bitbake build run
     """
 
-    def __init__(self, configuration, server_registration_cb):
+    def __init__(self, configuration, server_registration_cb, savedenv=None):

def __init__(self, configuration, server_registration_cb, savedenv={}):

Quoted 6 lines
lib/bb/cooker.py +0 -0
         self.status = None
         self.appendlist = {}
         self.skiplist = {}
@@ -87,6 +87,15 @@ class BBCooker:
 
         self.configuration = configuration

lib/bb/cooker.py class BBCooker: · line 98

Quoted 10 lines
lib/bb/cooker.py +9 -0
 
+        # Keep a datastore of the initial environment variables and their
+        # values from when BitBake was launched to enable child processes
+        # to use environment variables which have been cleaned from the
+        # BitBake processes env
+        if savedenv:
+            self.savedenv = bb.data.init()
+            for k in savedenv:
+                self.savedenv.setVar(k, savedenv[k])
+

Then you can drop the if and we'd just create an empty dictionary which is likely going to lead to saner code in future...

Cheers,

Richard