Fix SOURCEDIR, BUILDDIR and similar when `cd` prints to stdout 85/18185/2
authorHenrique Ferreiro <hferreiro@igalia.com>
Fri, 23 Nov 2018 00:40:32 +0000 (01:40 +0100)
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>
Fri, 23 Nov 2018 19:16:16 +0000 (19:16 +0000)
Several variables containing directories in `aglsetup.sh` and other
scripts use the common one-liner "cd $DIR && pwd -P" to resolve
symlinks. Unfortunately, in some cases, `cd` writes the new directory to
stdout, e.g. when using multiple search paths. This commit changes the
above to "cd $DIR > /dev/null && pwd -P" to make it more robust.

Change-Id: I150ecc9940d88738cf17add68290c35486a81a3b
Signed-off-by: Henrique Ferreiro <hferreiro@igalia.com>
scripts/.aglsetup_genconfig.bash
scripts/aglsetup.sh
scripts/envsetup.sh

index d4f3ba8..b2471a7 100755 (executable)
@@ -39,8 +39,8 @@ DEBUG=0
 
 #SCRIPT=$(basename $BASH_SOURCE)
 SCRIPT=aglsetup.sh
-SCRIPTDIR=$(cd $(dirname $BASH_SOURCE) && pwd -P)
-METADIR=$(cd $(dirname $BASH_SOURCE)/../.. && pwd -P)
+SCRIPTDIR=$(cd $(dirname $BASH_SOURCE) > /dev/null && pwd -P)
+METADIR=$(cd $(dirname $BASH_SOURCE)/../.. > /dev/null && pwd -P)
 
 function info() { echo "$@" >&2; }
 function infon() { echo -n "$@" >&2; }
@@ -342,7 +342,7 @@ done
 
 # validate build dir
 debug "validating builddir $BUILDDIR"
-BUILDDIR=$(mkdir -p "$BUILDDIR" && cd "$BUILDDIR" && pwd -P)
+BUILDDIR=$(mkdir -p "$BUILDDIR" && cd "$BUILDDIR" > /dev/null && pwd -P)
 validate_builddir
 
 ###########################################################################################
@@ -359,7 +359,7 @@ function genconfig() {
        info "   Features: $FEATURES"
 
        # step 1: run usual OE setup to generate conf dir
-       export TEMPLATECONF=$(cd $SCRIPTDIR/../templates/base && pwd -P)
+       export TEMPLATECONF=$(cd $SCRIPTDIR/../templates/base > /dev/null && pwd -P)
        debug "running oe-init-build-env with TEMPLATECONF=$TEMPLATECONF"
        info "   Running $METADIR/poky/oe-init-build-env"
        info "   Templates dir: $TEMPLATECONF"
index b11a541..e7b4b19 100644 (file)
 # detect if this script is sourced: see http://stackoverflow.com/a/38128348/6255594
 SOURCED=0
 if [ -n "$ZSH_EVAL_CONTEXT" ]; then 
-       [[ $ZSH_EVAL_CONTEXT =~ :file$ ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $0) && pwd -P); }
+       [[ $ZSH_EVAL_CONTEXT =~ :file$ ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $0) > /dev/null && pwd -P); }
 elif [ -n "$KSH_VERSION" ]; then
-       [[ "$(cd $(dirname -- $0) && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) && pwd -P)/$(basename -- ${.sh.file})" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- ${.sh.file}) && pwd -P); }
+       [[ "$(cd $(dirname -- $0) > /dev/null && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) > /dev/null && pwd -P)/$(basename -- ${.sh.file})" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- ${.sh.file}) > /dev/null && pwd -P); }
 elif [ -n "$BASH_VERSION" ]; then
-       [[ $0 != "$BASH_SOURCE" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $BASH_SOURCE) && pwd -P); }
+       [[ $0 != "$BASH_SOURCE" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $BASH_SOURCE) > /dev/null && pwd -P); }
 fi
 
 if [ $SOURCED -ne 1 ]; then
index 27b1de1..ad2cce7 100644 (file)
 # detect if this script is sourced: see http://stackoverflow.com/a/38128348/6255594
 SOURCED=0
 if [ -n "$ZSH_EVAL_CONTEXT" ]; then 
-       [[ $ZSH_EVAL_CONTEXT =~ :file$ ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $0) && pwd -P); }
+       [[ $ZSH_EVAL_CONTEXT =~ :file$ ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $0) > /dev/null && pwd -P); }
 elif [ -n "$KSH_VERSION" ]; then
-       [[ "$(cd $(dirname -- $0) && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) && pwd -P)/$(basename -- ${.sh.file})" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- ${.sh.file}) && pwd -P); }
+       [[ "$(cd $(dirname -- $0) > /dev/null && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) > /dev/null && pwd -P)/$(basename -- ${.sh.file})" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- ${.sh.file}) > /dev/null && pwd -P); }
 elif [ -n "$BASH_VERSION" ]; then
-       [[ $0 != "$BASH_SOURCE" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $BASH_SOURCE) && pwd -P); }
+       [[ $0 != "$BASH_SOURCE" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $BASH_SOURCE) > /dev/null && pwd -P); }
 fi
 
 if [ $SOURCED -ne 1 ]; then