/*
 * 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 org.jetbrains.kotlin.gradle.tasks.KotlinCompile

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

android {
    defaultConfig {
        minSdk = 23

        // The package name is passed to the app as an instrumentation runner argument.
        // Set default target package at runtime. This could also be set by baseline profile
        // gradle plugin, but that's not used here.
        testInstrumentationRunnerArguments["androidx.benchmark.targetPackageName"] =
                "androidx.benchmark.integration.macrobenchmark.target"

        // 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"
        // these extra payload values are used in test.
        testInstrumentationRunnerArguments["androidx.benchmark.output.payload.simpleValue"] =
                "simple_value"
    }
    namespace = "androidx.benchmark.macro.junit4"
}

dependencies {
    api(libs.junit)
    api(libs.kotlinStdlib)
    api("androidx.annotation:annotation:1.8.1")
    api(project(":benchmark:benchmark-macro"))
    api("androidx.test.uiautomator:uiautomator:2.3.0")
    implementation(project(":benchmark:benchmark-common"))
    implementation("androidx.test:rules:1.5.0")
    implementation("androidx.test:runner:1.5.2")

    androidTestImplementation(libs.testExtJunit)
    androidTestImplementation(libs.testRules)
    androidTestImplementation(libs.testRunner)
    androidTestImplementation(libs.kotlinTest)
    androidTestImplementation(libs.truth)
}

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",
        ]
    }
}

androidx {
    name = "Benchmark - Macrobenchmark JUnit4"
    type = LibraryType.PUBLISHED_LIBRARY
    inceptionYear = "2020"
    description = "Android Benchmark - Macrobenchmark JUnit4"
    legacyDisableKotlinStrictApiMode = true
    deviceTests {
        targetAppProject = project(":benchmark:integration-tests:macrobenchmark-target")
        targetAppVariant = "release"
    }
    kotlinTarget = KotlinTarget.KOTLIN_1_9
    samples(project(":benchmark:benchmark-samples"))
}
