#!/bin/bash
#
# Copyright (C) 2019-Present A-Team Digital Solutions
#

#SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
#DEVICE_CONFIG="$PWD/configs/${DEVICE_NAME}.conf"
#ROM_CONFIG="$PWD/configs/rom.conf"

#if [ ! -f "$DEVICE_CONFIG" ]; then
#    echo "Device Config Not Found: $DEVICE_CONFIG"
#    exit 1
#fi
#if [ ! -f "$ROM_CONFIG" ]; then
#    echo "Rom Config Not Found: $ROM_CONFIG"
#    exit 1
#fi
#source "$DEVICE_CONFIG"
#source "$ROM_CONFIG"

#DEVICE_MODEL="$DEVICE_MODEL_NUMBER"

bash $PWD/scripts/clean.sh

#cd "$ROM_PATH" || exit 1

clear

# Used For Testing variable additions
#env | sort | grep -E 'DEVICE|ROM|ANDROID|JOB|CCACHE'

echo 
echo "================================"
echo "ROM Build Settings ..."
echo 
echo "Device: $DEVICE_DISPLAY_NAME"
echo "Device Codename: $DEVICE_DISPLAY_CODENAME"
echo "Device Model: $DEVICE_MODEL"
echo "Rom: $ROM_DISPLAY_NAME"
echo "Android: $ANDROID_VERSION"
echo "Build Jobs: $BUILD_JOBS"
echo "Ccache: $USE_CCACHE"
echo "Build Variant: ${BUILD_VARIANT^}"
echo "Gapps Variant: $GAPPS_VARIANT"
echo "Installer Variant: $INSTALLER_VARIANT"
echo "Pre-Build Clean Variant: $CLEAN_VARIANT"
echo "================================"
echo 
echo 
sleep 5
echo "ROM Build Starting ..."
echo 
echo
# Source Build Env
source build/envsetup.sh
# Export Build Variables
export LC_ALL=C
export SELINUX_IGNORE_NEVERALLOWS=true
# Lunch
lunch ${ROM_BUILD_NAME}_${DEVICE_NAME}-${ROM_TARGET_RELEASE}-${BUILD_VARIANT}
# Build
$ROM_BUILD_COMMAND
#m bacon -j$JOBS


