-
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
- Loading branch information
1 parent
5ab058a
commit 8bcad23
Showing
6 changed files
with
102 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
56 changes: 56 additions & 0 deletions
56
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,56 @@ | ||
/* | ||
* 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 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 { | ||
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 enableMetrics() { | ||
if (metricsEnabled) return | ||
metricsEnabled = true | ||
|
||
project.tasks.withType(KotlinCompile::class.java) { | ||
val dir = project.redwoodGeneratedDir("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) { | ||
val dir = project.redwoodGeneratedDir("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