Skip to content

Commit

Permalink
Merge pull request #259 from DataDog/nogorodnikov/rum-4406/avoid-buil…
Browse files Browse the repository at this point in the history
…did-task-creation-if-no-deobfuscation-or-native-build-providers

RUM-4406: Avoid BuildId task creation if there is no obfuscation or native build providers registered
  • Loading branch information
0xnm authored May 15, 2024
2 parents db3ff0d + ecf9853 commit e5b955f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,40 @@ class DdAndroidGradlePlugin @Inject constructor(
variant: ApplicationVariant,
apiKey: ApiKey
) {
val buildIdGenerationTask =
configureBuildIdGenerationTask(target, androidExtension, variant)

if (isObfuscationEnabled(variant, datadogExtension)) {
configureVariantForUploadTask(
target,
variant,
buildIdGenerationTask,
apiKey,
datadogExtension
)
} else {
LOGGER.info("Minifying disabled for variant ${variant.name}, no upload task created")
val isObfuscationEnabled = isObfuscationEnabled(variant, datadogExtension)
val isNativeBuildRequired = variant.externalNativeBuildProviders.isNotEmpty()

if (isObfuscationEnabled || isNativeBuildRequired) {
val buildIdGenerationTask =
configureBuildIdGenerationTask(target, androidExtension, variant)

if (isObfuscationEnabled) {
configureVariantForUploadTask(
target,
variant,
buildIdGenerationTask,
apiKey,
datadogExtension
)
} else {
LOGGER.info("Minifying disabled for variant ${variant.name}, no mapping file upload task created")
}

if (isNativeBuildRequired) {
configureNdkSymbolUploadTask(
target,
datadogExtension,
variant,
buildIdGenerationTask,
apiKey
)
} else {
LOGGER.info(
"No native build tasks found for variant ${variant.name}," +
" no NDK symbol file upload task created."
)
}
}
configureNdkSymbolUploadTask(
target,
datadogExtension,
variant,
buildIdGenerationTask
)
configureVariantForSdkCheck(target, variant, datadogExtension)
}

Expand All @@ -118,9 +132,9 @@ class DdAndroidGradlePlugin @Inject constructor(
target: Project,
extension: DdExtension,
variant: ApplicationVariant,
buildIdTask: TaskProvider<GenerateBuildIdTask>
): TaskProvider<DdNdkSymbolFileUploadTask>? {
val apiKey = resolveApiKey(target)
buildIdTask: TaskProvider<GenerateBuildIdTask>,
apiKey: ApiKey
): TaskProvider<DdNdkSymbolFileUploadTask> {
val extensionConfiguration = resolveExtensionConfiguration(extension, variant)

val uploadTask = DdNdkSymbolFileUploadTask.register(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.datadog.gradle.plugin.internal.Uploader
import org.gradle.api.Project
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.logging.Logging
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
Expand Down Expand Up @@ -89,8 +88,6 @@ internal abstract class DdNdkSymbolFileUploadTask @Inject constructor(
SupportedArchitectureMapping("x86_64", "x64")
)

internal val LOGGER = Logging.getLogger("DdSymbolFileUploadTask")

private fun getSearchDirs(
buildTask: TaskProvider<ExternalNativeBuildTask>,
providerFactory: ProviderFactory
Expand Down Expand Up @@ -122,13 +119,7 @@ internal abstract class DdNdkSymbolFileUploadTask @Inject constructor(
apiKey: ApiKey,
extensionConfiguration: DdExtensionConfiguration,
repositoryDetector: RepositoryDetector
): TaskProvider<DdNdkSymbolFileUploadTask>? {
val nativeBuildProviders = variant.externalNativeBuildProviders
if (nativeBuildProviders.isEmpty()) {
LOGGER.info("No native build tasks found for variant ${variant.name}, skipping NDK symbol file upload.")
return null
}

): TaskProvider<DdNdkSymbolFileUploadTask> {
return project.tasks.register(
TASK_NAME + variant.name.capitalize(),
DdNdkSymbolFileUploadTask::class.java,
Expand All @@ -145,6 +136,7 @@ internal abstract class DdNdkSymbolFileUploadTask @Inject constructor(
}
task.sourceSetRoots = roots

val nativeBuildProviders = variant.externalNativeBuildProviders
nativeBuildProviders.forEach { buildTask ->
val searchFiles = getSearchDirs(buildTask, providerFactory)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ internal class DdAndroidGradlePluginTest {
}

@Test
fun `M create buildId task W configureTasksForVariant() { no deobfuscation }`(
fun `M not create buildId task W configureTasksForVariant() { no deobfuscation, no native build providers }`(
@StringForgery(case = Case.LOWER) flavorName: String,
@StringForgery(case = Case.LOWER) buildTypeName: String,
@StringForgery versionName: String,
Expand Down Expand Up @@ -465,7 +465,7 @@ internal class DdAndroidGradlePluginTest {

// Then
val allTasks = fakeProject.tasks.map { it.name }
assertThat(allTasks).contains("generateBuildId${variantName.replaceFirstChar { capitalizeChar(it) }}")
assertThat(allTasks).doesNotContain("generateBuildId${variantName.replaceFirstChar { capitalizeChar(it) }}")
}

@Test
Expand Down

0 comments on commit e5b955f

Please sign in to comment.