|
| 1 | +package com.softartdev.notedelight |
| 2 | + |
| 3 | +import org.gradle.api.Project |
| 4 | +import org.gradle.api.artifacts.VersionCatalog |
| 5 | +import org.gradle.api.artifacts.VersionCatalogsExtension |
| 6 | +import org.gradle.kotlin.dsl.getByType |
| 7 | +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME |
| 8 | +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.TEST_COMPILATION_NAME |
| 9 | +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet |
| 10 | +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet.Companion.COMMON_MAIN_SOURCE_SET_NAME |
| 11 | +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet.Companion.COMMON_TEST_SOURCE_SET_NAME |
| 12 | +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetContainer |
| 13 | +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget |
| 14 | + |
| 15 | +val Project.libs |
| 16 | + get(): VersionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs") |
| 17 | + |
| 18 | +//FIXME https://github.com/cashapp/sqldelight/issues/4523 |
| 19 | +fun KotlinSourceSetContainer.iosIntermediateSourceSets(vararg iosTargets: KotlinNativeTarget) { |
| 20 | + val children: List<Pair<KotlinSourceSet, KotlinSourceSet>> = iosTargets.map { target -> |
| 21 | + val main = target.compilations.getByName(MAIN_COMPILATION_NAME).defaultSourceSet |
| 22 | + val test = target.compilations.getByName(TEST_COMPILATION_NAME).defaultSourceSet |
| 23 | + return@map main to test |
| 24 | + } |
| 25 | + val parent: Pair<KotlinSourceSet, KotlinSourceSet> = Pair( |
| 26 | + first = sourceSets.getByName(COMMON_MAIN_SOURCE_SET_NAME), |
| 27 | + second = sourceSets.getByName(COMMON_TEST_SOURCE_SET_NAME) |
| 28 | + ) |
| 29 | + createIntermediateSourceSet("iosMain", children.map { it.first }, parent.first) |
| 30 | + createIntermediateSourceSet("iosTest", children.map { it.second }, parent.second) |
| 31 | +} |
| 32 | + |
| 33 | +private fun KotlinSourceSetContainer.createIntermediateSourceSet( |
| 34 | + name: String, |
| 35 | + children: List<KotlinSourceSet>, |
| 36 | + parent: KotlinSourceSet |
| 37 | +): KotlinSourceSet = sourceSets.maybeCreate(name).apply { |
| 38 | + dependsOn(parent) |
| 39 | + children.forEach { it.dependsOn(this) } |
| 40 | +} |
0 commit comments