#!/usr/bin/env bash
# CI entry: native codecs (all ABIs) + Gradle debug APK + unit tests.
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"

bash "$ROOT/scripts/ensure-gradle-wrapper.sh"
export ANDROIDCAST_ROOT="$ROOT"
export ANDROIDCAST_CCACHE="${ANDROIDCAST_CCACHE:-1}"
export ANDROIDCAST_USE_DISTCC="${ANDROIDCAST_USE_DISTCC:-0}"

# shellcheck source=android-ndk.sh
source "$ROOT/scripts/android-ndk.sh"
export ANDROID_NDK_HOME="$(androidcast_find_ndk_root "$ROOT")"
export ANDROID_NDK_ROOT="$ANDROID_NDK_HOME"

echo "==> Initializing third-party git submodules"
bash "$ROOT/scripts/init-third-party-submodules.sh"

ABIS="${ANDROIDCAST_CI_ABIS:-armeabi-v7a arm64-v8a x86_64}"
echo "==> Building libvpx for: $ABIS"
rm -rf "$ROOT/build/native"
mkdir -p "$ROOT/build/native"
for abi in $ABIS; do
  ./scripts/build-native-codecs.sh "$abi"
done

echo "==> Gradle :tunnel + assembleDebug + unit tests"
./gradlew --no-daemon clean :tunnel:assembleDebug assembleDebug testDebugUnitTest

echo "==> Done: $ROOT/app/build/outputs/apk/debug/app-debug.apk"
