-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DSL helpers to enable metrics and reports (#1627)
- Loading branch information
1 parent
e242612
commit d1fc6d0
Showing
13 changed files
with
284 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
redwood-gradle-plugin/src/main/kotlin/app/cash/redwood/gradle/RedwoodComposeExtensionImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.gradle | ||
|
||
import app.cash.redwood.gradle.RedwoodComposeExtension.DangerZone | ||
import org.gradle.api.Action | ||
import org.gradle.api.Project | ||
import org.gradle.api.provider.Property | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
internal class RedwoodComposeExtensionImpl( | ||
private val project: Project, | ||
) : RedwoodComposeExtension, DangerZone { | ||
private var metricsEnabled = false | ||
private var reportsEnabled = false | ||
|
||
// Explicit backing property avoids Gradle attempting to reflect on an implicit backing field. | ||
override val kotlinCompilerPlugin: Property<String> get() = _kotlinCompilerPlugin | ||
|
||
private val _kotlinCompilerPlugin = project.objects.property(String::class.java) | ||
.convention(composeCompilerVersion) | ||
|
||
override fun dangerZone(body: Action<DangerZone>) { | ||
body.execute(this) | ||
} | ||
|
||
override fun enableMetrics() { | ||
if (metricsEnabled) return | ||
metricsEnabled = true | ||
|
||
project.tasks.withType(KotlinCompile::class.java).configureEach { | ||
val dir = project.redwoodReportDir("compose-metrics/${it.name}").get().asFile.absolutePath | ||
it.compilerOptions.freeCompilerArgs.addAll( | ||
"-P", | ||
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=$dir", | ||
) | ||
} | ||
} | ||
|
||
override fun enableReports() { | ||
if (reportsEnabled) return | ||
reportsEnabled = true | ||
|
||
project.tasks.withType(KotlinCompile::class.java).configureEach { | ||
val dir = project.redwoodReportDir("compose-reports/${it.name}").get().asFile.absolutePath | ||
it.compilerOptions.freeCompilerArgs.addAll( | ||
"-P", | ||
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=$dir", | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
redwood-gradle-plugin/src/test/fixture/compose-compiler-metrics/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
buildscript { | ||
dependencies { | ||
classpath "app.cash.redwood:redwood-gradle-plugin:$redwoodVersion" | ||
classpath libs.kotlin.gradlePlugin | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "file://${rootDir.absolutePath}/../../../../../build/localMaven" | ||
} | ||
mavenCentral() | ||
google() | ||
} | ||
} | ||
|
||
apply plugin: 'org.jetbrains.kotlin.jvm' | ||
apply plugin: 'app.cash.redwood' | ||
|
||
redwood { | ||
dangerZone { | ||
enableMetrics() | ||
} | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "file://${rootDir.absolutePath}/../../../../../build/localMaven" | ||
} | ||
mavenCentral() | ||
google() | ||
} |
7 changes: 7 additions & 0 deletions
7
redwood-gradle-plugin/src/test/fixture/compose-compiler-metrics/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dependencyResolutionManagement { | ||
versionCatalogs { | ||
libs { | ||
from(files('../../../../../gradle/libs.versions.toml')) | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...le-plugin/src/test/fixture/compose-compiler-metrics/src/main/kotlin/com/example/double.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.example | ||
|
||
import androidx.compose.runtime.Composable | ||
|
||
@Composable | ||
fun double(value: Int): Int { | ||
return value * 2 | ||
} |
31 changes: 31 additions & 0 deletions
31
redwood-gradle-plugin/src/test/fixture/compose-compiler-reports/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
buildscript { | ||
dependencies { | ||
classpath "app.cash.redwood:redwood-gradle-plugin:$redwoodVersion" | ||
classpath libs.kotlin.gradlePlugin | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "file://${rootDir.absolutePath}/../../../../../build/localMaven" | ||
} | ||
mavenCentral() | ||
google() | ||
} | ||
} | ||
|
||
apply plugin: 'org.jetbrains.kotlin.jvm' | ||
apply plugin: 'app.cash.redwood' | ||
|
||
redwood { | ||
dangerZone { | ||
enableReports() | ||
} | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "file://${rootDir.absolutePath}/../../../../../build/localMaven" | ||
} | ||
mavenCentral() | ||
google() | ||
} |
7 changes: 7 additions & 0 deletions
7
redwood-gradle-plugin/src/test/fixture/compose-compiler-reports/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dependencyResolutionManagement { | ||
versionCatalogs { | ||
libs { | ||
from(files('../../../../../gradle/libs.versions.toml')) | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...le-plugin/src/test/fixture/compose-compiler-reports/src/main/kotlin/com/example/double.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.example | ||
|
||
import androidx.compose.runtime.Composable | ||
|
||
@Composable | ||
fun double(value: Int): Int { | ||
return value * 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters