From 3bcababcef48aaea4b7048c338dedaf09e645e63 Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Fri, 23 Aug 2024 14:54:05 +0900 Subject: [PATCH 1/5] Create Project.relativeToRootProject extension. Change-Id: I746648d1b11c029a0dcdbac8ca0b8b6487542b0f --- .../samples/apps/nowinandroid/ProjectExtensions.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/ProjectExtensions.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/ProjectExtensions.kt index e45d7f2e1e..dfb55a6b0d 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/ProjectExtensions.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/ProjectExtensions.kt @@ -19,7 +19,16 @@ package com.google.samples.apps.nowinandroid import org.gradle.api.Project import org.gradle.api.artifacts.VersionCatalog import org.gradle.api.artifacts.VersionCatalogsExtension +import org.gradle.api.file.Directory +import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.getByType val Project.libs get(): VersionCatalog = extensions.getByType().named("libs") + +/** + * Create new Directory by [dir] name in the root build directory. + */ +internal fun Project.relativeToRootProject(dir: String): Provider = + rootProject.layout.buildDirectory.dir(projectDir.toRelativeString(rootDir)) + .map { it.dir(dir) } From ddffc459ca74e6abd607aecfc7a2fe2a9c1a1c4a Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Fri, 23 Aug 2024 15:00:25 +0900 Subject: [PATCH 2/5] Integrate compose-metrics and compose-reports in one property "enableComposeCompilerReportsAndMetrics". Change-Id: Iaa78284fae1532e728c5f4546ac825b7509e450f --- .../apps/nowinandroid/AndroidCompose.kt | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt index f16a8051a5..ec9238a6af 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt @@ -18,7 +18,6 @@ package com.google.samples.apps.nowinandroid import com.android.build.api.dsl.CommonExtension import org.gradle.api.Project -import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.assign import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.dependencies @@ -52,21 +51,14 @@ internal fun Project.configureAndroidCompose( } extensions.configure { - fun Provider.onlyIfTrue() = flatMap { provider { it.takeIf(String::toBoolean) } } - fun Provider<*>.relativeToRootProject(dir: String) = flatMap { - rootProject.layout.buildDirectory.dir(projectDir.toRelativeString(rootDir)) - }.map { it.dir(dir) } - - project.providers.gradleProperty("enableComposeCompilerMetrics").onlyIfTrue() - .relativeToRootProject("compose-metrics") - .let(metricsDestination::set) + if (project.hasProperty("enableComposeCompilerReportsAndMetrics")) { + metricsDestination = relativeToRootProject("compose-metrics") + reportsDestination = relativeToRootProject("compose-reports") + } - project.providers.gradleProperty("enableComposeCompilerReports").onlyIfTrue() - .relativeToRootProject("compose-reports") - .let(reportsDestination::set) + stabilityConfigurationFile = + rootProject.layout.projectDirectory.file("compose_compiler_config.conf") - stabilityConfigurationFile = rootProject.layout.projectDirectory.file("compose_compiler_config.conf") - enableStrongSkippingMode = true } } From 3a71f267cc3c8539768020d9be12e299f1a76329 Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Fri, 23 Aug 2024 15:04:17 +0900 Subject: [PATCH 3/5] Edit Compose compiler section README. Change-Id: I19409913690df600eee80b6ca98f6ad9dd59f0a0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1f52703239..14efcff3b4 100644 --- a/README.md +++ b/README.md @@ -190,11 +190,11 @@ Then copy the resulting baseline profile from the emulator to [`app/src/main/bas Run the following command to get and analyse compose compiler metrics: ```bash -./gradlew assembleRelease -PenableComposeCompilerMetrics=true -PenableComposeCompilerReports=true +./gradlew assembleRelease -PenableComposeCompilerReportsAndMetrics=true --rerun-tasks ``` -The reports files will be added to [build/compose-reports](build/compose-reports). The metrics files will also be -added to [build/compose-metrics](build/compose-metrics). +The reports files will be added to ***build/module-name/compose-reports***. The metrics files will also be +added to ***build/module-name/compose-metrics***. For more information on Compose compiler metrics, see [this blog post](https://medium.com/androiddevelopers/jetpack-compose-stability-explained-79c10db270c8). From 96f4b50b6ae660d73ae509efd11c7934f04aaab6 Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Fri, 23 Aug 2024 18:53:01 +0900 Subject: [PATCH 4/5] Create Project.isPropertyValueIsTrue extension. Change-Id: I550739d630b82c252add80a277fe1248e7577d74 --- .../google/samples/apps/nowinandroid/ProjectExtensions.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/ProjectExtensions.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/ProjectExtensions.kt index dfb55a6b0d..1756cb52b6 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/ProjectExtensions.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/ProjectExtensions.kt @@ -32,3 +32,9 @@ val Project.libs internal fun Project.relativeToRootProject(dir: String): Provider = rootProject.layout.buildDirectory.dir(projectDir.toRelativeString(rootDir)) .map { it.dir(dir) } + +/** + * Check a [propertyName]'s property value is true. + */ +internal fun Project.isPropertyValueIsTrue(propertyName: String): Boolean = + properties[propertyName].toString().toBoolean() From 15cc78f763e004d5c5481d73b898864959b1058c Mon Sep 17 00:00:00 2001 From: Jaehwa Noh Date: Fri, 23 Aug 2024 18:53:26 +0900 Subject: [PATCH 5/5] Check the property value is true. Change-Id: Idbde833767c13f73a46533bf8dc320fc1926a620 --- .../com/google/samples/apps/nowinandroid/AndroidCompose.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt index ec9238a6af..c4f5d3d0ba 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/AndroidCompose.kt @@ -51,7 +51,7 @@ internal fun Project.configureAndroidCompose( } extensions.configure { - if (project.hasProperty("enableComposeCompilerReportsAndMetrics")) { + if (isPropertyValueIsTrue("enableComposeCompilerReportsAndMetrics")) { metricsDestination = relativeToRootProject("compose-metrics") reportsDestination = relativeToRootProject("compose-reports") }