aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bb/utils.py
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@linux.intel.com>2008-09-30 21:08:24 +0000
committerRichard Purdie <rpurdie@linux.intel.com>2008-09-30 21:08:24 +0000
commite1737a7506856f0660bf0fcf05517e1337dba1df (patch)
tree13326096e097fa31f6c0e5930d0f61c24e22719f /lib/bb/utils.py
parent35562ac01ad18d3dc5374827e8fb5548a0a3537e (diff)
downloadbitbake-e1737a7506856f0660bf0fcf05517e1337dba1df.tar.gz
bin/bitbake: Add better environmental variable handling. By default it will now only pass certain whitelisted variables into the data store. If BB_PRESERVE_ENV is set bitbake will use all variable from the environment. If BB_ENV_WHITELIST is set, that whitelist will be used instead of the internal bitbake one. Alternatively, BB_ENV_EXTRAWHITE can be used to extend the internal whitelist.
Diffstat (limited to 'lib/bb/utils.py')
-rw-r--r--lib/bb/utils.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 0a0c9ada3..9c9eb5d32 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -296,6 +296,60 @@ def sha256_file(filename):
s.update(line)
return s.hexdigest()
+def preserved_envvars_list():
+ return [
+ 'BBPATH',
+ 'BB_PRESERVE_ENV',
+ 'BB_ENV_WHITELIST',
+ 'BB_ENV_EXTRAWHITE',
+ 'COLORTERM',
+ 'DBUS_SESSION_BUS_ADDRESS',
+ 'DESKTOP_SESSION',
+ 'DESKTOP_STARTUP_ID',
+ 'DISPLAY',
+ 'GNOME_KEYRING_PID',
+ 'GNOME_KEYRING_SOCKET',
+ 'GPG_AGENT_INFO',
+ 'GTK_RC_FILES',
+ 'HOME',
+ 'LANG',
+ 'LOGNAME',
+ 'PATH',
+ 'PWD',
+ 'SESSION_MANAGER',
+ 'SHELL',
+ 'SSH_AUTH_SOCK',
+ 'TERM',
+ 'USER',
+ 'USERNAME',
+ '_',
+ 'XAUTHORITY',
+ 'XDG_DATA_DIRS',
+ 'XDG_SESSION_COOKIE',
+ ]
+
+def filter_environment(good_vars):
+ """
+ Create a pristine environment for bitbake. This will remove variables that
+ are not known and may influence the build in a negative way.
+ """
+
+ import bb
+
+ removed_vars = []
+ for key in os.environ.keys():
+ if key in good_vars:
+ continue
+
+ removed_vars.append(key)
+ os.unsetenv(key)
+ del os.environ[key]
+
+ if len(removed_vars):
+ bb.debug(1, "Removed the following variables from the environment:", ",".join(removed_vars))
+
+ return removed_vars
+
def prunedir(topdir):
# Delete everything reachable from the directory named in 'topdir'.
# CAUTION: This is dangerous!