Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the multiplatform configuration #3246

Merged
merged 3 commits into from
May 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.TaskProvider
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import java.io.File

/**
Expand Down Expand Up @@ -61,31 +58,16 @@ private fun KotlinMultiplatformExtension.sources(): List<Source> {
// For multiplatform we only support SQLDelight in commonMain - to support other source sets
// we would need to generate expect/actual SQLDelight code which at least right now doesn't
// seem like there is a use case for. However this code is capable of running on any Target type.
val target = targets.single { it is KotlinMetadataTarget }
return target.compilations.mapNotNull { compilation ->
if (compilation.name.endsWith(suffix = "Test", ignoreCase = true)) {
// TODO: If we can include these compilations as sqldelight compilation units, we solve
// the testing problem. However there's no api to get the main compilation for a test
// compilation, except for native where KotlinNativeCompilation has a
// "friendCompilationName" which is the main compilation unit. There looks to be
// nothing for the other compilation units, but we should revisit later to see if
// theres a way to accomplish this.
return@mapNotNull null
}
if (target is KotlinMetadataTarget && compilation.name == "commonMain") {
// In Kotlin 1.6.20 the metadata target now has two compilations for unknown reasons.
return@mapNotNull null
}
val targetName = if (target is KotlinMetadataTarget) "common" else target.name
return listOf(
Source(
type = target.platformType,
nativePresetName = (target as? KotlinNativeTarget)?.preset?.name,
name = "$targetName${compilation.name.capitalize()}",
variantName = (compilation as? KotlinJvmAndroidCompilation)?.name,
sourceDirectorySet = compilation.defaultSourceSet.kotlin,
sourceSets = compilation.allKotlinSourceSets.map { it.name },
type = KotlinPlatformType.common,
nativePresetName = null,
name = "commonMain",
variantName = "commonMain",
sourceDirectorySet = sourceSets.getByName("commonMain").kotlin,
sourceSets = listOf("commonMain"),
)
}
)
}

private fun BaseExtension.sources(): List<Source> {
Expand Down