Skip to content

Commit ee5ab90

Browse files
authored
Update leftover sources from jvm-only to kmp (#300)
* Move krpc-ktor-server to commonMain * Move krpc-test to commonMain * Move krpc-test tests to commonTest * detekt * PR comments
1 parent 7bfdb56 commit ee5ab90

File tree

45 files changed

+978
-879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+978
-879
lines changed

core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ public class RpcParameter(public val name: String, public val type: RpcType)
8888
@ExperimentalRpcApi
8989
public class RpcType(public val kType: KType) {
9090
override fun toString(): String {
91-
return return kType.toString()
91+
return kType.toString()
9292
}
9393
}

gradle-conventions/common/src/main/kotlin/util/JsTarget.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package util
@@ -40,7 +40,7 @@ fun KotlinJsTargetDsl.configureJsAndWasmJsTasks() {
4040
nodejs {
4141
testTask {
4242
useMocha {
43-
timeout = "10000"
43+
timeout = "100s"
4444
}
4545
}
4646
}

gradle-conventions/common/src/main/kotlin/util/ProjectKotlinConfig.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package util
@@ -38,6 +38,7 @@ class ProjectKotlinConfig(
3838
jvm: Boolean = true,
3939
js: Boolean = true,
4040
wasmJs: Boolean = true,
41+
wasmJsD8: Boolean = true,
4142
wasmWasi: Boolean = true,
4243
val native: Boolean = true,
4344
) : Project by project {
@@ -48,18 +49,18 @@ class ProjectKotlinConfig(
4849

4950
private fun isIncluded(
5051
targetName: String,
51-
kotlinVersion: KotlinVersion,
52-
lookupTable: Map<String, String>,
52+
lookupTable: Map<String, String> = targetsLookup,
5353
): Boolean {
5454
return lookupTable[targetName]?.let { sinceKotlin ->
5555
sinceKotlin == FULLY_SUPPORTED_TARGET || sinceKotlin.kotlinVersionParsed() <= kotlinVersion
5656
} ?: false
5757
}
5858

59-
val jvm: Boolean by lazy { jvm && isIncluded("jvm", kotlinVersion, targetsLookup) }
60-
val js: Boolean by lazy { js && isIncluded("js", kotlinVersion, targetsLookup) }
61-
val wasmJs: Boolean by lazy { wasmJs && isIncluded("wasmJs", kotlinVersion, targetsLookup) }
62-
val wasmWasi: Boolean by lazy { wasmWasi && isIncluded("wasmWasi", kotlinVersion, targetsLookup) }
59+
val jvm: Boolean by lazy { jvm && isIncluded("jvm") }
60+
val js: Boolean by lazy { js && isIncluded("js") }
61+
val wasmJs: Boolean by lazy { wasmJs && isIncluded("wasmJs") }
62+
val wasmJsD8: Boolean by lazy { wasmJsD8 && wasmJs }
63+
val wasmWasi: Boolean by lazy { wasmWasi && isIncluded("wasmWasi") }
6364

6465
private val nativeLookup by lazy {
6566
targetsLookup.filterKeys { key ->
@@ -71,7 +72,6 @@ class ProjectKotlinConfig(
7172
.filter { targetFunction ->
7273
targetFunction.parameters.size == 1 && isIncluded(
7374
targetName = targetFunction.name,
74-
kotlinVersion = kotlinVersion,
7575
lookupTable = nativeLookup,
7676
)
7777
}.map { function ->
@@ -84,6 +84,7 @@ fun Project.withKotlinConfig(configure: ProjectKotlinConfig.() -> Unit) {
8484
val excludeJvm: Boolean by optionalProperty()
8585
val excludeJs: Boolean by optionalProperty()
8686
val excludeWasmJs: Boolean by optionalProperty()
87+
val excludeWasmJsD8: Boolean by optionalProperty()
8788
val excludeWasmWasi: Boolean by optionalProperty()
8889
val excludeNative: Boolean by optionalProperty()
8990

@@ -93,6 +94,7 @@ fun Project.withKotlinConfig(configure: ProjectKotlinConfig.() -> Unit) {
9394
jvm = !excludeJvm,
9495
js = !excludeJs,
9596
wasmJs = !excludeWasmJs,
97+
wasmJsD8 = !excludeWasmJsD8,
9698
wasmWasi = !excludeWasmWasi,
9799
native = !excludeNative,
98100
).configure()

gradle-conventions/src/main/kotlin/util/wasm.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package util
@@ -23,7 +23,9 @@ fun ProjectKotlinConfig.configureWasm() {
2323

2424
browser()
2525
nodejs()
26-
d8()
26+
if (wasmJsD8) {
27+
d8()
28+
}
2729

2830
binaries.library()
2931
}.configurePublication()

krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package kotlinx.rpc.krpc.client
77
import kotlinx.atomicfu.atomic
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.channels.Channel
10-
import kotlinx.coroutines.channels.ClosedReceiveChannelException
1110
import kotlinx.coroutines.flow.Flow
1211
import kotlinx.coroutines.flow.flow
1312
import kotlinx.rpc.RpcCall
@@ -258,9 +257,7 @@ public abstract class KrpcClient(
258257

259258
val id = callCounter.incrementAndGet()
260259

261-
val dataTypeString = callable.dataType.toString()
262-
263-
val callId = "$connectionId:$dataTypeString:$id"
260+
val callId = "$connectionId:${callable.name}:$id"
264261

265262
logger.trace { "start a call[$callId] ${callable.name}" }
266263

@@ -325,9 +322,7 @@ public abstract class KrpcClient(
325322
val callable = call.descriptor.getCallable(call.callableName)
326323
?: error("Unexpected callable '${call.callableName}' for ${call.descriptor.fqName} service")
327324

328-
val dataTypeString = callable.dataType.toString()
329-
330-
val callId = "$connectionId:$dataTypeString:$id"
325+
val callId = "$connectionId:${callable.name}:$id"
331326

332327
val channel = Channel<T>()
333328

krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcConnector.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.internal
@@ -154,9 +154,25 @@ public class KrpcConnector<SubscriptionKey>(
154154
if (waitForSubscribers) {
155155
waiting.getOrPut(message.getKey()) { mutableListOf() }.add(message)
156156

157-
logger.warn {
157+
val reason = when (result) {
158+
is HandlerResult.Failure -> {
159+
"Unhandled exception while processing ${result.cause?.message}"
160+
}
161+
162+
is HandlerResult.NoSubscription -> {
163+
"No service with key '${message.getKey()}' and '${message.serviceType}' type was registered." +
164+
"Available: keys: [${subscriptions.keys.joinToString()}]"
165+
}
166+
167+
else -> {
168+
"Unknown"
169+
}
170+
}
171+
172+
logger.warn((result as? HandlerResult.Failure)?.cause) {
158173
"No registered service of ${message.serviceType} service type " +
159-
"was able to process message at the moment. Waiting for new services."
174+
"was able to process message at the moment. Waiting for new services." +
175+
"Reason: $reason"
160176
}
161177

162178
return

krpc/krpc-ktor/krpc-ktor-core/src/jvmTest/kotlin/kotlinx/rpc/krpc/ktor/KtorTransportTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
@file:Suppress("ExtractKtorModule")
@@ -31,6 +31,7 @@ class NewServiceImpl(
3131
override val coroutineContext: CoroutineContext,
3232
private val call: ApplicationCall,
3333
) : NewService {
34+
@Suppress("UastIncorrectHttpHeaderInspection")
3435
override suspend fun echo(value: String): String {
3536
assertEquals("test-header", call.request.headers["TestHeader"])
3637
return value

krpc/krpc-ktor/krpc-ktor-server/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
plugins {
@@ -9,7 +9,7 @@ plugins {
99

1010
kotlin {
1111
sourceSets {
12-
jvmMain {
12+
commonMain {
1313
dependencies {
1414
api(projects.krpc.krpcServer)
1515
api(projects.krpc.krpcKtor.krpcKtorCore)

krpc/krpc-ktor/krpc-ktor-server/gradle.properties

Lines changed: 0 additions & 6 deletions
This file was deleted.

krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/Krpc.kt renamed to krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/Krpc.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.ktor.server

0 commit comments

Comments
 (0)