Add compose compiler metrics option

pull/125/head
takahirom 3 years ago
parent f651908b4f
commit 5c73cdd973

@ -24,6 +24,7 @@ import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import java.io.File
/** /**
* Configure base Kotlin with Android options * Configure base Kotlin with Android options
@ -56,7 +57,7 @@ internal fun Project.configureKotlinAndroid(
"-opt-in=kotlin.Experimental", "-opt-in=kotlin.Experimental",
// Enable experimental kotlinx serialization APIs // Enable experimental kotlinx serialization APIs
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi" "-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
) ) + buildComposeMetricsParameters()
// Set JVM target to 1.8 // Set JVM target to 1.8
jvmTarget = JavaVersion.VERSION_1_8.toString() jvmTarget = JavaVersion.VERSION_1_8.toString()
@ -70,6 +71,26 @@ internal fun Project.configureKotlinAndroid(
} }
} }
private fun Project.buildComposeMetricsParameters(): List<String> {
val metricParameters = mutableListOf<String>()
val enableMetricsProvider = project.providers.gradleProperty("enableComposeCompilerMetrics")
val enableMetrics = (enableMetricsProvider.orNull == "true")
if (enableMetrics) {
val metricsFolder = File(project.buildDir, "compose-metrics")
metricParameters.add("-P")
metricParameters.add("plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" + metricsFolder.absolutePath)
}
val enableReportsProvider = project.providers.gradleProperty("enableComposeCompilerReports")
val enableReports = (enableReportsProvider.orNull == "true")
if (enableReports) {
val reportsFolder = File(project.buildDir, "compose-reports")
metricParameters.add("-P")
metricParameters.add("plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + reportsFolder.absolutePath)
}
return metricParameters
}
private fun CommonExtension<*, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) { private fun CommonExtension<*, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
(this as ExtensionAware).extensions.configure("kotlinOptions", block) (this as ExtensionAware).extensions.configure("kotlinOptions", block)
} }

Loading…
Cancel
Save