# Common configuration for StarlingX builder

[[ -z "$_BUILDRC" ]] || return 0
declare -r -g _BUILDRC=1

# Find the other rc files
BUILDRC_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd)

# Allow local overrides of env variables
if [[ -f $BUILDRC_DIR/localrc ]]; then
    source $BUILDRC_DIR/localrc
fi

# Source repo base - Intel GitHub
SOURCE_HOST=${SOURCE_HOST:-git.openstack.org}
SOURCE_PORT=${SOURCE_PORT:-}
SOURCE_PROJECT=${SOURCE_PROJECT:-openstack}
SOURCE_REMOTE_URI=${SOURCE_REMOTE_URI:-git@${SOURCE_HOST}:${SOURCE_PROJECT}}

# Host-side prefix
if [[ -n $container && "$container" == "docker" ]]; then
    # We are running inside a docker container, do not give HOST_PATH a value
    HOST_PREFIX=
else
    # Host-side path for user-local /localdisk assumes that all user workspaces are
    # in the same directory structure.  Override this in localrc if that is
    # not the case.
    HOST_PREFIX=${HOST_PREFIX:-${HOME}/starlingx}
fi

# Basic build environment configuration

# Real (outside the container) username
export USER=${USER:-$(id -un)}

# Local mirror location
HOST_MIRROR_DIR=${HOST_MIRROR_DIR:-${HOME}/starlingx/mirror}


# The root of an individual build workspace

# GUEST_LOCALDISK is used for the docker run command mapping; don't change this
# until the WRS tooling is gone, it is hard-coded in many places
# We remove a leading '/' as having more than one breaks certain bits of the build
GUEST_LOCALDISK=${LOCALDISK:-localdisk}
GUEST_LOCALDISK=${GUEST_LOCALDISK%/}

# In the docker run command this will be correct for the host side of the mapping
LOCALDISK=${HOST_PREFIX}/${GUEST_LOCALDISK}


# Release Variable
export MY_RELEASE=${MY_RELEASE:-3.0}

# Default branch to build
export BRANCH=${BRANCH:-intel_r0}

# avoid calling your project 'build' it will break some SRPMs
export PROJECT=${PROJECT:-test}

# These are used in the Dockerfile, not sure where else
export MYUNAME=${MYUNAME:-builder}
export MYPROJECTNAME=${PROJECT:-frog1}

export SRC_BUILD_ENVIRONMENT=${SRC_BUILD_ENVIRONMENT:-$MY_RELEASE}

# All of the below are dependent on variables defined earlier, right now
# we are not going to support directly setting them in localrc
export MY_BUILD_ENVIRONMENT=$MYUNAME-$PROJECT-$SRC_BUILD_ENVIRONMENT
export MY_BUILD_ENVIRONMENT_FILE=${MY_BUILD_ENVIRONMENT}.cfg
export MY_BUILD_ENVIRONMENT_FILE_STD=${MY_BUILD_ENVIRONMENT}-std.cfg
export MY_BUILD_ENVIRONMENT_FILE_RT=${MY_BUILD_ENVIRONMENT}-rt.cfg
export MY_BUILD_DIR=${LOCALDISK}/loadbuild/$MYUNAME/$PROJECT
export MY_WORKSPACE=$MY_BUILD_DIR
export MY_LOCAL_DISK=${LOCALDISK}/designer/$MYUNAME
export MY_REPO_ROOT_DIR=$MY_LOCAL_DISK/$PROJECT
export MY_REPO=$MY_REPO_ROOT_DIR/cgcs-root
export MY_SRC_RPM_BUILD_DIR=$MY_BUILD_DIR/rpmbuild
export MY_BUILD_CFG=$MY_WORKSPACE/$MY_BUILD_ENVIRONMENT_FILE
export MY_BUILD_CFG_STD=$MY_WORKSPACE/std/${MY_BUILD_ENVIRONMENT_FILE_STD}
export MY_BUILD_CFG_RT=${MY_WORKSPACE}/rt/${MY_BUILD_ENVIRONMENT_FILE_RT}
export MY_MOCK_ROOT=$MY_WORKSPACE/mock/root
export MY_DEBUG_BUILD_CFG_STD=${MY_WORKSPACE}/std/configs/${MY_BUILD_ENVIRONMENT}-std/${MY_BUILD_ENVIRONMENT}-std.b0.cfg
export MY_DEBUG_BUILD_CFG_RT=${MY_WORKSPACE}/std/configs/${MY_BUILD_ENVIRONMENT}-std/${MY_BUILD_ENVIRONMENT}-rt.b0.cfg
export LAYER=$LAYER
export STX_CONFIG_DIR="$STX_CONFIG_DIR"