Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ To use the library in a KMM project, use this config in the `build.gradle.kts`:
plugins {
//add ksp and koru compiler plugin
id("com.google.devtools.ksp") version "1.6.21-1.0.6"
id("com.futuremind.koru").version("0.11.1")
id("com.futuremind.koru").version("0.13.0")
}

kotlin {
Expand All @@ -256,7 +256,7 @@ kotlin {
val commonMain by getting {
dependencies {
// add library dependency
implementation("com.futuremind:koru:0.11.1")
implementation("com.futuremind:koru:0.13.0")
}
}

Expand All @@ -267,12 +267,6 @@ kotlin {
}

}

koru {
// let the compiler plugin know where the generated code should be available
// by providing the name of ios source set
nativeSourceSetNames = listOf("iosMain")
}
```

<details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import java.io.File


class CompilerPlugin : Plugin<Project> {

override fun apply(project: Project) = with(project) {
val extension: KoruPluginExtension = extensions.create("koru")
requireKspPluginDependency()
enableKspRunForCommonMainSourceSet()
makeSureCompilationIsRunAfterKsp()
afterEvaluate {
requireSourceSetsNamesSet(extension.nativeSourceSetNames)
addGeneratedFilesToSourceSets(extension.nativeSourceSetNames)
enableKspRunForAppleSourceSet()
}
}

Expand All @@ -28,45 +21,13 @@ class CompilerPlugin : Plugin<Project> {
}
}

private fun Project.enableKspRunForCommonMainSourceSet() = dependencies {
//todo don't hardcode version
add("kspCommonMainMetadata", "com.futuremind:koru-processor:0.12.0")
}

private fun Project.makeSureCompilationIsRunAfterKsp() = tasks
.matching {
it.name.startsWith("compileKotlinIos")
|| it.name.startsWith("compileKotlinMacos")
|| it.name.startsWith("compileKotlinWatchos")
|| it.name.startsWith("compileKotlinTvos")
}
.configureEach {
dependsOn("kspCommonMainKotlinMetadata")
}

private fun requireSourceSetsNamesSet(nativeSourceSetNames: List<String>) {
require(nativeSourceSetNames.isNotEmpty()) {
"You need to provide the name of your main native source set in your build.gradle, e.g. koru.nativeSourceSetNames = listOf(\"iosMain\")"
}
}

private fun Project.addGeneratedFilesToSourceSets(sourceSetNames: List<String>) {
val anyMatch = extensions
.getByType<KotlinMultiplatformExtension>().sourceSets
.any { sourceSetNames.contains(it.name) }
if (!anyMatch) throw IllegalStateException("None of the provided source set names were matched: $sourceSetNames. You need to provide the name of your main native source set in your build.gradle, e.g. koru.nativeSourceSetNames = listOf(\"iosMain\")")

extensions
.getByType<KotlinMultiplatformExtension>().sourceSets
.matching { sourceSetNames.contains(it.name) }
.configureEach {
kotlin.srcDir("${project.buildDir.absolutePath}${File.separator}generated${File.separator}ksp${File.separator}metadata${File.separator}commonMain${File.separator}kotlin")
private fun Project.enableKspRunForAppleSourceSet() = dependencies {
val kspAppleRegex = "ksp[Ios|Tvos|Macos|Watchos]+(?!.*Test$)".toRegex()
configurations
.filter { it.name.contains(kspAppleRegex) }
.forEach {
//todo don't hardcode version
add(it.name, "com.futuremind:koru-processor:0.13.0")
}
}
}

open class KoruPluginExtension {
var nativeSourceSetNames: List<String> = listOf()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class WrapperClassBuilder(
companion object {
private const val WRAPPED_PROPERTY_NAME = "wrapped"
private const val SCOPE_PROVIDER_PROPERTY_NAME = "scopeProvider"
private val SUSPEND_WRAPPER_TYPE_NAME = SuspendWrapper::class.asTypeName()
private val FLOW_WRAPPER_TYPE_NAME = FlowWrapper::class.asTypeName()
}

private val constructorSpec = FunSpec
Expand Down Expand Up @@ -132,7 +134,7 @@ class WrapperClassBuilder(
originalFunSpec: FunSpec
): FunSpec.Builder = addCode(
buildCodeBlock {
add("return %T(", SuspendWrapper::class)
add("return %T(", SUSPEND_WRAPPER_TYPE_NAME)
add(SCOPE_PROVIDER_PROPERTY_NAME)
add(", ")
add("%L", freezeWrapper)
Expand All @@ -149,7 +151,7 @@ class WrapperClassBuilder(
)

private fun flowWrapperFunctionBody(callOriginal: String) = buildCodeBlock {
add("return %T(", FlowWrapper::class)
add("return %T(", FLOW_WRAPPER_TYPE_NAME)
add(SCOPE_PROVIDER_PROPERTY_NAME)
add(", %L", freezeWrapper)
add(", ${callOriginal})")
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ rootProject.name = "Koru"

gradle.allprojects {
group = "com.futuremind"
version = "0.12.0"
version = "0.13.0"
}

includeBuild("publish-plugin")
Expand Down