#!/bin/sh

__BITBAKE_LAST_LINE=0

# Emit a useful diagnostic if something fails:
bb_sh_exit_handler() {
    ret=$?
    if [ "$ret" != 0 ]; then
        echo "WARNING: exit code $ret from a shell command."
    fi
    exit $ret
}

bb_bash_exit_handler() {
    ret=$?
    { set +x; } > /dev/null
    trap "" DEBUG
    if [ "$ret" != 0 ]; then
        echo "WARNING: ${BASH_SOURCE[0]}:${__BITBAKE_LAST_LINE} exit $ret from '$1'"

        echo "WARNING: Backtrace (BB generated script): "
        for i in $(seq 1 $((${#FUNCNAME[@]} - 1))); do
            if [ "$i" -eq 1 ]; then
                echo -e "	#$((i)): ${FUNCNAME[$i]}, ${BASH_SOURCE[$((i-1))]}, line ${__BITBAKE_LAST_LINE}"
            else
                echo -e "	#$((i)): ${FUNCNAME[$i]}, ${BASH_SOURCE[$((i-1))]}, line ${BASH_LINENO[$((i-1))]}"
            fi
        done
    fi
    exit $ret
}

bb_bash_debug_handler() {
    local line=${BASH_LINENO[0]}
    # For some reason the DEBUG trap trips with lineno=1 when scripts exit; ignore it
    if [ "$line" -eq 1 ]; then
        return
    fi

    # Track the line number of commands as they execute. This is so we can have access to the failing line number
    # in the EXIT trap. See http://gnu-bash.2382.n7.nabble.com/trap-echo-quot-trap-exit-on-LINENO-quot-EXIT-gt-wrong-linenumber-td3666.html
    if [ "${FUNCNAME[1]}" != "bb_bash_exit_handler" ]; then
        __BITBAKE_LAST_LINE=$line
    fi
}

case $BASH_VERSION in
"") trap 'bb_sh_exit_handler' 0
    set -e
    ;;
*)  trap 'bb_bash_exit_handler "$BASH_COMMAND"' 0
    trap '{ bb_bash_debug_handler; } 2>/dev/null' DEBUG
    set -e
    shopt -s extdebug
    ;;
esac
export AR="ar"
export AS="as "
export BUILD_AR="ar"
export BUILD_AS="as "
export BUILD_CC="gcc "
export BUILD_CCLD="gcc "
export BUILD_CFLAGS="-isystem/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/include -O2 -pipe"
export BUILD_CPP="gcc  -E"
export BUILD_CPPFLAGS="-isystem/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/include"
export BUILD_CXX="g++ "
export BUILD_CXXFLAGS="-isystem/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/include -O2 -pipe"
export BUILD_FC="gfortran "
export BUILD_LD="ld "
export BUILD_LDFLAGS="-L/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib                         -L/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/lib                         -Wl,--enable-new-dtags                         -Wl,-rpath-link,/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib                         -Wl,-rpath-link,/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/lib                         -Wl,-rpath,/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib                         -Wl,-rpath,/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/lib                         -Wl,-O1 -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=/home/sim/yocto/scarthgap/build/tmp/sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2 -pthread"
export BUILD_NM="nm"
export BUILD_RANLIB="ranlib -D"
export BUILD_STRIP="strip"
export CC="gcc "
export CCLD="gcc "
export CCSHARED="-fPIC -DPIC"
export CFLAGS="-isystem/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/include -O2 -pipe"
export CONFIG_SITE="/home/sim/yocto/scarthgap/poky/meta/site/native"
export CPP="gcc  -E"
export CPPFLAGS="-isystem/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/include"
export CXX="g++ "
export CXXFLAGS="-isystem/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/include -O2 -pipe"
export FC="gfortran "
export GIT_CEILING_DIRECTORIES="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8:/home/sim/yocto/scarthgap/build/tmp"
export HOME="/home/sim"
export LC_ALL="en_US.UTF-8"
export LD="ld "
export LDCXXSHARED="g++  -shared"
export LDFLAGS="-L/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib                         -L/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/lib                         -Wl,--enable-new-dtags                         -Wl,-rpath-link,/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib                         -Wl,-rpath-link,/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/lib                         -Wl,-rpath,/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib                         -Wl,-rpath,/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/lib                         -Wl,-O1 -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=/home/sim/yocto/scarthgap/build/tmp/sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2 -pthread"
export LDSHARED="gcc  -shared"
export LINKFORSHARED="-fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security -Xlinker -export-dynamic"
export LOGNAME="sim"
export MAKE="make"
export NM="nm"
export OBJCOPY="objcopy"
export OBJDUMP="objdump"
export OMP_NUM_THREADS="8"
export PATH="/home/sim/yocto/scarthgap/poky/scripts/native-intercept:/home/sim/yocto/scarthgap/build/tmp/sysroots-uninative/x86_64-linux/usr/bin:/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/bin/python3-native:/home/sim/yocto/scarthgap/poky/scripts:/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/bin/x86_64-linux:/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/bin:/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/sbin:/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/bin:/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/sbin:/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/bin:/home/sim/yocto/scarthgap/poky/bitbake/bin:/home/sim/yocto/scarthgap/build/tmp/hosttools"
export PERL_HASH_SEED="0"
export PKG_CONFIG_DIR="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib/pkgconfig"
export PKG_CONFIG_DISABLE_UNINSTALLED="yes"
export PKG_CONFIG_LIBDIR="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib/pkgconfig"
export PKG_CONFIG_PATH="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib/pkgconfig:/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/share/pkgconfig"
export PKG_CONFIG_SYSROOT_DIR=""
unset PKG_CONFIG_SYSTEM_INCLUDE_PATH
unset PKG_CONFIG_SYSTEM_LIBRARY_PATH
export PSEUDO_DISABLED="1"
export PSEUDO_UNLOAD="1"
export PYTHON="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/bin/python3-native/python3"
export PYTHONHASHSEED="0"
export PYTHONNOUSERSITE="1"
export PYTHON_INCLUDE_DIR="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/include/python3.12"
export PYTHON_LIBRARY="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib/libpython3.12.so"
export RANLIB="ranlib -D"
export READELF="readelf"
unset SHELL
export SOURCE_DATE_EPOCH="1703660414"
export STAGING_INCDIR="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/include"
export STAGING_LIBDIR="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib"
export STRINGS="strings"
export STRIP="strip"
export TZ="UTC"
export USER="sim"
export base_bindir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/bin"
export base_libdir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/lib"
export base_prefix="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native"
export base_sbindir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/sbin"
export bindir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/bin"
export datadir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/share"
export docdir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/share/doc"
export exec_prefix="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr"
export includedir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/include"
export infodir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/share/info"
export libdir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib"
export libexecdir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/libexec"
export localstatedir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/var"
export lt_cv_sys_lib_dlsearch_path_spec="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/lib /lib /lib64 /usr/lib /usr/lib64"
export mandir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/share/man"
export nonarch_base_libdir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/lib"
export nonarch_libdir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib"
export prefix="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr"
export sbindir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/sbin"
export servicedir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/srv"
export sharedstatedir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/com"
export sysconfdir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/etc"
export systemd_system_unitdir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/lib/systemd/system"
export systemd_unitdir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/lib/systemd"
export systemd_user_unitdir="/home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/recipe-sysroot-native/usr/lib/systemd/user"

# line: 35, file: /home/sim/yocto/scarthgap/poky/meta/classes/rm_work.bbclass
do_rm_work() {
    # Force using the HOSTTOOLS 'rm' - otherwise the SYSROOT_NATIVE 'rm' can be selected depending on PATH
    # Avoids race-condition accessing 'rm' when deleting WORKDIR folders at the end of this function
    RM_BIN="$(PATH=/home/sim/yocto/scarthgap/build/tmp/hosttools command -v rm)"
    if [ -z "${RM_BIN}" ]; then
        bbfatal "Binary 'rm' not found in HOSTTOOLS_DIR, cannot remove WORKDIR data."
    fi

    # If the recipe name is in the RM_WORK_EXCLUDE, skip the recipe.
    for p in ${RM_WORK_EXCLUDE}; do
        if [ "$p" = "python3-pdm-backend-native" ]; then
            bbnote "rm_work: Skipping python3-pdm-backend-native since it is in RM_WORK_EXCLUDE"
            exit 0
        fi
    done

    # Need to add pseudo back or subsqeuent work in this workdir
    # might fail since setscene may not rerun to recreate it
    mkdir -p /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/pseudo/

    excludes='temp'

    # Change normal stamps into setscene stamps as they better reflect the
    # fact WORKDIR is now empty
    # Also leave noexec stamps since setscene stamps don't cover them
    STAMPDIR=`dirname /home/sim/yocto/scarthgap/build/tmp/stamps/x86_64-linux/python3-pdm-backend-native/2.1.8`
    if test -d $STAMPDIR; then
        cd $STAMPDIR
        for i in `basename /home/sim/yocto/scarthgap/build/tmp/stamps/x86_64-linux/python3-pdm-backend-native/2.1.8`*
        do
            case $i in
            *sigdata*|*sigbasedata*)
                # Save/skip anything that looks like a signature data file.
                ;;
            *do_image_complete_setscene*|*do_image_qa_setscene*)
                # Ensure we don't 'stack' setscene extensions to these stamps with the sections below
                ;;
            *do_image_complete*)
                # Promote do_image_complete stamps to setscene versions (ahead of *do_image* below)
                mv $i `echo $i | sed -e "s#do_image_complete#do_image_complete_setscene#"`
                ;;
            *do_image_qa*)
                # Promote do_image_qa stamps to setscene versions (ahead of *do_image* below)
                mv $i `echo $i | sed -e "s#do_image_qa#do_image_qa_setscene#"`
                ;;
            *do_package_write*|*do_rootfs*|*do_image*|*do_bootimg*|*do_write_qemuboot_conf*|*do_build*)
                ;;
            *do_addto_recipe_sysroot*)
                # Preserve recipe-sysroot-native if do_addto_recipe_sysroot has been used
                excludes="$excludes recipe-sysroot-native"
                ;;
            *do_package|*do_package.*|*do_package_setscene.*)
                # We remove do_package entirely, including any
                # sstate version since otherwise we'd need to leave 'plaindirs' around
                # such as 'packages' and 'packages-split' and these can be large. No end
                # of chain tasks depend directly on do_package anymore.
                "${RM_BIN}" -f -- $i;
                ;;
            *_setscene*)
                # Skip stamps which are already setscene versions
                ;;
            *)
                # For everything else: if suitable, promote the stamp to a setscene
                # version, otherwise remove it
                for j in do_create_runtime_spdx do_create_spdx do_deploy_source_date_epoch do_package do_package_qa do_package_write_deb do_packagedata do_populate_lic do_populate_sysroot do_recipe_qa do_shared_workdir
                do
                    case $i in
                    *$j|*$j.*)
                        mv $i `echo $i | sed -e "s#${j}#${j}_setscene#"`
                        break
                        ;;
                    esac
                done
                "${RM_BIN}" -f -- $i
            esac
        done
    fi

    cd /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8
    for dir in *
    do
        # Retain only logs and other files in temp, safely ignore
        # failures of removing pseudo folers on NFS2/3 server.
        if [ $dir = 'pseudo' ]; then
            "${RM_BIN}" -rf -- $dir 2> /dev/null || true
        elif ! echo "$excludes" | grep -q -w "$dir"; then
            "${RM_BIN}" -rf -- $dir
        fi
    done
}

# line: 60, file: /home/sim/yocto/scarthgap/poky/meta/classes-global/logging.bbclass
bbfatal() {
	if [ -p /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/temp/fifo.3047136 ] ; then
		printf "%b\0" "bbfatal $*" > /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/temp/fifo.3047136
	else
		echo "ERROR: $*"
	fi
	exit 1
}

# line: 27, file: /home/sim/yocto/scarthgap/poky/meta/classes-global/logging.bbclass
bbnote() {
	if [ -p /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/temp/fifo.3047136 ] ; then
		printf "%b\0" "bbnote $*" > /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python3-pdm-backend-native/2.1.8/temp/fifo.3047136
	else
		echo "NOTE: $*"
	fi
}

do_rm_work

# cleanup
ret=$?
trap '' 0
exit $ret
