All of lore.kernel.org
 help / color / mirror / Atom feed
* Creating a pristine environment?
@ 2008-05-08  0:15 Holger Freyther
  2008-05-08 10:05 ` Koen Kooi
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Holger Freyther @ 2008-05-08  0:15 UTC (permalink / raw)
  To: bitbake-dev; +Cc: openembedded-devel

[-- Attachment #1: Type: text/plain, Size: 336 bytes --]

Hey,

I have seen raster's environment breaking various buildsystems and we might 
want to really start having a clean environment before starting to build.

the patch below should implement it. Should we do this in OE? I'm aware of the 
unexport inside OE but we really should do this the otherway around.


comments?

	z.

[-- Attachment #2: clean_environment.patch --]
[-- Type: text/x-diff, Size: 1953 bytes --]

Index: bin/bitbake
===================================================================
--- bin/bitbake	(Revision 1063)
+++ bin/bitbake	(Arbeitskopie)
@@ -42,6 +42,56 @@
 
 
 #============================================================================#
+# clean_environment 
+#============================================================================#
+def clean_environment():
+    """
+    Create a pristine environment for bitbake. This will remove variables that
+    are not known and may influence the build in a negative way.
+    """
+    good_keys = [
+        "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",
+    ]
+
+
+    removed_vars = []
+    for key in os.environ.keys():
+        if key in good_keys:
+            continue
+        
+        removed_vars.append(key)
+        os.unsetenv(key)
+        del os.environ[key]
+
+    if len(removed_vars):
+        bb.note("Removed the following variables from the environment:", ",".join(removed_vars))
+
+
+#============================================================================#
 # main
 #============================================================================#
 
@@ -111,6 +161,8 @@
     configuration.pkgs_to_build = []
     configuration.pkgs_to_build.extend(args[1:])
 
+    clean_environment()
+
     cooker = bb.cooker.BBCooker(configuration)
 
     if configuration.profile:

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-08  0:15 Creating a pristine environment? Holger Freyther
@ 2008-05-08 10:05 ` Koen Kooi
  2008-05-08 11:06   ` Holger Freyther
  2008-05-08 12:06 ` Cliff Brake
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Koen Kooi @ 2008-05-08 10:05 UTC (permalink / raw)
  To: openembedded-devel; +Cc: bitbake-dev

Holger Freyther wrote:
> Hey,
>
> I have seen raster's environment breaking various buildsystems and we might
> want to really start having a clean environment before starting to build.
>
> the patch below should implement it. Should we do this in OE? I'm aware of the
> unexport inside OE but we really should do this the otherway around.

While this is a good idea, your current implementation breaks:

MACHINE=foo ANGSTROM_MODE=bar bitbake foo-bar-image


>
>
> comments?
>
> 	z.
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Openembedded-devel mailing list
> Openembedded-devel@lists.openembedded.org
> http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-08 10:05 ` Koen Kooi
@ 2008-05-08 11:06   ` Holger Freyther
  2008-05-08 11:29     ` Richard Purdie
  0 siblings, 1 reply; 16+ messages in thread
From: Holger Freyther @ 2008-05-08 11:06 UTC (permalink / raw)
  To: openembedded-devel

On Thursday 08 May 2008 12:05:38 Koen Kooi wrote:
> Holger Freyther wrote:
> > Hey,
> >
> > I have seen raster's environment breaking various buildsystems and we
> > might want to really start having a clean environment before starting to
> > build.
> >
> > the patch below should implement it. Should we do this in OE? I'm aware
> > of the unexport inside OE but we really should do this the otherway
> > around.
>
> While this is a good idea, your current implementation breaks:
>
> MACHINE=foo ANGSTROM_MODE=bar bitbake foo-bar-image

Well, that would make a case for keeping the unexport feature in OE. Or we 
could move the unsetting to after having parsed the configuration. I will 
give the 2nd idea a go...


z.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-08 11:06   ` Holger Freyther
@ 2008-05-08 11:29     ` Richard Purdie
  2008-05-08 12:51       ` Mark Brown
  2008-05-10 12:05       ` Holger Freyther
  0 siblings, 2 replies; 16+ messages in thread
From: Richard Purdie @ 2008-05-08 11:29 UTC (permalink / raw)
  To: openembedded-devel

On Thu, 2008-05-08 at 13:06 +0200, Holger Freyther wrote:
> On Thursday 08 May 2008 12:05:38 Koen Kooi wrote:
> > Holger Freyther wrote:
> > > Hey,
> > >
> > > I have seen raster's environment breaking various buildsystems and we
> > > might want to really start having a clean environment before starting to
> > > build.
> > >
> > > the patch below should implement it. Should we do this in OE? I'm aware
> > > of the unexport inside OE but we really should do this the otherway
> > > around.
> >
> > While this is a good idea, your current implementation breaks:
> >
> > MACHINE=foo ANGSTROM_MODE=bar bitbake foo-bar-image
> 
> Well, that would make a case for keeping the unexport feature in OE. Or we 
> could move the unsetting to after having parsed the configuration. I will 
> give the 2nd idea a go...

I agree we should do something, I'm just not sure what. Personally I do
set things in the environment quite heavily and I'd prefer not to lose
that capability. Perhaps we clean by default but allow a user to
override and claim their starting environment is clean at their own
risk?

Cheers,

Richard




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-08  0:15 Creating a pristine environment? Holger Freyther
  2008-05-08 10:05 ` Koen Kooi
@ 2008-05-08 12:06 ` Cliff Brake
  2008-05-08 12:14   ` Leon Woestenberg
  2008-05-08 14:10 ` Geoffrey Wossum
  2008-05-09  8:55 ` Leon Woestenberg
  3 siblings, 1 reply; 16+ messages in thread
From: Cliff Brake @ 2008-05-08 12:06 UTC (permalink / raw)
  To: openembedded-devel; +Cc: bitbake-dev

On Wed, May 7, 2008 at 8:15 PM, Holger Freyther <zecke@selfish.org> wrote:
> Hey,
>
>  I have seen raster's environment breaking various buildsystems and we might
>  want to really start having a clean environment before starting to build.
>
>  the patch below should implement it. Should we do this in OE? I'm aware of the
>  unexport inside OE but we really should do this the otherway around.

I currently use a few other env variables in my builds to make things
a little more convenient:
export OEDIR="/build/myproject/oe"
export TOPDIR="${OEDIR}/build/angstrom-2007.1"
export BBPATH="${OEDIR}/oe/custom:${TOPDIR}:${OEDIR}/oe/org.openembedded.dev"
export PATH="${OEDIR}/bitbake/bin:${PATH}"

and then in site.conf:
DL_DIR = "${OEDIR}/downloads"

BBFILES := "${OEDIR}/oe/org.openembedded.dev/packages/*/*.bb
${OEDIR}/oe/custom/packages/*/*.bb"
BBFILE_COLLECTIONS = "upstream custom"
BBFILE_PATTERN_upstream = "^${OEDIR}/oe/org.openembedded.dev/packages/"
BBFILE_PATTERN_custom = "^${OEDIR}/oe/custom/packages"
BBFILE_PRIORITY_upstream = "5"
BBFILE_PRIORITY_custom = "10"

So, I would like OEDIR and TOPDIR included in the "good" list :-)

Thanks,
Cliff

-- 
=======================
Cliff Brake
http://bec-systems.com



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-08 12:06 ` Cliff Brake
@ 2008-05-08 12:14   ` Leon Woestenberg
  2008-05-08 13:57     ` Cliff Brake
  0 siblings, 1 reply; 16+ messages in thread
From: Leon Woestenberg @ 2008-05-08 12:14 UTC (permalink / raw)
  To: openembedded-devel

Hello Cliff,

On Thu, May 8, 2008 at 2:06 PM, Cliff Brake <cliff.brake@gmail.com> wrote:
>  export TOPDIR="${OEDIR}/build/angstrom-2007.1"

A warning here, I have seen breakage with some environment variables.

I think TOPDIR is used by u-boot or some such.

Think of a better (more uniquer) namespace, such as OE_TOPDIR.

Regards,
-- 
Leon



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-08 11:29     ` Richard Purdie
@ 2008-05-08 12:51       ` Mark Brown
  2008-05-10 12:05       ` Holger Freyther
  1 sibling, 0 replies; 16+ messages in thread
From: Mark Brown @ 2008-05-08 12:51 UTC (permalink / raw)
  To: openembedded-devel; +Cc: openembedded-devel

On Thu, May 08, 2008 at 12:29:30PM +0100, Richard Purdie wrote:

> that capability. Perhaps we clean by default but allow a user to
> override and claim their starting environment is clean at their own
> risk?

That's roughly how SCons handles a similar feature - it defaults to
cleaning the environment but makes the original environment availiable
to the build system so it can either be referred to or imported
wholesale as desired.

-- 
"You grabbed my hand and we fell into it, like a daydream - or a fever."



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-08 12:14   ` Leon Woestenberg
@ 2008-05-08 13:57     ` Cliff Brake
  0 siblings, 0 replies; 16+ messages in thread
From: Cliff Brake @ 2008-05-08 13:57 UTC (permalink / raw)
  To: openembedded-devel

On Thu, May 8, 2008 at 8:14 AM, Leon Woestenberg
<leon.woestenberg@gmail.com> wrote:
>  On Thu, May 8, 2008 at 2:06 PM, Cliff Brake <cliff.brake@gmail.com> wrote:
>  >  export TOPDIR="${OEDIR}/build/angstrom-2007.1"
>
>  A warning here, I have seen breakage with some environment variables.
>
>  I think TOPDIR is used by u-boot or some such.
>
>  Think of a better (more uniquer) namespace, such as OE_TOPDIR.

Good point.  TOPDIR is currently coded in bitbake:

./lib/bb/parse/parse_py/ConfHandler.py:    if not
bb.data.getVar('TOPDIR', data):
./lib/bb/parse/parse_py/ConfHandler.py:
bb.data.setVar('TOPDIR', os.getcwd(), data)
./lib/bb/build.py:        prevdir = data.expand('${TOPDIR}', d)

so, it won't be trivial to change without breaking existing build environments.

Thanks,
Cliff

-- 
=======================
Cliff Brake
http://bec-systems.com



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-08  0:15 Creating a pristine environment? Holger Freyther
  2008-05-08 10:05 ` Koen Kooi
  2008-05-08 12:06 ` Cliff Brake
@ 2008-05-08 14:10 ` Geoffrey Wossum
  2008-05-09  8:55 ` Leon Woestenberg
  3 siblings, 0 replies; 16+ messages in thread
From: Geoffrey Wossum @ 2008-05-08 14:10 UTC (permalink / raw)
  To: openembedded-devel

On Wednesday 07 May 2008 07:15:23 pm Holger Freyther wrote:

> I have seen raster's environment breaking various buildsystems and we might
> want to really start having a clean environment before starting to build.
>
> the patch below should implement it. Should we do this in OE? I'm aware of
> the unexport inside OE but we really should do this the otherway around.

Using some variables from the users environment is good, as others have 
mentioned.  But some (I'm looking at you, CPATH) really need to be unset.  My 
Gentoo system automatically sets CPATH, and having that set results in "CROSS 
COMPILE Badness: /usr/include in INCLUDEPATH: /usr/include/libffi".  

---
Geoffrey






^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-08  0:15 Creating a pristine environment? Holger Freyther
                   ` (2 preceding siblings ...)
  2008-05-08 14:10 ` Geoffrey Wossum
@ 2008-05-09  8:55 ` Leon Woestenberg
  3 siblings, 0 replies; 16+ messages in thread
From: Leon Woestenberg @ 2008-05-09  8:55 UTC (permalink / raw)
  To: openembedded-devel

Hello,

On Thu, May 8, 2008 at 2:15 AM, Holger Freyther <zecke@selfish.org> wrote:
> comments?
>
How about in the insanity checker?

We would like the user to make sure his environment is sane for
OpenEmbedded, and not try to fix it up ourselves.

Regards,
-- 
Leon



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-08 11:29     ` Richard Purdie
  2008-05-08 12:51       ` Mark Brown
@ 2008-05-10 12:05       ` Holger Freyther
  2008-05-10 12:28         ` Koen Kooi
  2008-05-19 21:15         ` Richard Purdie
  1 sibling, 2 replies; 16+ messages in thread
From: Holger Freyther @ 2008-05-10 12:05 UTC (permalink / raw)
  To: openembedded-devel; +Cc: bitbake-dev

[-- Attachment #1: Type: text/plain, Size: 1561 bytes --]

On Thursday 08 May 2008 13:29:30 Richard Purdie wrote:
> On Thu, 2008-05-08 at 13:06 +0200, Holger Freyther wrote:
> > On Thursday 08 May 2008 12:05:38 Koen Kooi wrote:
> > > Holger Freyther wrote:
> > > > Hey,
> > > >
> > > > I have seen raster's environment breaking various buildsystems and we
> > > > might want to really start having a clean environment before starting
> > > > to build.
> > > >
> > > > the patch below should implement it. Should we do this in OE? I'm
> > > > aware of the unexport inside OE but we really should do this the
> > > > otherway around.
> > >
> > > While this is a good idea, your current implementation breaks:
> > >
> > > MACHINE=foo ANGSTROM_MODE=bar bitbake foo-bar-image
> >
> > Well, that would make a case for keeping the unexport feature in OE. Or
> > we could move the unsetting to after having parsed the configuration. I
> > will give the 2nd idea a go...
>
> I agree we should do something, I'm just not sure what. Personally I do
> set things in the environment quite heavily and I'd prefer not to lose
> that capability. Perhaps we clean by default but allow a user to
> override and claim their starting environment is clean at their own
> risk?

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).

comments?

	z.


[-- Attachment #2: bitbake-remove-environment-r1.diff --]
[-- Type: text/x-diff, Size: 4054 bytes --]

Index: doc/bitbake.1
===================================================================
--- doc/bitbake.1	(Revision 1067)
+++ doc/bitbake.1	(Arbeitskopie)
@@ -97,13 +97,18 @@
 .B \-IIGNORED\_DOT\_DEPS, \-\-ignore-deps=IGNORED_DOT_DEPS
 Stop processing at the given list of dependencies when generating dependency
 graphs. This can help to make the graph more appealing
-.\"
-.\" Next option is only in BitBake 1.7.x (trunk)
-.\"
-.\".TP
-.\".B \-lDEBUG_DOMAINS, \-\-log-domains=DEBUG_DOMAINS
-.\"Show debug logging for the specified logging domains
+.TP
+.B \-lDEBUG_DOMAINS, \-\-log-domains=DEBUG_DOMAINS
+Show debug logging for the specified logging domains
+.TP
+.B \-P, \-\-profile
+profile the command and print a report
+.TP
+.B \-S, \-\-sane-environment
+Do not clean the environment variables. Use this on your own risk.
+.TP
 
+
 .SH AUTHORS
 BitBake was written by 
 Phil Blundell,
Index: doc/manual/usermanual.xml
===================================================================
--- doc/manual/usermanual.xml	(Revision 1067)
+++ doc/manual/usermanual.xml	(Arbeitskopie)
@@ -415,6 +415,10 @@
                         the graph more appealing
   -l DEBUG_DOMAINS, --log-domains=DEBUG_DOMAINS
                         Show debug logging for the specified logging domains
+  -P, --profile         profile the command and print a report
+  -S, --sane-environment
+                        Do not clean the environment variables. Use this on
+                        your own risk.
 
 </screen>
                 </para>
Index: bin/bitbake
===================================================================
--- bin/bitbake	(Revision 1067)
+++ bin/bitbake	(Arbeitskopie)
@@ -42,6 +42,56 @@
 
 
 #============================================================================#
+# clean_environment 
+#============================================================================#
+def clean_environment():
+    """
+    Create a pristine environment for bitbake. This will remove variables that
+    are not known and may influence the build in a negative way.
+    """
+    good_keys = [
+        "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",
+    ]
+
+
+    removed_vars = []
+    for key in os.environ.keys():
+        if key in good_keys:
+            continue
+        
+        removed_vars.append(key)
+        os.unsetenv(key)
+        del os.environ[key]
+
+    if len(removed_vars):
+        bb.note("Removed the following variables from the environment:", ",".join(removed_vars))
+
+
+#============================================================================#
 # main
 #============================================================================#
 
@@ -105,6 +155,9 @@
     parser.add_option( "-P", "--profile", help = "profile the command and print a report",
                action = "store_true", dest = "profile", default = False )
 
+    parser.add_option( "-S", "--sane-environment", help = """Do not clean the environment variables. Use this on your own risk.""",
+                action = "store_false", dest = "clean_environment", default = True)
+
     options, args = parser.parse_args(sys.argv)
 
     configuration = BBConfiguration(options)
@@ -112,6 +165,8 @@
     configuration.pkgs_to_build.extend(args[1:])
 
     cooker = bb.cooker.BBCooker(configuration)
+    if options.clean_environment:
+        clean_environment()
 
     if configuration.profile:
         try:

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-10 12:05       ` Holger Freyther
@ 2008-05-10 12:28         ` Koen Kooi
  2008-05-13  8:43           ` Holger Freyther
  2008-05-19 21:15         ` Richard Purdie
  1 sibling, 1 reply; 16+ messages in thread
From: Koen Kooi @ 2008-05-10 12:28 UTC (permalink / raw)
  To: openembedded-devel; +Cc: bitbake-dev

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.

Implementation question: who will fix all the shell based functions in 
OE that rely on things like MACHINE being exported?

regards,

Koen




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-10 12:28         ` Koen Kooi
@ 2008-05-13  8:43           ` Holger Freyther
  2008-05-13 10:42             ` Rolf Leggewie
  0 siblings, 1 reply; 16+ messages in thread
From: Holger Freyther @ 2008-05-13  8:43 UTC (permalink / raw)
  To: openembedded-devel

On Saturday 10 May 2008 14:28:39 Koen Kooi wrote:
> 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.
>
> Implementation question: who will fix all the shell based functions in
> OE that rely on things like MACHINE being exported?

To my understanding there is nothing to fix. Bitbake will unexport the 
environment after having parsed the configuration. If you have export FOO 
inside a Bitbake file. data.py:emit_var will put an "export FOO=.." into the 
shell script.

comments.

	z.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-13  8:43           ` Holger Freyther
@ 2008-05-13 10:42             ` Rolf Leggewie
  0 siblings, 0 replies; 16+ messages in thread
From: Rolf Leggewie @ 2008-05-13 10:42 UTC (permalink / raw)
  To: openembedded-devel

Holger Freyther wrote:
> To my understanding there is nothing to fix. Bitbake will unexport the 
> environment after having parsed the configuration. 

MACHINE=spitz bitbake opie-image

will still work?




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-10 12:05       ` Holger Freyther
  2008-05-10 12:28         ` Koen Kooi
@ 2008-05-19 21:15         ` Richard Purdie
  2008-05-21 21:38           ` Richard Purdie
  1 sibling, 1 reply; 16+ messages in thread
From: Richard Purdie @ 2008-05-19 21:15 UTC (permalink / raw)
  To: openembedded-devel; +Cc: bitbake-dev

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




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Creating a pristine environment?
  2008-05-19 21:15         ` Richard Purdie
@ 2008-05-21 21:38           ` Richard Purdie
  0 siblings, 0 replies; 16+ messages in thread
From: Richard Purdie @ 2008-05-21 21:38 UTC (permalink / raw)
  To: openembedded-devel; +Cc: bitbake-dev

Hi,

I talked to Holger about the previous patch and he rightly IMO didn't
like some aspects of it. In the discussion we concluded (I think,
correct me if I'm wrong!) the best idea was to:

Take the original environment and process it as I proposed cleaning
completely by default apart from the standard whitelist and allowing
this behaviour to be overridden with:

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)

Any variables still in the environment after this process are added into
the data dictionary. The difference is that whilst we used to export
everything in the original environment when executing shell tasks we now
will only export anything explicitly marked as an export.

I ran some tests and various things did break, specifically, PATH went
missing, devshell was missing some variables and bbimage broke badly. I
did fix up bbimage but then I decided to remove it entirely, something
long planned we've just never got around to it. I've added fixes for the
PATH and devshell issues although devshell could perhaps use some
further variables.

One side effect of this is we can throw the 'matchesenv' flag away which
might actually give a small parsing speedup.

So, any further comments?

I should probably s/BB_PRESERVE_ENV/BB_ENV_PRESERVE/ for consistency.

Cheers,

Richard

Index: lib/bb/utils.py
===================================================================
--- lib/bb/utils.py	(revision 4517)
+++ lib/bb/utils.py	(working copy)
@@ -268,3 +268,59 @@
     for line in open(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
+
+
Index: lib/bb/data.py
===================================================================
--- lib/bb/data.py	(revision 4517)
+++ lib/bb/data.py	(working copy)
@@ -324,22 +324,16 @@
         if val != expanded:
             setVar(key, expanded, alterdata)
 
-import os
-
 def inheritFromOS(d):
     """Inherit variables from the environment."""
-#   fakeroot needs to be able to set these
-    non_inherit_vars = [ "LD_LIBRARY_PATH", "LD_PRELOAD" ]
     for s in os.environ.keys():
-        if not s in non_inherit_vars:
-            try:
-                setVar(s, os.environ[s], d)
-                setVarFlag(s, 'matchesenv', '1', d)
-            except TypeError:
-                pass
+        try:
+            setVar(s, os.environ[s], d)
+        except TypeError:
+            pass
+        os.unsetenv(s)
+        del os.environ[s]
 
-import sys
-
 def emit_var(var, o=sys.__stdout__, d = init(), all=False):
     """Emit a variable to be sourced by a shell."""
     if getVarFlag(var, "python", d):
@@ -379,9 +373,6 @@
         o.write('unset %s\n' % varExpanded)
         return 1
 
-    if getVarFlag(var, 'matchesenv', d):
-        return 0
-
     val.rstrip()
     if not val:
         return 0
Index: lib/bb/data_smart.py
===================================================================
--- lib/bb/data_smart.py	(revision 4517)
+++ lib/bb/data_smart.py	(working copy)
@@ -149,9 +149,6 @@
 
         if not var in self.dict:
             self._makeShadowCopy(var)
-        if self.getVarFlag(var, 'matchesenv'):
-            self.delVarFlag(var, 'matchesenv')
-            self.setVarFlag(var, 'export', 1)
 
         # more cookies for the cookie monster
         if '_' in var:
Index: lib/bb/cooker.py
===================================================================
--- lib/bb/cooker.py	(revision 4517)
+++ lib/bb/cooker.py	(working copy)
@@ -59,6 +59,10 @@
 
         self.configuration.data = bb.data.init()
 
+    def parseConfiguration(self):
+
+        bb.data.inheritFromOS(self.configuration.data)
+
         for f in self.configuration.file:
             self.parseConfigurationFile( f )
 
Index: lib/bb/parse/parse_py/ConfHandler.py
===================================================================
--- lib/bb/parse/parse_py/ConfHandler.py	(revision 4517)
+++ lib/bb/parse/parse_py/ConfHandler.py	(working copy)
@@ -118,7 +118,6 @@
     init(data)
 
     if include == 0:
-        bb.data.inheritFromOS(data)
         oldfile = None
     else:
         oldfile = bb.data.getVar('FILE', data)
Index: bin/bitbake
===================================================================
--- bin/bitbake	(revision 4517)
+++ bin/bitbake	(working copy)
@@ -113,6 +113,18 @@
 
     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)
+
+    cooker.parseConfiguration()
+
     if configuration.profile:
         try:
             import cProfile as profile




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2008-05-21 21:41 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-08  0:15 Creating a pristine environment? Holger Freyther
2008-05-08 10:05 ` Koen Kooi
2008-05-08 11:06   ` Holger Freyther
2008-05-08 11:29     ` Richard Purdie
2008-05-08 12:51       ` Mark Brown
2008-05-10 12:05       ` Holger Freyther
2008-05-10 12:28         ` Koen Kooi
2008-05-13  8:43           ` Holger Freyther
2008-05-13 10:42             ` Rolf Leggewie
2008-05-19 21:15         ` Richard Purdie
2008-05-21 21:38           ` Richard Purdie
2008-05-08 12:06 ` Cliff Brake
2008-05-08 12:14   ` Leon Woestenberg
2008-05-08 13:57     ` Cliff Brake
2008-05-08 14:10 ` Geoffrey Wossum
2008-05-09  8:55 ` Leon Woestenberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.