[1/1] oe-buildenv-internal: Only add to $PATH if needed

Submitted by Peter Kjellerstedt on April 9, 2013, 10:24 a.m.

Details

Message ID 4b8c3ca6b0f66674fbc8196e9bbed57ca9df2980.1365503027.git.pkj@axis.com
State New
Headers show

Commit Message

Peter Kjellerstedt April 9, 2013, 10:24 a.m.
First strip $PATH of any existence of the paths needed by Open Embedded
and BitBake. Then add the needed paths at the beginning. This makes sure
the needed paths are searched first, without growing $PATH unnecessarily
if oe-init-build-env is rerun for a directory for which it has
previously been run.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---
 scripts/oe-buildenv-internal | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/scripts/oe-buildenv-internal b/scripts/oe-buildenv-internal
index 0a4d324..644df8f 100755
--- a/scripts/oe-buildenv-internal
+++ b/scripts/oe-buildenv-internal
@@ -74,8 +74,10 @@  if ! (test -d "$BITBAKEDIR"); then
     return 1
 fi
 
-PATH="${OEROOT}/scripts:$BITBAKEDIR/bin/:$PATH"
-unset BITBAKEDIR
+# Make sure our paths are at the beginning of $PATH
+NEWPATHS="${OEROOT}/scripts:$BITBAKEDIR/bin:"
+PATH=$NEWPATHS$(echo $PATH | sed -e "s|:$NEWPATHS|:|g" -e "s|^$NEWPATHS||")
+unset BITBAKEDIR NEWPATHS
 
 # Used by the runqemu script
 export BUILDDIR

Comments

Richard Purdie April 9, 2013, 12:16 p.m.
On Tue, 2013-04-09 at 12:24 +0200, Peter Kjellerstedt wrote:
> First strip $PATH of any existence of the paths needed by Open Embedded
> and BitBake. Then add the needed paths at the beginning. This makes sure
> the needed paths are searched first, without growing $PATH unnecessarily
> if oe-init-build-env is rerun for a directory for which it has
> previously been run.
> 
> Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
> ---
>  scripts/oe-buildenv-internal | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

I'll merge this however ultimately I suspect we should have off the
original PATH into some variable, then if that variable is set, append
NEWPATHS to the original value and reset PATH to that.

It does mean if the user messed with path in the meantime, it gets reset
but I suspect not many users do that.

Cheers,

Richard

> diff --git a/scripts/oe-buildenv-internal b/scripts/oe-buildenv-internal
> index 0a4d324..644df8f 100755
> --- a/scripts/oe-buildenv-internal
> +++ b/scripts/oe-buildenv-internal
> @@ -74,8 +74,10 @@ if ! (test -d "$BITBAKEDIR"); then
>      return 1
>  fi
>  
> -PATH="${OEROOT}/scripts:$BITBAKEDIR/bin/:$PATH"
> -unset BITBAKEDIR
> +# Make sure our paths are at the beginning of $PATH
> +NEWPATHS="${OEROOT}/scripts:$BITBAKEDIR/bin:"
> +PATH=$NEWPATHS$(echo $PATH | sed -e "s|:$NEWPATHS|:|g" -e "s|^$NEWPATHS||")
> +unset BITBAKEDIR NEWPATHS
>  
>  # Used by the runqemu script
>  export BUILDDIR