Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround for source information in KGP/AGP #977

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------

Expand Down
17 changes: 14 additions & 3 deletions slack-plugin/src/main/kotlin/slack/gradle/SlackExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -942,15 +942,17 @@ 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<String>()
var includeSourceInformation =
slackProperties.composeIncludeSourceInformationEverywhereByDefault
for ((k, v) in compilerOptions.get().map { it.split('=') }) {
project.logger.debug("Processing compose option $k = $v")
when (k) {
"generateFunctionKeyMetaClasses" -> {
extension.generateFunctionKeyMetaClasses.set(v.toBoolean())
}

"sourceInformation" -> {
extension.includeSourceInformation.set(v.toBoolean())
OPTION_SOURCE_INFORMATION -> {
includeSourceInformation = v.toBoolean()
}

"metricsDestination" -> {
Expand Down Expand Up @@ -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(
Expand All @@ -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"
}
}

Expand Down
25 changes: 25 additions & 0 deletions slack-plugin/src/main/kotlin/slack/gradle/SlackProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://issuetracker.google.com/issues/362780328">Upstream issue</a>
*/
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".
Expand Down