]> code.ossystems Code Review - openembedded-core.git/commitdiff
bitbake-dev: Refactor the environment variable handling.
authorRobert Bradford <rob@openedhand.com>
Fri, 17 Oct 2008 09:46:23 +0000 (09:46 +0000)
committerRobert Bradford <rob@openedhand.com>
Fri, 17 Oct 2008 09:46:23 +0000 (09:46 +0000)
Do not clear the environment when saving the environment to the data store.
Instead clear this once the cooker has forked. This ensures that the UI
operates in a filtered (but not empty) environment.

git-svn-id: https://svn.o-hand.com/repos/poky/trunk@5526 311d38ba-8fff-0310-9ca6-ca027cbcb966

bitbake-dev/bin/bitbake
bitbake-dev/lib/bb/cooker.py
bitbake-dev/lib/bb/data.py
bitbake-dev/lib/bb/utils.py

index 247b54fcd3d98ab3da70d8d18b25342d3bfd2948..87284c08feb4ed49f9827e6f7283fec9d6702879 100755 (executable)
@@ -141,15 +141,10 @@ Default BBFILES are the .bb files in the current directory.""" )
 
     cooker = bb.cooker.BBCooker(configuration)
 
-    # Optionally clean up the environment
-    if 'BB_PRESERVE_ENV' not in os.environ:
-        if 'BB_ENV_WHITELIST' in os.environ:
-            good_vars = os.environ['BB_ENV_WHITELIST'].split()
-        else:
-            good_vars = bb.utils.preserved_envvars_list()
-        if 'BB_ENV_EXTRAWHITE' in os.environ:
-            good_vars.extend(os.environ['BB_ENV_EXTRAWHITE'].split())
-        bb.utils.filter_environment(good_vars)
+    # 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.)
+    bb.utils.clean_environment()
 
     cooker.parseConfiguration()
     host = cooker.server.host
index 8feb228faf8dc37ebac3da252109402058ee971b..6d04d380806f197d58df5d2e7d405aa69b7fb3df 100644 (file)
@@ -907,6 +907,10 @@ class BBCooker:
 
     def serve(self):
 
+        # Empty the environment. The environment will be populated as
+        # necessary from the data store.
+        bb.utils.empty_environment()
+
         if self.configuration.profile:
             try:
                 import cProfile as profile
index 82eef44989c6023314a7b228a925953384482ee0..19e67dbc37bea7e94780f6e4b7316e3e74e21351 100644 (file)
@@ -331,8 +331,6 @@ def inheritFromOS(d):
             setVar(s, os.environ[s], d)
         except TypeError:
             pass
-        os.unsetenv(s)
-        del os.environ[s]
 
 def emit_var(var, o=sys.__stdout__, d = init(), all=False):
     """Emit a variable to be sourced by a shell."""
index 119f08582d46341ec2bbce21c00d01b69778a34f..94bc62f7cf77e58f0a44b2bed9f7ccdab0b7e192 100644 (file)
@@ -354,6 +354,28 @@ def filter_environment(good_vars):
 
     return removed_vars
 
+def clean_environment():
+    """
+    Clean up any spurious environment variables. This will remove any
+    variables the user hasn't chose to preserve.
+    """
+    if 'BB_PRESERVE_ENV' not in os.environ:
+        if 'BB_ENV_WHITELIST' in os.environ:
+            good_vars = os.environ['BB_ENV_WHITELIST'].split()
+        else:
+            good_vars = preserved_envvars_list()
+        if 'BB_ENV_EXTRAWHITE' in os.environ:
+            good_vars.extend(os.environ['BB_ENV_EXTRAWHITE'].split())
+        filter_environment(good_vars)
+
+def empty_environment():
+    """
+    Remove all variable from the environment.
+    """
+    for s in os.environ.keys():
+        os.unsetenv(s)
+        del os.environ[s]
+
 def prunedir(topdir):
     # Delete everything reachable from the directory named in 'topdir'.
     # CAUTION:  This is dangerous!