diff --git a/CHANGELOG.md b/CHANGELOG.md index 12366b95..75ea0a49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Changelog **Unreleased** -------------- +- Add workaround for KGP not applying `sourceInformation` compose options in android projects and default it to true. + 0.19.4 ------ diff --git a/slack-plugin/src/main/kotlin/slack/gradle/SlackExtension.kt b/slack-plugin/src/main/kotlin/slack/gradle/SlackExtension.kt index fd3ba4a0..ddfb30ec 100644 --- a/slack-plugin/src/main/kotlin/slack/gradle/SlackExtension.kt +++ b/slack-plugin/src/main/kotlin/slack/gradle/SlackExtension.kt @@ -942,6 +942,8 @@ constructor( // Because the Compose Compiler plugin auto applies common options for us, we need to know // about those options and _avoid_ setting them a second time val freeOptions = mutableListOf() + var includeSourceInformation = + slackProperties.composeIncludeSourceInformationEverywhereByDefault for ((k, v) in compilerOptions.get().map { it.split('=') }) { project.logger.debug("Processing compose option $k = $v") when (k) { @@ -949,8 +951,8 @@ constructor( extension.generateFunctionKeyMetaClasses.set(v.toBoolean()) } - "sourceInformation" -> { - extension.includeSourceInformation.set(v.toBoolean()) + OPTION_SOURCE_INFORMATION -> { + includeSourceInformation = v.toBoolean() } "metricsDestination" -> { @@ -999,6 +1001,14 @@ constructor( } } + if (includeSourceInformation) { + if (androidExtension == null) { + extension.includeSourceInformation.set(true) + } else if (slackProperties.composeUseIncludeInformationWorkaround) { + freeOptions += "$OPTION_SOURCE_INFORMATION=true" + } + } + if (freeOptions.isNotEmpty()) { project.tasks.configureKotlinCompilationTask { compilerOptions.freeCompilerArgs.addAll( @@ -1011,7 +1021,8 @@ constructor( private companion object { /** Live literals are disabled and deprecated in AGP 8.7+ */ - val AGP_LIVE_LITERALS_MAX_VERSION = AndroidPluginVersion(8, 6, 0) + private val AGP_LIVE_LITERALS_MAX_VERSION = AndroidPluginVersion(8, 6, 0) + private const val OPTION_SOURCE_INFORMATION = "sourceInformation" } } diff --git a/slack-plugin/src/main/kotlin/slack/gradle/SlackProperties.kt b/slack-plugin/src/main/kotlin/slack/gradle/SlackProperties.kt index 59db8ef8..5849a39c 100644 --- a/slack-plugin/src/main/kotlin/slack/gradle/SlackProperties.kt +++ b/slack-plugin/src/main/kotlin/slack/gradle/SlackProperties.kt @@ -175,6 +175,31 @@ internal constructor( project.rootProject.layout.projectDirectory.file(it) } + /** + * Use a workaround for compose-compiler's `includeInformation` option on android projects. + * + * On android projects, the compose compiler gradle plugin annoyingly no-ops + * https://issuetracker.google.com/issues/362780328#comment4 + */ + public val composeUseIncludeInformationWorkaround: Boolean + get() = + resolver.booleanValue("sgp.compose.useIncludeInformationWorkaround", defaultValue = true) + + /** + * By default, Compose on android only enables source information in debug variants. This is a bit + * silly in large projects because we generally make all libraries single-variant as "release", + * and can result in libraries not having source information. Instead, we rely on R8 to strip out + * this information in release builds as needed. + * + * @see Upstream issue + */ + public val composeIncludeSourceInformationEverywhereByDefault: Boolean + get() = + resolver.booleanValue( + "sgp.compose.includeSourceInformationEverywhereByDefault", + defaultValue = true, + ) + /** * When this property is present, the "internalRelease" build variant will have an application id * of "com.Slack.prototype", instead of "com.Slack.internal".