/*
 * Copyright (C) 2022 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.LibraryType
import androidx.build.AndroidXConfig

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

/**
 * When `reusePrebuiltsAar` is set to `true` reuses the AAR file from the ../../prebuilts directory.
 * When `reusePrebuiltsAar` is set to `false` builds the project from scratch (from CXX) files.
 *
 * This was introduced to address the following issues that occurred when always building
 * the project from scratch:
 * - no stripping of debug symbols in 'test' configurations resulting in very large
 *   files (200+ MB total) being added to e.g. each Benchmark project (b/228627720).
 * - no caching due to the way CMake builds are currently handled in Android Gradle Plugin
 *   resulting in always building the CXX files from scratch, which is very slow due to the
 *   size of Perfetto SDK (b/230790969).
 *
 *  Additionally, using the prebuilts reference directly (instead of the project reference)
 *  resulted in the project not getting published to Maven or Snapshot Builds (androidx.dev).
 */

def reusePrebuiltsAar = Boolean.parseBoolean(
        System.getProperty("TRACING_PERFETTO_REUSE_PREBUILTS_AAR", "true")
)
def prebuiltsAarVersion = androidx.LibraryVersions.TRACING_PERFETTO
def unzippedPrebuiltsAarDir = "$buildDir/unzipped-aar"

if (reusePrebuiltsAar) {
    def unzipTask = tasks.register("unzipPrebuiltsAarDir", Copy) {
        def zipFile = AndroidXConfig.getPrebuiltsRoot(project).toPath().resolve(
                "androidx/internal/androidx/tracing/tracing-perfetto-binary/$prebuiltsAarVersion/" +
                        "tracing-perfetto-binary-${prebuiltsAarVersion}.aar"
        )
        from zipTree(zipFile)
        into file(unzippedPrebuiltsAarDir)
    }

    tasks.findByName("preBuild").dependsOn(unzipTask)
}

android {
    if (reusePrebuiltsAar) {
        sourceSets {
            main.jniLibs.srcDirs += new File(unzippedPrebuiltsAarDir, "jni")
        }
    } else { // build .so files from scratch
        externalNativeBuild {
            cmake {
                path "src/main/cpp/CMakeLists.txt"
                version = libs.versions.cmake.get()
            }
        }
    }
    namespace = "androidx.tracing.perfetto.binary"
}

dependencies {
    androidTestImplementation(libs.kotlinStdlib)
    androidTestImplementation(libs.testExtJunit)
    androidTestImplementation(libs.testRunner)
    androidTestImplementation(project(":benchmark:benchmark-common")) // for supported ABI checks
}

androidx {
    name = "Tracing Perfetto Binary"
    type = LibraryType.PUBLISHED_LIBRARY
    inceptionYear = "2022"
    description = "Provides native binaries required by AndroidX Tracing: Perfetto SDK " +
        "and is not intended to be used outside of that context."
    doNotDocumentReason = "No public API"
    deviceTests {
        enableAlsoRunningOnPhysicalDevices = true
    }
}
