|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Meshtastic LLC |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.meshtastic.buildlogic |
| 19 | + |
| 20 | +import org.gradle.api.Project |
| 21 | +import org.gradle.api.provider.Provider |
| 22 | +import org.gradle.kotlin.dsl.configure |
| 23 | +import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension |
| 24 | + |
| 25 | +internal fun Project.configureComposeCompiler() { |
| 26 | + extensions.configure<ComposeCompilerGradlePluginExtension> { |
| 27 | + fun Provider<String>.onlyIfTrue() = |
| 28 | + flatMap { provider { it.takeIf(String::toBoolean) } } |
| 29 | + |
| 30 | + fun Provider<*>.relativeToRootProject(dir: String) = map { |
| 31 | + isolated.rootProject.projectDirectory |
| 32 | + .dir("build") |
| 33 | + .dir(projectDir.toRelativeString(rootDir)) |
| 34 | + }.map { it.dir(dir) } |
| 35 | + project.providers.gradleProperty("enableComposeCompilerMetrics").onlyIfTrue() |
| 36 | + .relativeToRootProject("compose-metrics").let(metricsDestination::set) |
| 37 | + project.providers.gradleProperty("enableComposeCompilerReports").onlyIfTrue() |
| 38 | + .relativeToRootProject("compose-reports").let(reportsDestination::set) |
| 39 | + stabilityConfigurationFiles.add( |
| 40 | + isolated.rootProject.projectDirectory.file("compose_compiler_config.conf"), |
| 41 | + ) |
| 42 | + } |
| 43 | +} |
0 commit comments