From cba6d5a2a1bcf8e254c9701aed9dd823298b6135 Mon Sep 17 00:00:00 2001 From: marty-suzuki Date: Tue, 15 Aug 2023 17:32:01 +0900 Subject: [PATCH 1/5] replace SuspendWrapper::class to TypeName --- .../futuremind/koru/processor/builders/WrapperClassBuilder.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/koru-processor/src/jvmMain/kotlin/com/futuremind/koru/processor/builders/WrapperClassBuilder.kt b/koru-processor/src/jvmMain/kotlin/com/futuremind/koru/processor/builders/WrapperClassBuilder.kt index 7e6f392..983648d 100644 --- a/koru-processor/src/jvmMain/kotlin/com/futuremind/koru/processor/builders/WrapperClassBuilder.kt +++ b/koru-processor/src/jvmMain/kotlin/com/futuremind/koru/processor/builders/WrapperClassBuilder.kt @@ -19,6 +19,7 @@ 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 constructorSpec = FunSpec @@ -132,7 +133,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) From 21cad6519a34023c6e60f8b7551b04cec2024f54 Mon Sep 17 00:00:00 2001 From: marty-suzuki Date: Tue, 15 Aug 2023 17:32:35 +0900 Subject: [PATCH 2/5] replace FlowWrapper::class to TypeName --- .../futuremind/koru/processor/builders/WrapperClassBuilder.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/koru-processor/src/jvmMain/kotlin/com/futuremind/koru/processor/builders/WrapperClassBuilder.kt b/koru-processor/src/jvmMain/kotlin/com/futuremind/koru/processor/builders/WrapperClassBuilder.kt index 983648d..1887d9c 100644 --- a/koru-processor/src/jvmMain/kotlin/com/futuremind/koru/processor/builders/WrapperClassBuilder.kt +++ b/koru-processor/src/jvmMain/kotlin/com/futuremind/koru/processor/builders/WrapperClassBuilder.kt @@ -20,6 +20,7 @@ class WrapperClassBuilder( 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 @@ -150,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})") From 7a05ff71fd492d321327f0b72bcf98c64205bbb4 Mon Sep 17 00:00:00 2001 From: marty-suzuki Date: Tue, 15 Aug 2023 23:07:25 +0900 Subject: [PATCH 3/5] fix CompilerPlugin --- .../futuremind/koru/gradle/CompilerPlugin.kt | 57 +++---------------- 1 file changed, 9 insertions(+), 48 deletions(-) diff --git a/koru-compiler-plugin/src/main/kotlin/com/futuremind/koru/gradle/CompilerPlugin.kt b/koru-compiler-plugin/src/main/kotlin/com/futuremind/koru/gradle/CompilerPlugin.kt index 38a5fd7..f42028f 100644 --- a/koru-compiler-plugin/src/main/kotlin/com/futuremind/koru/gradle/CompilerPlugin.kt +++ b/koru-compiler-plugin/src/main/kotlin/com/futuremind/koru/gradle/CompilerPlugin.kt @@ -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 { override fun apply(project: Project) = with(project) { - val extension: KoruPluginExtension = extensions.create("koru") requireKspPluginDependency() - enableKspRunForCommonMainSourceSet() - makeSureCompilationIsRunAfterKsp() afterEvaluate { - requireSourceSetsNamesSet(extension.nativeSourceSetNames) - addGeneratedFilesToSourceSets(extension.nativeSourceSetNames) + enableKspRunForAppleSourceSet() } } @@ -28,45 +21,13 @@ class CompilerPlugin : Plugin { } } - 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) { - 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) { - val anyMatch = extensions - .getByType().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().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 = listOf() -} - - +} \ No newline at end of file From b8f00347c44aa46d5542f88813f07679729b8c4b Mon Sep 17 00:00:00 2001 From: marty-suzuki Date: Tue, 15 Aug 2023 23:09:40 +0900 Subject: [PATCH 4/5] replace version 0.12.0 to 0.13.0 --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index c468c4d..8d7e2a4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,7 +2,7 @@ rootProject.name = "Koru" gradle.allprojects { group = "com.futuremind" - version = "0.12.0" + version = "0.13.0" } includeBuild("publish-plugin") From 4b60a59af9b1d7cd3bfa6ee89fbdf48564854616 Mon Sep 17 00:00:00 2001 From: marty-suzuki Date: Wed, 16 Aug 2023 11:07:50 +0900 Subject: [PATCH 5/5] fix README.md --- README.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6ab1bae..4dc10b3 100644 --- a/README.md +++ b/README.md @@ -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 { @@ -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") } } @@ -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") -} ```