oe-init-build-env: fix unbound variable errors under 'set -u'
PATCH 1/1 oe-init-build-env: fix unbound variable errors under 'set -u'
Sourcing oe-init-build-env from a shell running with 'set -u' fails:
./oe-init-build-env: line 29: BBSERVER: unbound variable
Give the variables that may be unset an explicit empty default, here and in oe-buildenv-internal.
[YOCTO #15469]
Signed-off-by Babanpreet Singh <[email protected]>
--- oe-init-build-env | 14 +++++++------- scripts/oe-buildenv-internal | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 18 deletions(-)
oe-init-build-env +7 -7
@@ -14,9 +14,9 @@ # when being sourced. To workaround the shell limitation use "set <builddir>" # prior to sourcing this script. # -if [ -n "$BASH_SOURCE" ]; then +if [ -n "${BASH_SOURCE:-}" ]; then THIS_SCRIPT=$BASH_SOURCE -elif [ -n "$ZSH_NAME" ]; then +elif [ -n "${ZSH_NAME:-}" ]; then THIS_SCRIPT=$0 else THIS_SCRIPT="$(pwd)/oe-init-build-env"
@@ -26,16 +26,16 @@ else exit 1 fi fi -if [ -n "$BBSERVER" ]; then +if [ -n "${BBSERVER:-}" ]; then unset BBSERVER fi -if [ -z "$ZSH_NAME" ] && [ "$0" = "$THIS_SCRIPT" ]; then +if [ -z "${ZSH_NAME:-}" ] && [ "$0" = "$THIS_SCRIPT" ]; then echo "Error: This script needs to be sourced. Please run as '. $THIS_SCRIPT'" >&2 exit 1 fi -if [ -z "$OEROOT" ]; then +if [ -z "${OEROOT:-}" ]; then OEROOT=$(dirname "$THIS_SCRIPT") OEROOT=$(readlink -f "$OEROOT") fi
@@ -43,12 +43,12 @@ unset THIS_SCRIPT export OEROOT . "$OEROOT"/scripts/oe-buildenv-internal && - TEMPLATECONF="$TEMPLATECONF" "$OEROOT"/scripts/oe-setup-builddir || { + TEMPLATECONF="${TEMPLATECONF:-}" "$OEROOT"/scripts/oe-setup-builddir || { unset OEROOT return 1 } unset OEROOT -[ -z "$BUILDDIR" ] || cd "$BUILDDIR" +[ -z "${BUILDDIR:-}" ] || cd "$BUILDDIR"
scripts/oe-buildenv-internal +11 -11
@@ -19,12 +19,12 @@ if ! $(return >/dev/null 2>&1) ; then fi # It is assumed OEROOT is already defined when this is called -if [ -z "$OEROOT" ]; then +if [ -z "${OEROOT:-}" ]; then echo >&2 "Error: OEROOT is not defined!" return 1 fi -if [ -z "$OE_SKIP_SDK_CHECK" ] && [ -n "$OECORE_SDK_VERSION" ]; then +if [ -z "${OE_SKIP_SDK_CHECK:-}" ] && [ -n "${OECORE_SDK_VERSION:-}" ]; then echo >&2 "Error: The OE SDK/ADT was detected as already being present in this shell environment. Please use a clean shell when sourcing this environment script." return 1 fi
@@ -39,8 +39,8 @@ if [ "$py_v38_check" != "True" ]; then fi unset py_v38_check -if [ -z "$BDIR" ]; then - if [ -z "$1" ]; then +if [ -z "${BDIR:-}" ]; then + if [ -z "${1:-}" ]; then BDIR="build" else BDIR="$1"
@@ -61,7 +61,7 @@ if [ -z "$BDIR" ]; then return 1 fi fi - if [ -n "$2" ]; then + if [ -n "${2:-}" ]; then BITBAKEDIR="$2" fi fi
@@ -72,9 +72,9 @@ else fi unset BDIR -if [ -z "$BITBAKEDIR" ]; then - BITBAKEDIR="$OEROOT/bitbake$BBEXTRA" - test -d "$BITBAKEDIR" || BITBAKEDIR="$OEROOT/../bitbake$BBEXTRA" +if [ -z "${BITBAKEDIR:-}" ]; then + BITBAKEDIR="$OEROOT/bitbake${BBEXTRA:-}" + test -d "$BITBAKEDIR" || BITBAKEDIR="$OEROOT/../bitbake${BBEXTRA:-}" fi BITBAKEDIR=$(readlink -f "$BITBAKEDIR")
@@ -89,11 +89,11 @@ if [ ! -d "$BITBAKEDIR" ]; then fi # Add BitBake's library to PYTHONPATH -PYTHONPATH=$BITBAKEDIR/lib:$PYTHONPATH +PYTHONPATH=$BITBAKEDIR/lib:${PYTHONPATH:-} export PYTHONPATH # Remove any paths added by sourcing this script before -[ -n "$OE_ADDED_PATHS" ] && PATH=$(echo $PATH | sed -e "s#$OE_ADDED_PATHS##") || +[ -n "${OE_ADDED_PATHS:-}" ] && PATH=$(echo $PATH | sed -e "s#$OE_ADDED_PATHS##") || PATH=$(echo $PATH | sed -e "s#$OEROOT/scripts:$BITBAKEDIR/bin:##") # Make sure our paths are at the beginning of $PATH
@@ -114,6 +114,6 @@ SDKMACHINE BB_NUMBER_THREADS BB_NO_NETWORK PARALLEL_MAKE GIT_PROXY_COMMAND \ SOCKS5_PASSWD SOCKS5_USER SCREENDIR STAMPS_DIR BBPATH_EXTRA BB_SETSCENE_ENFORCE \ BB_LOGCONFIG" -BB_ENV_PASSTHROUGH_ADDITIONS="$(echo $BB_ENV_PASSTHROUGH_ADDITIONS $BB_ENV_PASSTHROUGH_ADDITIONS_OE | tr ' ' '\n' | LC_ALL=C sort --unique | tr '\n' ' ')" +BB_ENV_PASSTHROUGH_ADDITIONS="$(echo ${BB_ENV_PASSTHROUGH_ADDITIONS:-} $BB_ENV_PASSTHROUGH_ADDITIONS_OE | tr ' ' '\n' | LC_ALL=C sort --unique | tr '\n' ' ')" export BB_ENV_PASSTHROUGH_ADDITIONS
Signature · 1 line
2.43.0