/*
 * Copyright (C) 2018 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")
    id("com.squareup.wire")
    id("com.google.devtools.ksp")
}

android {
    sourceSets {
        main.assets.srcDirs += new File(
                AndroidXConfig.getPrebuiltsRoot(project),
                "androidx/traceprocessor/tracebox"
        )
        androidTest.assets.srcDirs += new File(
                AndroidXConfig.getPrebuiltsRoot(project),
                "androidx/traceprocessor/testdata"
        )
    }
    namespace = "androidx.benchmark"
    defaultConfig {
        externalNativeBuild {
            cmake {
                cppFlags ''
            }
        }
    }
    externalNativeBuild {
        cmake {
            path file('src/main/cpp/CMakeLists.txt')
            version = libs.versions.cmake.get()
        }
    }
}

wire {
    kotlin {}

    // prune unused config components which have deprecated fields
    prune 'perfetto.protos.TraceConfig.IncidentReportConfig'
    prune 'perfetto.protos.ProcessStatsConfig.Quirks'

    sourcePath {
        srcDir 'src/main/proto'
    }
}

dependencies {
    api(libs.jspecify)
    implementation(libs.kotlinStdlib)
    api("androidx.annotation:annotation:1.8.1")
    api("androidx.annotation:annotation-experimental:1.4.1")
    api(project(":benchmark:benchmark-traceprocessor"))
    implementation("androidx.tracing:tracing-ktx:1.0.0")
    implementation("androidx.tracing:tracing-perfetto-handshake:1.0.0")
    implementation("androidx.test:monitor:1.6.1")
    implementation(libs.wireRuntime)
    implementation(libs.moshi)
    implementation(libs.kotlinCoroutinesAndroid)
    ksp(libs.moshiCodeGen)

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

androidx {
    name = "Benchmark - Common"
    type = LibraryType.PUBLISHED_LIBRARY
    inceptionYear = "2018"
    description = "Android Benchmark - Common"
    legacyDisableKotlinStrictApiMode = true
    kotlinTarget = KotlinTarget.KOTLIN_1_9
    deviceTests {
        enableAlsoRunningOnPhysicalDevices = true
    }
    samples(project(":benchmark:benchmark-samples"))
}

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