/*
 * 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.SoftwareType
import androidx.build.AndroidXConfig
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("AndroidXPlugin")
    id("com.android.library")
    id("org.jetbrains.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 = SoftwareType.PUBLISHED_LIBRARY
    inceptionYear = "2018"
    description = "Android Benchmark - Common"
    legacyDisableKotlinStrictApiMode = true
    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",
                "-opt-in=androidx.benchmark.traceprocessor.ExperimentalInsightApi",
        ]
    }
}

