Get rid of kotlinx-coroutines usage in scripting libs and plugins
the dependency on the coroutines library caused various problems like KT-30778, or stdlib/runtime version conflicts. The only function used was `runBlocking`, so this change replaces it with the internal implementation based on the similar internal thing from the stdlib. #KT-30778 fixed
This commit is contained in:
committed by
TeamCityServer
parent
9b1de90452
commit
0cd29adcc7
+3
-2
@@ -5,7 +5,6 @@
|
||||
|
||||
package kotlin.script.experimental.jvm.impl
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.File
|
||||
import kotlin.script.dependencies.Environment
|
||||
import kotlin.script.dependencies.ScriptContents
|
||||
@@ -16,6 +15,7 @@ import kotlin.script.experimental.dependencies.ScriptDependencies
|
||||
import kotlin.script.experimental.dependencies.ScriptReport
|
||||
import kotlin.script.experimental.host.FileScriptSource
|
||||
import kotlin.script.experimental.host.toScriptSource
|
||||
import kotlin.script.experimental.impl.internalScriptingRunSuspend
|
||||
import kotlin.script.experimental.jvm.JvmDependency
|
||||
import kotlin.script.experimental.jvm.compat.mapToLegacyScriptReportPosition
|
||||
import kotlin.script.experimental.jvm.compat.mapToLegacyScriptReportSeverity
|
||||
@@ -27,7 +27,8 @@ class BridgeDependenciesResolver(
|
||||
) : AsyncDependenciesResolver {
|
||||
|
||||
override fun resolve(scriptContents: ScriptContents, environment: Environment): DependenciesResolver.ResolveResult =
|
||||
runBlocking {
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
internalScriptingRunSuspend {
|
||||
resolveAsync(scriptContents, environment)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
|
||||
package kotlin.script.experimental.jvm
|
||||
|
||||
import kotlin.coroutines.Continuation
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
import kotlin.coroutines.startCoroutine
|
||||
import kotlin.script.experimental.api.*
|
||||
import kotlin.script.experimental.api.ScriptCompilationConfiguration
|
||||
import kotlin.script.experimental.api.baseClass
|
||||
import kotlin.script.experimental.api.hostConfiguration
|
||||
import kotlin.script.experimental.api.onFailure
|
||||
import kotlin.script.experimental.host.createEvaluationConfigurationFromTemplate
|
||||
import kotlin.script.experimental.host.withDefaultsFrom
|
||||
import kotlin.script.experimental.impl.internalScriptingRunSuspend
|
||||
import kotlin.script.experimental.jvm.impl.createScriptFromClassLoader
|
||||
|
||||
@Suppress("unused") // script codegen generates a call to it
|
||||
@@ -29,42 +29,11 @@ fun runCompiledScript(scriptClass: Class<*>, vararg args: String) {
|
||||
mainArguments(args)
|
||||
}
|
||||
}
|
||||
runScriptSuspend {
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
internalScriptingRunSuspend {
|
||||
evaluator(script, evaluationConfiguration).onFailure {
|
||||
it.reports.forEach(System.err::println)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copied form kotlin.coroutines.jvm.internal.runSuspend/RunSuspend to create a runner without dependency on the kotlinx.coroutines
|
||||
private fun runScriptSuspend(block: suspend () -> Unit) {
|
||||
val run = RunScriptSuspend()
|
||||
block.startCoroutine(run)
|
||||
run.await()
|
||||
}
|
||||
|
||||
private class RunScriptSuspend : Continuation<Unit> {
|
||||
override val context: CoroutineContext
|
||||
get() = EmptyCoroutineContext
|
||||
|
||||
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")
|
||||
var result: Result<Unit>? = null
|
||||
|
||||
override fun resumeWith(result: Result<Unit>) = synchronized(this) {
|
||||
this.result = result
|
||||
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") (this as Object).notifyAll()
|
||||
}
|
||||
|
||||
fun await() = synchronized(this) {
|
||||
while (true) {
|
||||
when (val result = this.result) {
|
||||
null -> @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") (this as Object).wait()
|
||||
else -> {
|
||||
result.getOrThrow() // throw up failure
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user