Skip to content

Commit

Permalink
use source files as input for generating uuids and source bundle (#634)
Browse files Browse the repository at this point in the history
* use source files as input for generating uuids and source bundle

* Allow UploadSourceBundleTask to be considered up to date, use mapping file as trigger for ProguardUUID Task
  • Loading branch information
lbloder authored Feb 5, 2024
1 parent afa92e8 commit a4bd46d
Show file tree
Hide file tree
Showing 15 changed files with 505 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
- Fall back to `findTask` if `assembleProvider` of AndroidVariant is null when hooking source bundle and native symbols upload tasks ([#639](https://github.com/getsentry/sentry-android-gradle-plugin/pull/639))
- Hook source context tasks to also run after `install{Variant}` tasks ([#643](https://github.com/getsentry/sentry-android-gradle-plugin/pull/643))
- Do not run sentry-cli commands if telemetry is disabled ([#648](https://github.com/getsentry/sentry-android-gradle-plugin/pull/648))
- Proguard and source context tasks don't run on every build ([#634](https://github.com/getsentry/sentry-android-gradle-plugin/pull/634))
- Proguard UUID task now depends on the proguard mapping file. I.e. it will only run if the mapping file has changed
- Source context tasks now depend on source file changes, if there are no source changes, the tasks won't run

### Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import io.sentry.android.gradle.util.hookWithMinifyTasks
import io.sentry.android.gradle.util.info
import java.io.File
import org.gradle.api.Project
import org.gradle.api.file.Directory
import org.gradle.api.provider.Provider
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.TaskProvider
Expand Down Expand Up @@ -73,13 +74,26 @@ fun AndroidComponentsExtension<*, *, *>.configure(

variant.configureDependenciesTask(project, extension, sentryTelemetryProvider)

// TODO: do this only once, and all other tasks should be SentryVariant.configureSomething
val sentryVariant = if (isAGP74) AndroidVariant74(variant) else null

val additionalSourcesProvider = project.provider {
extension.additionalSourceDirsForSourceContext.getOrElse(emptySet())
.map { project.layout.projectDirectory.dir(it) }
}
val sourceFiles = sentryVariant?.sources(
project,
additionalSourcesProvider
)

val tasksGeneratingProperties =
mutableListOf<TaskProvider<out PropertiesFileOutputTask>>()
val sourceContextTasks = variant.configureSourceBundleTasks(
project,
extension,
sentryTelemetryProvider,
paths,
sourceFiles,
cliExecutable,
sentryOrg,
sentryProject
Expand All @@ -97,8 +111,6 @@ fun AndroidComponentsExtension<*, *, *>.configure(
)
generateProguardUuidTask?.let { tasksGeneratingProperties.add(it) }

// TODO: do this only once, and all other tasks should be SentryVariant.configureSomething
val sentryVariant = if (isAGP74) AndroidVariant74(variant) else null
sentryVariant?.configureNativeSymbolsTask(
project,
extension,
Expand Down Expand Up @@ -265,6 +277,7 @@ private fun Variant.configureSourceBundleTasks(
extension: SentryPluginExtension,
sentryTelemetryProvider: Provider<SentryTelemetryService>,
paths: OutputPaths,
sourceFiles: Provider<out Collection<Directory>>?,
cliExecutable: Provider<String>,
sentryOrg: String?,
sentryProject: String?
Expand All @@ -280,6 +293,7 @@ private fun Variant.configureSourceBundleTasks(
sentryTelemetryProvider,
variant,
paths,
sourceFiles,
cliExecutable,
sentryOrg,
sentryProject,
Expand Down Expand Up @@ -354,6 +368,7 @@ private fun Variant.configureProguardMappingsTasks(
project = project,
extension,
sentryTelemetryProvider,
proguardMappingFile = getMappingFileProvider(project, variant, dexguardEnabled),
taskSuffix = name.capitalized,
output = paths.proguardUuidDir
)
Expand Down
40 changes: 29 additions & 11 deletions plugin-build/src/main/kotlin/io/sentry/android/gradle/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import io.sentry.android.gradle.util.hookWithPackageTasks
import io.sentry.android.gradle.util.info
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.Directory
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
import org.gradle.internal.build.event.BuildEventListenerRegistryInternal
Expand Down Expand Up @@ -68,11 +69,32 @@ fun AppExtension.configure(
buildEvents
)

// TODO: do this only once, and all other tasks should be SentryVariant.configureSomething
val sentryVariant = if (isAGP74) null else AndroidVariant70(variant)
sentryVariant?.configureNativeSymbolsTask(
project,
extension,
sentryTelemetryProvider,
cliExecutable,
sentryOrg,
sentryProject
)

val additionalSourcesProvider = project.provider {
extension.additionalSourceDirsForSourceContext.getOrElse(emptySet())
.map { project.layout.projectDirectory.dir(it) }
}
val sourceFiles = sentryVariant?.sources(
project,
additionalSourcesProvider
)

val tasksGeneratingProperties = mutableListOf<TaskProvider<out PropertiesFileOutputTask>>()
val sourceContextTasks = variant.configureSourceBundleTasks(
project,
extension,
sentryTelemetryProvider,
sourceFiles,
cliExecutable,
sentryOrg,
sentryProject
Expand All @@ -97,17 +119,6 @@ fun AppExtension.configure(
)
generateProguardUuidTask?.let { tasksGeneratingProperties.add(it) }

// TODO: do this only once, and all other tasks should be SentryVariant.configureSomething
val sentryVariant = if (isAGP74) null else AndroidVariant70(variant)
sentryVariant?.configureNativeSymbolsTask(
project,
extension,
sentryTelemetryProvider,
cliExecutable,
sentryOrg,
sentryProject
)

variant.configureDebugMetaPropertiesTask(
project,
extension,
Expand Down Expand Up @@ -187,6 +198,7 @@ private fun ApplicationVariant.configureSourceBundleTasks(
project: Project,
extension: SentryPluginExtension,
sentryTelemetryProvider: Provider<SentryTelemetryService>,
sourceFiles: Provider<out Collection<Directory>>?,
cliExecutable: Provider<String>,
sentryOrg: String?,
sentryProject: String?
Expand All @@ -208,6 +220,7 @@ private fun ApplicationVariant.configureSourceBundleTasks(
sentryTelemetryProvider,
variant,
paths,
sourceFiles,
cliExecutable,
sentryOrg,
sentryProject,
Expand Down Expand Up @@ -289,6 +302,11 @@ private fun ApplicationVariant.configureProguardMappingsTasks(
extension,
sentryTelemetryProvider,
output = outputDir,
proguardMappingFile = SentryTasksProvider.getMappingFileProvider(
project,
variant,
dexguardEnabled
),
taskSuffix = name.capitalized
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ abstract class CollectSourcesTask : DirectoryOutputTask() {
project: Project,
extension: SentryPluginExtension,
sentryTelemetryProvider: Provider<SentryTelemetryService>?,
sourceDirs: Provider<out Collection<Directory>>,
sourceDirs: Provider<out Collection<Directory>>?,
output: Provider<Directory>,
includeSourceContext: Property<Boolean>,
taskSuffix: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ import io.sentry.android.gradle.util.info
import java.util.Properties
import java.util.UUID
import org.gradle.api.Project
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.Directory
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskProvider

abstract class GenerateBundleIdTask : PropertiesFileOutputTask() {

init {
outputs.upToDateWhen { false }
description = "Generates a unique build ID to be used " +
"when bundling sources for upload to Sentry"

Expand All @@ -33,6 +36,10 @@ abstract class GenerateBundleIdTask : PropertiesFileOutputTask() {
@get:Input
abstract val includeSourceContext: Property<Boolean>

@get:PathSensitive(PathSensitivity.RELATIVE)
@get:InputFiles
abstract val sourceDirs: ConfigurableFileCollection

@get:Internal
override val outputFile: Provider<RegularFile> get() = output.file(SENTRY_BUNDLE_ID_OUTPUT)

Expand Down Expand Up @@ -64,6 +71,7 @@ abstract class GenerateBundleIdTask : PropertiesFileOutputTask() {
project: Project,
extension: SentryPluginExtension,
sentryTelemetryProvider: Provider<SentryTelemetryService>?,
sourceDirs: Provider<out Collection<Directory>>?,
output: Provider<Directory>? = null,
includeSourceContext: Property<Boolean>,
taskSuffix: String = ""
Expand All @@ -75,6 +83,7 @@ abstract class GenerateBundleIdTask : PropertiesFileOutputTask() {
output?.let { task.output.set(it) }
task.includeSourceContext.set(includeSourceContext)
task.withSentryTelemetry(extension, sentryTelemetryProvider)
task.sourceDirs.setFrom(sourceDirs)
}
return generateBundleIdTask
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.sentry.android.gradle.extensions.SentryPluginExtension
import io.sentry.android.gradle.telemetry.SentryTelemetryService
import io.sentry.gradle.common.SentryVariant
import org.gradle.api.Project
import org.gradle.api.file.Directory
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider

Expand All @@ -15,23 +16,17 @@ class SourceContext {
sentryTelemetryProvider: Provider<SentryTelemetryService>?,
variant: SentryVariant,
paths: OutputPaths,
sourceFiles: Provider<out Collection<Directory>>?,
cliExecutable: Provider<String>,
sentryOrg: String?,
sentryProject: String?,
taskSuffix: String
): SourceContextTasks {
val additionalSourcesProvider = project.provider {
extension.additionalSourceDirsForSourceContext.getOrElse(emptySet())
.map { project.layout.projectDirectory.dir(it) }
}
val sourceFiles = variant.sources(
project,
additionalSourcesProvider
)
val generateBundleIdTask = GenerateBundleIdTask.register(
project,
extension,
sentryTelemetryProvider,
sourceFiles,
output = paths.bundleIdDir,
extension.includeSourceContext,
taskSuffix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ abstract class UploadSourceBundleTask : Exec() {
includeSourceContext.getOrElse(false) &&
!sourceBundleDir.asFileTree.isEmpty
}

// Allows gradle to consider this task up-to-date if the inputs haven't changed
// As this task does not have any outputs, it will always be considered to be out-of-date otherwise
// More info here https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:task_outcomes
// and https://docs.gradle.org/current/userguide/incremental_build.html#sec:custom_up_to_date_logic
outputs.upToDateWhen { true }
}

@get:Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import org.gradle.api.tasks.TaskProvider
abstract class SentryGenerateDebugMetaPropertiesTask : DirectoryOutputTask() {

init {
outputs.upToDateWhen { false }
description = "Combines multiple properties files into sentry-debug-meta.properties"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,32 @@ import io.sentry.android.gradle.util.info
import java.util.Properties
import java.util.UUID
import org.gradle.api.Project
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.Directory
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskProvider

abstract class SentryGenerateProguardUuidTask : PropertiesFileOutputTask() {

init {
outputs.upToDateWhen { false }
description = "Generates a unique build ID to be used " +
"when uploading the Sentry mapping file"
}

@get:Internal
override val outputFile: Provider<RegularFile> get() = output.file(SENTRY_UUID_OUTPUT)

@get:PathSensitive(PathSensitivity.RELATIVE)
@get:InputFiles
abstract val proguardMappingFile: ConfigurableFileCollection

@TaskAction
fun generateProperties() {
val outputDir = output.get().asFile
Expand Down Expand Up @@ -54,6 +62,7 @@ abstract class SentryGenerateProguardUuidTask : PropertiesFileOutputTask() {
extension: SentryPluginExtension,
sentryTelemetryProvider: Provider<SentryTelemetryService>?,
output: Provider<Directory>? = null,
proguardMappingFile: Provider<FileCollection>?,
taskSuffix: String = ""
): TaskProvider<SentryGenerateProguardUuidTask> {
val generateUuidTask = project.tasks.register(
Expand All @@ -62,6 +71,7 @@ abstract class SentryGenerateProguardUuidTask : PropertiesFileOutputTask() {
) { task ->
output?.let { task.output.set(it) }
task.withSentryTelemetry(extension, sentryTelemetryProvider)
task.proguardMappingFile.setFrom(proguardMappingFile)
}
return generateUuidTask
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ abstract class SentryUploadProguardMappingsTask : Exec() {

init {
description = "Uploads the proguard mappings file to Sentry"

// Allows gradle to consider this task up-to-date if the inputs haven't changed
// As this task does not have any outputs, it will always be considered to be out-of-date otherwise
// More info here https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:task_outcomes
// and https://docs.gradle.org/current/userguide/incremental_build.html#sec:custom_up_to_date_logic
outputs.upToDateWhen { true }
}

@get:Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,22 @@ class SentryJvmPlugin @Inject constructor(
buildEvents.onOperationCompletion(sentryTelemetryProvider)
}

val additionalSourcesProvider = project.provider {
extension.additionalSourceDirsForSourceContext.getOrElse(emptySet())
.map { project.layout.projectDirectory.dir(it) }
}
val sourceFiles = javaVariant.sources(
project,
additionalSourcesProvider
)

val sourceContextTasks = SourceContext.register(
project,
extension,
sentryTelemetryProvider,
javaVariant,
outputPaths,
sourceFiles,
cliExecutable,
sentryOrgParameter,
sentryProjectParameter,
Expand Down
Loading

0 comments on commit a4bd46d

Please sign in to comment.