/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * This file was created using the `create_project.py` script located in the
 * `<AndroidX root>/development/project-creator` directory.
 *
 * Please use that script when creating a new project, rather than copying an existing project and
 * modifying its settings.
 */

import androidx.build.KotlinTarget
import androidx.build.LibraryType
import androidx.build.AndroidXConfig
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("AndroidXPlugin")
    id("com.android.library")
    id("kotlin-android")
}

android {
    defaultConfig {
        minSdk = 23

        // We don't care about perf from these correctness tests, so suppress
        // anything that may otherwise block these tests
        testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] =
                "CODE-COVERAGE,DEBUGGABLE,EMULATOR,LOW-BATTERY,UNLOCKED"
    }
    sourceSets {
        main.assets.srcDirs += new File(
                AndroidXConfig.getPrebuiltsRoot(project),
                "androidx/traceprocessor/trace_processor_shell"
        )
        androidTest.assets.srcDirs += new File(
                AndroidXConfig.getPrebuiltsRoot(project),
                "androidx/traceprocessor/testdata"
        )
        // PerfettoHandshake supports both AAR and APK as libtracing_perfetto.so sources:
        // - AAR is used when e.g. tooling downloads tracing-perfetto-binary AAR files from Maven
        // - APK is when an APK that contains tracing binaries is used
        //
        // Adding the AAR as a test asset below allows us to test the AAR scenario
        androidTest.assets.srcDirs += new File(
                AndroidXConfig.getPrebuiltsRoot(project),
                "androidx/internal/androidx/tracing/tracing-perfetto-binary/" +
                        "${androidx.LibraryVersions.TRACING_PERFETTO}"
        )
    }

    namespace = "androidx.benchmark.macro"
}

dependencies {
    api(libs.jspecify)
    api(project(":benchmark:benchmark-common"))
    api(libs.junit)
    api(libs.kotlinStdlib)
    api("androidx.annotation:annotation:1.8.1")

    implementation("androidx.core:core:1.9.0")
    implementation("androidx.profileinstaller:profileinstaller:1.4.1")
    implementation("androidx.tracing:tracing-ktx:1.1.0")
    implementation("androidx.tracing:tracing-perfetto:1.0.0")
    implementation("androidx.tracing:tracing-perfetto-binary:1.0.0")
    implementation("androidx.tracing:tracing-perfetto-handshake:1.0.0")
    implementation("androidx.test:core:1.5.0")
    implementation(libs.testUiautomator)
    implementation(libs.wireRuntime)
    implementation(libs.testExtJunit)

    androidTestImplementation(project(":benchmark:benchmark-junit4"))
    androidTestImplementation(project(":internal-testutils-ktx"))
    androidTestImplementation("androidx.activity:activity-ktx:1.3.1")
    androidTestImplementation(project(":tracing:tracing-perfetto"))
    androidTestImplementation(libs.testExtJunit)
    androidTestImplementation(libs.testRules)
    androidTestImplementation(libs.testRunner)
    androidTestImplementation(libs.kotlinTest)
    androidTestImplementation(libs.truth)
}

androidx {
    name = "Benchmark - Macrobenchmark"
    type = LibraryType.PUBLISHED_LIBRARY
    inceptionYear = "2020"
    description = "Android Benchmark - Macrobenchmark"
    legacyDisableKotlinStrictApiMode = true
    deviceTests {
        enableAlsoRunningOnPhysicalDevices = true
    }
}

tasks.withType(KotlinCompile).configureEach {
    kotlinOptions {
        // Enable using experimental APIs from within same version group
        freeCompilerArgs += [
                "-opt-in=androidx.benchmark.ExperimentalBenchmarkConfigApi",
                "-opt-in=androidx.benchmark.macro.ExperimentalMetricApi",
                "-opt-in=androidx.benchmark.perfetto.ExperimentalPerfettoCaptureApi",
                "-opt-in=androidx.benchmark.traceprocessor.ExperimentalTraceProcessorApi",
        ]
    }
}

// Define a task dependency so the app is installed before we run macro benchmarks.
afterEvaluate {
    // `:benchmark:integration-tests:macrobenchmark-target:installRelease` is not in the compose
    // build, so it may fail the compose build job.
    def installTask = tasks.findByPath(
            ":benchmark:integration-tests:macrobenchmark-target:installRelease")
    if (installTask != null) {
        tasks.getByPath(":benchmark:benchmark-macro:connectedReleaseAndroidTest")
                .dependsOn(installTask)
    }
}

androidx {
    deviceTests {
        targetAppProject = project(":benchmark:integration-tests:macrobenchmark-target")
        targetAppVariant = "release"
    }
    kotlinTarget = KotlinTarget.KOTLIN_1_9
}
