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

Isolate Kotlin compiler instances for Multiplex workers. #515

Merged
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 @@ -163,16 +163,18 @@ class KotlinToolchain private constructor(
toolchain: KotlinToolchain,
clazz: String
) {
private val compiler: Any
private val execMethod: Method
private val getCodeMethod: Method
private val compilerClass = toolchain.classLoader.loadClass(clazz)

init {
val compilerClass = toolchain.classLoader.loadClass(clazz)
// Disables disposing of the environment which is required when running parallel builds. This
// follows the behavior of the Kotlin compiler daemon.
System.setProperty("kotlin.environment.keepalive", "true")

val exitCodeClass =
toolchain.classLoader.loadClass("org.jetbrains.kotlin.cli.common.ExitCode")

compiler = compilerClass.getConstructor().newInstance()
execMethod =
compilerClass.getMethod("exec", PrintStream::class.java, Array<String>::class.java)
getCodeMethod = exitCodeClass.getMethod("getCode")
Expand All @@ -183,6 +185,7 @@ class KotlinToolchain private constructor(
// 2 is an internal error
// 3 is the script execution error
fun compile(args: Array<String>, out: PrintStream): Int {
val compiler = compilerClass.getConstructor().newInstance()
val exitCodeInstance = execMethod.invoke(compiler, out, args)
return getCodeMethod.invoke(exitCodeInstance, *NO_ARGS) as Int
}
Expand Down