apply from: 'config.gradle'

buildscript {
    apply from: 'config.gradle'

    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:$versions.gradlePluginVersion"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

def outputDir = "build/outputs"

task clean(type: Delete) {
    dependsOn(":OVRMobile:clean")

    delete(rootProject.buildDir)

    // Delete the contents of the outputs directory
    delete(outputDir)
}

/**
 * Generate the plugin binaries.
 */
task generatePluginBinary(type: Copy) {
    dependsOn(":OVRMobile:assembleDebug")
    dependsOn(":OVRMobile:assembleRelease")
    from("plugin/build/outputs/aar")
    into("$outputDir/pluginBin")
}

/**
 * Generate the plugin native shared libraries.
 * This is mostly to be used by maintainers to update the https://github.com/GodotVR/godot-oculus-mobile-asset repo.
 */
task generateSharedLibs(type: Copy) {
    dependsOn(":OVRMobile:externalNativeBuildFullDebug")
    dependsOn(":OVRMobile:externalNativeBuildFullRelease")

    // Specify the base directory. All following 'into' targets will be relative
    // to this directory.
    into("$outputDir/sharedLibs")

    // Copy the generated debug shared libs into the outputs directory
    from("plugin/build/intermediates/cmake/fullDebug/obj") {
        into("debug")
    }

    // Copy the generated release shared libs into the outputs directory
    from("plugin/build/intermediates/cmake/fullRelease/obj") {
        into("release")
    }
}
