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