bitbake-dev: Refactor the environment variable handling.

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
This commit is contained in:
Robert Bradford
2008-10-17 09:46:23 +00:00
parent 603ae240ff
commit 9294b95174
4 changed files with 30 additions and 11 deletions

View File

@@ -141,15 +141,10 @@ Default BBFILES are the .bb files in the current directory.""" )
cooker = bb.cooker.BBCooker(configuration) cooker = bb.cooker.BBCooker(configuration)
# Optionally clean up the environment # Clear away any spurious environment variables. But don't wipe the
if 'BB_PRESERVE_ENV' not in os.environ: # environment totally. This is necessary to ensure the correct operation
if 'BB_ENV_WHITELIST' in os.environ: # of the UIs (e.g. for DISPLAY, etc.)
good_vars = os.environ['BB_ENV_WHITELIST'].split() bb.utils.clean_environment()
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)
cooker.parseConfiguration() cooker.parseConfiguration()
host = cooker.server.host host = cooker.server.host

View File

@@ -907,6 +907,10 @@ class BBCooker:
def serve(self): 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: if self.configuration.profile:
try: try:
import cProfile as profile import cProfile as profile

View File

@@ -331,8 +331,6 @@ def inheritFromOS(d):
setVar(s, os.environ[s], d) setVar(s, os.environ[s], d)
except TypeError: except TypeError:
pass pass
os.unsetenv(s)
del os.environ[s]
def emit_var(var, o=sys.__stdout__, d = init(), all=False): def emit_var(var, o=sys.__stdout__, d = init(), all=False):
"""Emit a variable to be sourced by a shell.""" """Emit a variable to be sourced by a shell."""

View File

@@ -354,6 +354,28 @@ def filter_environment(good_vars):
return removed_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): def prunedir(topdir):
# Delete everything reachable from the directory named in 'topdir'. # Delete everything reachable from the directory named in 'topdir'.
# CAUTION: This is dangerous! # CAUTION: This is dangerous!