Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Richard Purdie <rpurdie <at> rpsys.net>
Subject: Re: [oe] Creating a pristine environment?
Newsgroups: gmane.comp.sysutils.bitbake.devel
Date: Monday 19th May 2008 21:15:30 UTC (over 9 years ago)
Hi,

On Sat, 2008-05-10 at 14:05 +0200, Holger Freyther wrote:
> Okay. I added an option, I clean the environment after having parsed the 
> configuration. This means everything used from conf/local.conf (TOPDIR, 
> BBPATH, BBFILES, MACHINE...) will be inside the configuration data of
bitbake 
> but not be exported. I also updated the documentation (man page and 
> usermanual).

I merged the manual bits of this so they no longer complicate the
equation. 

I've given this patch some thought and I'd like to propose the following
rehashed version of it. It has bitbake look at three different
environmental variables which whilst complicated, does keep everyone
happy:

BB_PRESERVE_ENV - if set don't touch the environment
BB_ENV_WHITELIST - a list of variables to whitelist overriding the default
BB_ENV_EXTRAWHITE - extra variables to whitelist (not touch)

So in Poky I can add MACHINE and POKYMODE to the whitelist by default in
the environment setup script and in my personal case, I can preserve my
environment since I trust myself to do this :).

Any thoughts on this?

Cheers,

Richard

Index: lib/bb/utils.py
===================================================================
--- lib/bb/utils.py	(revision 4503)
+++ lib/bb/utils.py	(working copy)
@@ -268,3 +268,56 @@
     for line in open(filename):
         s.update(line)
     return s.hexdigest()
+
+def preserved_envvars_list():
+    return [
+        "BBPATH",
+        "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
+
+
Index: lib/bb/cooker.py
===================================================================
--- lib/bb/cooker.py	(revision 4504)
+++ lib/bb/cooker.py	(working copy)
@@ -59,6 +59,8 @@
 
         self.configuration.data = bb.data.init()
 
+    def parseConfiguration(self):
+
         for f in self.configuration.file:
             self.parseConfigurationFile( f )
 
Index: bin/bitbake
===================================================================
--- bin/bitbake	(revision 4460)
+++ bin/bitbake	(working copy)
@@ -113,6 +113,19 @@
 
     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())
+            print "here %s" % good_vars
+        bb.utils.filter_environment(good_vars)
+
+    cooker.parseConfiguration()
+
     if configuration.profile:
         try:
             import cProfile as profile
 
CD: 3ms