#!/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
clear
source "$DEVICE_CONFIG"
source "$ROM_CONFIG"

DEVICE_MODEL="$DEVICE_MODEL_NUMBER"

cd "$ROM_PATH" || exit 1

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

echo 
echo "================================"
echo "ROM Clean Settings ..."
echo 
echo "Pre-Build Clean Variant: ${CLEAN_VARIANT^}"
echo "================================"
echo 
echo 
sleep 5
echo "Pre-Build Rom Clean Starting ..."
echo 
echo
# Source Build Env
source build/envsetup.sh
# Lunch
lunch ${ROM_BUILD_NAME}_${DEVICE_NAME}-${ROM_TARGET_RELEASE}-${BUILD_VARIANT}
# Clean
if [ "$CLEAN_VARIANT" = "full" ]; then
    $M clean
elif [ "$CLEAN_VARIANT" = "lite" ]; then
    $M installclean
fi


