# --------------------------------------------------------------------------------------------------------------------- # SPDX-License-Identifier: MIT # --------------------------------------------------------------------------------------------------------------------- flex_sourced=0 if [ -n "$ZSH_EVAL_CONTEXT" ]; then case $ZSH_EVAL_CONTEXT in *:file) flex_sourced=1;; esac elif [ -n "$BASH_VERSION" ]; then (return 0 2>/dev/null) && flex_sourced=1 else echo >&2 "Error: This shell is unsupported. Please use bash or zsh" flex_sourced=2 fi if [ "$flex_sourced" -eq 0 ]; then echo >&2 "Error: This script needs to be sourced. Please run as '. \"$0\"'" false elif [ "$flex_sourced" -eq 2 ]; then false else # shellcheck disable=SC2128 if [ -n "$BASH_SOURCE" ]; then layerdir="$(cd "$(dirname "$BASH_SOURCE")" && pwd -P)" elif [ -n "$ZSH_NAME" ]; then layerdir="$(cd "$(dirname "$0")" && pwd -P)" else layerdir="$(pwd -P)" fi export PYENV_ROOT="${PYENV_ROOT:-~/.pyenv}" PATH="$PYENV_ROOT/shims:$PATH" if [ -f conf/local.conf -o -f conf/bblayers.conf ]; then # Assuming we're already in the build dir BUILDDIR=$PWD else BUILDDIR=$PWD/build fi for i in $(seq $#); do setup_flex_arg="$(eval printf "%s" "\${$i}")" case "$setup_flex_arg" in -b) BUILDDIR="$(eval printf "%s" "\${$((i + 1))}")" if [ -z "$BUILDDIR" ]; then echo >&2 "-b requires an argument" fi BUILDDIR="$(readlink -f "$BUILDDIR")" ;; esac done ( for layercheck in $layerdir . $layerdir/..; do if [ -e "$layercheck/setup-environment.conf" ]; then . "$layercheck/setup-environment.conf" fi if [ -e "$layercheck/.setup-environment.conf" ]; then . "$layercheck/.setup-environment.conf" fi done OPTIONALLAYERS="${OPTIONALLAYERS-flex-private}" # Customer directory layers handling (e.g. -custom) for layercheck in . $layerdir/..; do if [ -e "$layercheck/customer.conf" ]; then while read -r _customer; do for layercheck2 in . $layerdir/..; do if [ -d "$layercheck2/$_customer-custom" ]; then if [ -e "$layercheck2/$_customer-custom/custom.conf" ]; then CUSTOMERLAYERS=$(cat $layercheck2/$_customer-custom/custom.conf | sed -e '/^[ ]*#/d') CUSTOMERLAYERS=$(echo $CUSTOMERLAYERS | sed -e 's/\n//g') OPTIONALLAYERS="$OPTIONALLAYERS $CUSTOMERLAYERS" fi break fi done done <"$layercheck/customer.conf" break fi done # Hotfix layers handling if [ -e "$layerdir/../hotfixes/hotfix.conf" ]; then HOTFIXES=$(cat $layerdir/../hotfixes/hotfix.conf | sed -e '/^[ ]*#/d') HOTFIXES=$(echo $HOTFIXES | sed -e 's/\n//g') OPTIONALLAYERS="$OPTIONALLAYERS $HOTFIXES" fi # Extra layers handling if [ -e "$layerdir/../xlayers.conf" ]; then EXTRALAYERS=$(cat $layerdir/../xlayers.conf | sed -e '/^[ ]*#/d') EXTRALAYERS=$(echo $EXTRALAYERS | sed -e 's/\n//g') OPTIONALLAYERS="$OPTIONALLAYERS $EXTRALAYERS" fi export OPTIONALLAYERS EXTRAFLEXLAYERS EXCLUDEDLAYERS $layerdir/scripts/setup-flex-builddir "$@" ) flex_setup_ret=$? if [ $flex_setup_ret -eq 0 ] && [ -n "$BUILDDIR" ] && [ -e "$BUILDDIR" ]; then . $BUILDDIR/setup-environment configured_layers() { tac $BUILDDIR/conf/bblayers.conf \ | sed -n -e '/^"/,/^BBLAYERS = /{ /^BBLAYERS =/d; /^"/d; p;}' \ | awk {'print $1'} | sed -e "s#\${TOPDIR}/#$BUILDDIR/#" } load_lconf_snippet() { if [ ! -e "$1/$2" ]; then return fi ( lheadername="${1#${layerdir%/*}/}/$2" printf '\n## Begin %s\n\n' "$lheadername" cat "$1/$2" printf '\n## End %s\n' "$lheadername" ) >>conf/local.conf } if [ -e "$BUILDDIR/conf/local.conf" ] && [ -e "$BUILDDIR/conf/bblayers.conf" ]; then sed -i -n -e ":out; /^## Begin /{ :loop; /^## End /{ d; b out; }; n; b loop; }; p;" conf/local.conf SETUP_ENV_MACHINE="$(sed -n -e 's/^MACHINE *?*= *"\(.*\)"/\1/p' "$BUILDDIR/conf/local.conf")" if [ -e "$layerdir/post-setup-environment" ]; then layer="$layerdir" . "$layerdir/post-setup-environment" fi load_lconf_snippet "$layerdir" "conf/local.conf.append" load_lconf_snippet "$layerdir" "conf/local.conf.append.$SETUP_ENV_MACHINE" configured_layers | grep -Fvx "$layerdir" | while read layer; do if [ -e $layer/post-setup-environment ]; then . $layer/post-setup-environment fi load_lconf_snippet "$layer" "conf/local.conf.append" load_lconf_snippet "$layer" "conf/local.conf.append.$SETUP_ENV_MACHINE" done . $BUILDDIR/setup-environment >/dev/null 2>&1 fi unset SETUP_ENV_MACHINE unset load_lconf_snippet unset configured_layers fi unset layerdir setup_flex_arg test $flex_setup_ret -eq 0 fi