summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbitbake-dev/bin/bitbake11
-rw-r--r--bitbake-dev/lib/bb/data.py21
-rw-r--r--bitbake-dev/lib/bb/data_smart.py3
-rw-r--r--bitbake-dev/lib/bb/utils.py54
-rwxr-xr-xbitbake/bin/bitbake10
-rw-r--r--bitbake/lib/bb/data.py21
-rw-r--r--bitbake/lib/bb/data_smart.py3
-rw-r--r--bitbake/lib/bb/utils.py54
8 files changed, 141 insertions, 36 deletions
diff --git a/bitbake-dev/bin/bitbake b/bitbake-dev/bin/bitbake
index c994edb84b..247b54fcd3 100755
--- a/bitbake-dev/bin/bitbake
+++ b/bitbake-dev/bin/bitbake
@@ -140,6 +140,17 @@ Default BBFILES are the .bb files in the current directory.""" )
140 140
141 141
142 cooker = bb.cooker.BBCooker(configuration) 142 cooker = bb.cooker.BBCooker(configuration)
143
144 # Optionally clean up the environment
145 if 'BB_PRESERVE_ENV' not in os.environ:
146 if 'BB_ENV_WHITELIST' in os.environ:
147 good_vars = os.environ['BB_ENV_WHITELIST'].split()
148 else:
149 good_vars = bb.utils.preserved_envvars_list()
150 if 'BB_ENV_EXTRAWHITE' in os.environ:
151 good_vars.extend(os.environ['BB_ENV_EXTRAWHITE'].split())
152 bb.utils.filter_environment(good_vars)
153
143 cooker.parseConfiguration() 154 cooker.parseConfiguration()
144 host = cooker.server.host 155 host = cooker.server.host
145 port = cooker.server.port 156 port = cooker.server.port
diff --git a/bitbake-dev/lib/bb/data.py b/bitbake-dev/lib/bb/data.py
index 54b2615afb..82eef44989 100644
--- a/bitbake-dev/lib/bb/data.py
+++ b/bitbake-dev/lib/bb/data.py
@@ -324,21 +324,15 @@ def expandData(alterdata, readdata = None):
324 if val != expanded: 324 if val != expanded:
325 setVar(key, expanded, alterdata) 325 setVar(key, expanded, alterdata)
326 326
327import os
328
329def inheritFromOS(d): 327def inheritFromOS(d):
330 """Inherit variables from the environment.""" 328 """Inherit variables from the environment."""
331# fakeroot needs to be able to set these
332 non_inherit_vars = [ "LD_LIBRARY_PATH", "LD_PRELOAD" ]
333 for s in os.environ.keys(): 329 for s in os.environ.keys():
334 if not s in non_inherit_vars: 330 try:
335 try: 331 setVar(s, os.environ[s], d)
336 setVar(s, os.environ[s], d) 332 except TypeError:
337 setVarFlag(s, 'matchesenv', '1', d) 333 pass
338 except TypeError: 334 os.unsetenv(s)
339 pass 335 del os.environ[s]
340
341import sys
342 336
343def emit_var(var, o=sys.__stdout__, d = init(), all=False): 337def emit_var(var, o=sys.__stdout__, d = init(), all=False):
344 """Emit a variable to be sourced by a shell.""" 338 """Emit a variable to be sourced by a shell."""
@@ -379,9 +373,6 @@ def emit_var(var, o=sys.__stdout__, d = init(), all=False):
379 o.write('unset %s\n' % varExpanded) 373 o.write('unset %s\n' % varExpanded)
380 return 1 374 return 1
381 375
382 if getVarFlag(var, 'matchesenv', d):
383 return 0
384
385 val.rstrip() 376 val.rstrip()
386 if not val: 377 if not val:
387 return 0 378 return 0
diff --git a/bitbake-dev/lib/bb/data_smart.py b/bitbake-dev/lib/bb/data_smart.py
index b3a51b0edf..0d39d20a45 100644
--- a/bitbake-dev/lib/bb/data_smart.py
+++ b/bitbake-dev/lib/bb/data_smart.py
@@ -149,9 +149,6 @@ class DataSmart:
149 149
150 if not var in self.dict: 150 if not var in self.dict:
151 self._makeShadowCopy(var) 151 self._makeShadowCopy(var)
152 if self.getVarFlag(var, 'matchesenv'):
153 self.delVarFlag(var, 'matchesenv')
154 self.setVarFlag(var, 'export', 1)
155 152
156 # more cookies for the cookie monster 153 # more cookies for the cookie monster
157 if '_' in var: 154 if '_' in var:
diff --git a/bitbake-dev/lib/bb/utils.py b/bitbake-dev/lib/bb/utils.py
index 0a0c9ada34..9c9eb5d328 100644
--- a/bitbake-dev/lib/bb/utils.py
+++ b/bitbake-dev/lib/bb/utils.py
@@ -296,6 +296,60 @@ def sha256_file(filename):
296 s.update(line) 296 s.update(line)
297 return s.hexdigest() 297 return s.hexdigest()
298 298
299def preserved_envvars_list():
300 return [
301 'BBPATH',
302 'BB_PRESERVE_ENV',
303 'BB_ENV_WHITELIST',
304 'BB_ENV_EXTRAWHITE',
305 'COLORTERM',
306 'DBUS_SESSION_BUS_ADDRESS',
307 'DESKTOP_SESSION',
308 'DESKTOP_STARTUP_ID',
309 'DISPLAY',
310 'GNOME_KEYRING_PID',
311 'GNOME_KEYRING_SOCKET',
312 'GPG_AGENT_INFO',
313 'GTK_RC_FILES',
314 'HOME',
315 'LANG',
316 'LOGNAME',
317 'PATH',
318 'PWD',
319 'SESSION_MANAGER',
320 'SHELL',
321 'SSH_AUTH_SOCK',
322 'TERM',
323 'USER',
324 'USERNAME',
325 '_',
326 'XAUTHORITY',
327 'XDG_DATA_DIRS',
328 'XDG_SESSION_COOKIE',
329 ]
330
331def filter_environment(good_vars):
332 """
333 Create a pristine environment for bitbake. This will remove variables that
334 are not known and may influence the build in a negative way.
335 """
336
337 import bb
338
339 removed_vars = []
340 for key in os.environ.keys():
341 if key in good_vars:
342 continue
343
344 removed_vars.append(key)
345 os.unsetenv(key)
346 del os.environ[key]
347
348 if len(removed_vars):
349 bb.debug(1, "Removed the following variables from the environment:", ",".join(removed_vars))
350
351 return removed_vars
352
299def prunedir(topdir): 353def prunedir(topdir):
300 # Delete everything reachable from the directory named in 'topdir'. 354 # Delete everything reachable from the directory named in 'topdir'.
301 # CAUTION: This is dangerous! 355 # CAUTION: This is dangerous!
diff --git a/bitbake/bin/bitbake b/bitbake/bin/bitbake
index e262d0b9b4..dc35152d57 100755
--- a/bitbake/bin/bitbake
+++ b/bitbake/bin/bitbake
@@ -113,6 +113,16 @@ Default BBFILES are the .bb files in the current directory.""" )
113 113
114 cooker = bb.cooker.BBCooker(configuration) 114 cooker = bb.cooker.BBCooker(configuration)
115 115
116 # Optionally clean up the environment
117 if 'BB_PRESERVE_ENV' not in os.environ:
118 if 'BB_ENV_WHITELIST' in os.environ:
119 good_vars = os.environ['BB_ENV_WHITELIST'].split()
120 else:
121 good_vars = bb.utils.preserved_envvars_list()
122 if 'BB_ENV_EXTRAWHITE' in os.environ:
123 good_vars.extend(os.environ['BB_ENV_EXTRAWHITE'].split())
124 bb.utils.filter_environment(good_vars)
125
116 cooker.parseConfiguration() 126 cooker.parseConfiguration()
117 127
118 if configuration.profile: 128 if configuration.profile:
diff --git a/bitbake/lib/bb/data.py b/bitbake/lib/bb/data.py
index 54b2615afb..82eef44989 100644
--- a/bitbake/lib/bb/data.py
+++ b/bitbake/lib/bb/data.py
@@ -324,21 +324,15 @@ def expandData(alterdata, readdata = None):
324 if val != expanded: 324 if val != expanded:
325 setVar(key, expanded, alterdata) 325 setVar(key, expanded, alterdata)
326 326
327import os
328
329def inheritFromOS(d): 327def inheritFromOS(d):
330 """Inherit variables from the environment.""" 328 """Inherit variables from the environment."""
331# fakeroot needs to be able to set these
332 non_inherit_vars = [ "LD_LIBRARY_PATH", "LD_PRELOAD" ]
333 for s in os.environ.keys(): 329 for s in os.environ.keys():
334 if not s in non_inherit_vars: 330 try:
335 try: 331 setVar(s, os.environ[s], d)
336 setVar(s, os.environ[s], d) 332 except TypeError:
337 setVarFlag(s, 'matchesenv', '1', d) 333 pass
338 except TypeError: 334 os.unsetenv(s)
339 pass 335 del os.environ[s]
340
341import sys
342 336
343def emit_var(var, o=sys.__stdout__, d = init(), all=False): 337def emit_var(var, o=sys.__stdout__, d = init(), all=False):
344 """Emit a variable to be sourced by a shell.""" 338 """Emit a variable to be sourced by a shell."""
@@ -379,9 +373,6 @@ def emit_var(var, o=sys.__stdout__, d = init(), all=False):
379 o.write('unset %s\n' % varExpanded) 373 o.write('unset %s\n' % varExpanded)
380 return 1 374 return 1
381 375
382 if getVarFlag(var, 'matchesenv', d):
383 return 0
384
385 val.rstrip() 376 val.rstrip()
386 if not val: 377 if not val:
387 return 0 378 return 0
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py
index b3a51b0edf..0d39d20a45 100644
--- a/bitbake/lib/bb/data_smart.py
+++ b/bitbake/lib/bb/data_smart.py
@@ -149,9 +149,6 @@ class DataSmart:
149 149
150 if not var in self.dict: 150 if not var in self.dict:
151 self._makeShadowCopy(var) 151 self._makeShadowCopy(var)
152 if self.getVarFlag(var, 'matchesenv'):
153 self.delVarFlag(var, 'matchesenv')
154 self.setVarFlag(var, 'export', 1)
155 152
156 # more cookies for the cookie monster 153 # more cookies for the cookie monster
157 if '_' in var: 154 if '_' in var:
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 9c8d8e8435..3c1fd31b03 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -296,6 +296,60 @@ def sha256_file(filename):
296 s.update(line) 296 s.update(line)
297 return s.hexdigest() 297 return s.hexdigest()
298 298
299def preserved_envvars_list():
300 return [
301 'BBPATH',
302 'BB_PRESERVE_ENV',
303 'BB_ENV_WHITELIST',
304 'BB_ENV_EXTRAWHITE',
305 'COLORTERM',
306 'DBUS_SESSION_BUS_ADDRESS',
307 'DESKTOP_SESSION',
308 'DESKTOP_STARTUP_ID',
309 'DISPLAY',
310 'GNOME_KEYRING_PID',
311 'GNOME_KEYRING_SOCKET',
312 'GPG_AGENT_INFO',
313 'GTK_RC_FILES',
314 'HOME',
315 'LANG',
316 'LOGNAME',
317 'PATH',
318 'PWD',
319 'SESSION_MANAGER',
320 'SHELL',
321 'SSH_AUTH_SOCK',
322 'TERM',
323 'USER',
324 'USERNAME',
325 '_',
326 'XAUTHORITY',
327 'XDG_DATA_DIRS',
328 'XDG_SESSION_COOKIE',
329 ]
330
331def filter_environment(good_vars):
332 """
333 Create a pristine environment for bitbake. This will remove variables that
334 are not known and may influence the build in a negative way.
335 """
336
337 import bb
338
339 removed_vars = []
340 for key in os.environ.keys():
341 if key in good_vars:
342 continue
343
344 removed_vars.append(key)
345 os.unsetenv(key)
346 del os.environ[key]
347
348 if len(removed_vars):
349 bb.debug(1, "Removed the following variables from the environment:", ",".join(removed_vars))
350
351 return removed_vars
352
299def prunedir(topdir): 353def prunedir(topdir):
300 # Delete everything reachable from the directory named in 'topdir'. 354 # Delete everything reachable from the directory named in 'topdir'.
301 # CAUTION: This is dangerous! 355 # CAUTION: This is dangerous!