All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sentry.android.gradle.tasks.SentryUploadNativeSymbolsTask.kt Maven / Gradle / Ivy

There is a newer version: 4.11.0
Show newest version
package io.sentry.android.gradle.tasks

import io.sentry.android.gradle.SentryPropertiesFileProvider
import io.sentry.android.gradle.SentryTasksProvider.capitalized
import io.sentry.android.gradle.extensions.SentryPluginExtension
import io.sentry.android.gradle.telemetry.SentryTelemetryService
import io.sentry.android.gradle.telemetry.withSentryTelemetry
import io.sentry.android.gradle.util.asSentryCliExec
import io.sentry.android.gradle.util.hookWithAssembleTasks
import io.sentry.android.gradle.util.info
import io.sentry.gradle.common.SentryVariant
import java.io.File
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskProvider

abstract class SentryUploadNativeSymbolsTask : SentryCliExecTask() {

    init {
        description = "Uploads native symbols to Sentry"
    }

    @get:Input
    abstract val autoUploadNativeSymbol: Property

    @get:Input
    abstract val includeNativeSources: Property

    @get:Internal
    abstract val variantName: Property

    override fun getArguments(args: MutableList) {
        args.add("debug-files")
        args.add("upload")

        if (!autoUploadNativeSymbol.get()) {
            args.add("--no-upload")
        }

        val sep = File.separator

        // eg absoluteProjectFolderPath/build/intermediates/merged_native_libs/{variantName}
        // where {variantName} could be debug/release...
        args.add(
            File(
                project.buildDir,
                "intermediates${sep}merged_native_libs${sep}${variantName.get()}"
            ).absolutePath
        )

        // Only include sources if includeNativeSources is enabled, as this is opt-in feature
        if (includeNativeSources.get()) {
            args.add("--include-sources")
        }
    }

    companion object {
        fun register(
            project: Project,
            extension: SentryPluginExtension,
            sentryTelemetryProvider: Provider,
            variantName: String,
            debug: Property,
            cliExecutable: Provider,
            sentryProperties: String?,
            sentryOrg: Provider,
            sentryProject: Provider,
            sentryAuthToken: Property,
            sentryUrl: Property,
            includeNativeSources: Property,
            autoUploadNativeSymbols: Property,
            taskSuffix: String = "",
        ): TaskProvider {
            val uploadSentryNativeSymbolsTask = project.tasks.register(
                "uploadSentryNativeSymbolsFor$taskSuffix",
                SentryUploadNativeSymbolsTask::class.java
            ) { task ->
                task.workingDir(project.rootDir)
                task.debug.set(debug)
                task.autoUploadNativeSymbol.set(autoUploadNativeSymbols)
                task.cliExecutable.set(cliExecutable)
                task.sentryProperties.set(sentryProperties?.let { file -> project.file(file) })
                task.includeNativeSources.set(includeNativeSources)
                task.variantName.set(variantName)
                task.sentryOrganization.set(sentryOrg)
                task.sentryProject.set(sentryProject)
                task.sentryAuthToken.set(sentryAuthToken)
                task.sentryUrl.set(sentryUrl)
                task.sentryTelemetryService.set(sentryTelemetryProvider)
                task.asSentryCliExec()
                task.withSentryTelemetry(extension, sentryTelemetryProvider)
            }
            return uploadSentryNativeSymbolsTask
        }
    }
}

fun SentryVariant.configureNativeSymbolsTask(
    project: Project,
    extension: SentryPluginExtension,
    sentryTelemetryProvider: Provider,
    cliExecutable: Provider,
    sentryOrg: String?,
    sentryProject: String?
) {
    if (!isDebuggable && extension.uploadNativeSymbols.get()) {
        val sentryProps = SentryPropertiesFileProvider.getPropertiesFilePath(project, this)
        // Setup the task to upload native symbols task after the assembling task
        val uploadSentryNativeSymbolsTask = SentryUploadNativeSymbolsTask.register(
            project = project,
            extension = extension,
            sentryTelemetryProvider = sentryTelemetryProvider,
            variantName = name,
            debug = extension.debug,
            cliExecutable = cliExecutable,
            sentryProperties = sentryProps,
            autoUploadNativeSymbols = extension.autoUploadNativeSymbols,
            includeNativeSources = extension.includeNativeSources,
            sentryOrg = sentryOrg?.let { project.provider { it } } ?: extension.org,
            sentryProject = sentryProject?.let { project.provider { it } }
                ?: extension.projectName,
            sentryAuthToken = extension.authToken,
            sentryUrl = extension.url,
            taskSuffix = name.capitalized
        )
        uploadSentryNativeSymbolsTask.hookWithAssembleTasks(project, this)
    } else {
        project.logger.info { "uploadSentryNativeSymbols won't be executed" }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy