From: "Paul Barker" <paul@pbarker.dev>
To: "Babanpreet Singh" <bbnpreetsingh@gmail.com>,
<openembedded-core@lists.openembedded.org>
Cc: "Ross Burton" <ross.burton@arm.com>
Subject: Re: [PATCH] oe-init-build-env: fix unbound variable errors under 'set -u'
Date: Mon, 23 Nov 2026 09:25:00 +0000 [thread overview]
Message-ID: <DN2HD431V6TX.3GQ0CXC17IQLQ@pbarker.dev> (raw)
In-Reply-To: <20261111195604.7-1-bbnpreetsingh@gmail.com>
On Wed Nov 11, 2026 at 7:56 PM GMT, Babanpreet Singh wrote:
> 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 <bbnpreetsingh@gmail.com>
> ---
> oe-init-build-env | 14 +++++++-------
> scripts/oe-buildenv-internal | 22 +++++++++++-----------
> 2 files changed, 18 insertions(+), 18 deletions(-)
>
> diff --git a/oe-init-build-env b/oe-init-build-env
> index 5a2bd0f4d9..660c6ad02e 100755
> --- a/oe-init-build-env
> +++ b/oe-init-build-env
> @@ -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"
>
> diff --git a/scripts/oe-buildenv-internal b/scripts/oe-buildenv-internal
> index 2fdb19565a..6b2e4ea518 100755
> --- a/scripts/oe-buildenv-internal
> +++ b/scripts/oe-buildenv-internal
> @@ -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
Hi,
This change looks good to me, but it does suggest we need a test case
here for sourcing oe-init-build-env in a script using `set -u`. Are you
able to write a test case?
Best regards,
--
Paul Barker
next prev parent reply other threads:[~2026-11-23 9:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 19:56 [PATCH] oe-init-build-env: fix unbound variable errors under 'set -u' Babanpreet Singh
2026-11-23 9:25 ` Paul Barker [this message]
2026-11-24 19:10 ` [PATCH] oeqa/selftest/oescripts: add a test for oe-init-build-env under set -u Babanpreet Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DN2HD431V6TX.3GQ0CXC17IQLQ@pbarker.dev \
--to=paul@pbarker.dev \
--cc=bbnpreetsingh@gmail.com \
--cc=openembedded-core@lists.openembedded.org \
--cc=ross.burton@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.