From 50f482e50f6c084a1b5eadfcfd894324516c3ac5 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Wed, 30 Sep 2015 15:42:36 +0200 Subject: [PATCH] Fixing problem of hanging wait for jps process in idea by using a native-platform lib for platform-specific daemon execution Adding native-platform uberjar contents to kotlin jps plugin jar --- .idea/artifacts/KotlinJpsPlugin.xml | 1 + .idea/libraries/native_platform_uberjar.xml | 9 ++++ build.xml | 2 + compiler/rmi/kotlinr/kotlinr.iml | 1 + .../rmi/kotlinr/KotlinCompilerClient.kt | 33 ++++++++----- update_dependencies.xml | 48 ++++++++++++++++++- 6 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 .idea/libraries/native_platform_uberjar.xml diff --git a/.idea/artifacts/KotlinJpsPlugin.xml b/.idea/artifacts/KotlinJpsPlugin.xml index 0f5cf9c7ddc..92d7cf797b0 100644 --- a/.idea/artifacts/KotlinJpsPlugin.xml +++ b/.idea/artifacts/KotlinJpsPlugin.xml @@ -22,6 +22,7 @@ + \ No newline at end of file diff --git a/.idea/libraries/native_platform_uberjar.xml b/.idea/libraries/native_platform_uberjar.xml new file mode 100644 index 00000000000..3a2818f2f9c --- /dev/null +++ b/.idea/libraries/native_platform_uberjar.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/build.xml b/build.xml index 14df58c77d4..256effa9ebd 100644 --- a/build.xml +++ b/build.xml @@ -592,11 +592,13 @@ + + diff --git a/compiler/rmi/kotlinr/kotlinr.iml b/compiler/rmi/kotlinr/kotlinr.iml index ec2851d6574..430bec4b135 100644 --- a/compiler/rmi/kotlinr/kotlinr.iml +++ b/compiler/rmi/kotlinr/kotlinr.iml @@ -11,5 +11,6 @@ + \ No newline at end of file diff --git a/compiler/rmi/kotlinr/src/org/jetbrains/kotlin/rmi/kotlinr/KotlinCompilerClient.kt b/compiler/rmi/kotlinr/src/org/jetbrains/kotlin/rmi/kotlinr/KotlinCompilerClient.kt index d02a8b7017e..461555f221f 100644 --- a/compiler/rmi/kotlinr/src/org/jetbrains/kotlin/rmi/kotlinr/KotlinCompilerClient.kt +++ b/compiler/rmi/kotlinr/src/org/jetbrains/kotlin/rmi/kotlinr/KotlinCompilerClient.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.rmi.kotlinr +import net.rubygrapefruit.platform.ProcessLauncher import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents import org.jetbrains.kotlin.progress.CompilationCanceledStatus import org.jetbrains.kotlin.rmi.* @@ -317,31 +318,41 @@ public object KotlinCompilerClient { } // TODO add os detection to specify option more precisely val platformSpecificOptions = listOf("-Djava.awt.headless=true") // hide daemon in OS X - val args = listOf(javaExecutable.absolutePath, "-cp", compilerId.compilerClasspath.joinToString(File.pathSeparator)) + + val args = listOf( + javaExecutable.absolutePath, "-cp", compilerId.compilerClasspath.joinToString(File.pathSeparator)) + platformSpecificOptions + daemonJVMOptions.mappers.flatMap { it.toArgs("-") } + COMPILER_DAEMON_CLASS_FQN + daemonOptions.mappers.flatMap { it.toArgs(COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) } + compilerId.mappers.flatMap { it.toArgs(COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) } reportingTargets.report(DaemonReportCategory.DEBUG, "starting the daemon as: " + args.joinToString(" ")) - val processBuilder = ProcessBuilder(args).redirectErrorStream(true) + val processBuilder = ProcessBuilder(args) + processBuilder.redirectErrorStream(true) // assuming daemon process is deaf and (mostly) silent, so do not handle streams - val daemon = processBuilder.start() + val daemonLauncher = net.rubygrapefruit.platform.Native.get(ProcessLauncher::class.java) + val daemon = daemonLauncher.start(processBuilder) var isEchoRead = Semaphore(1) isEchoRead.acquire() val stdoutThread = thread { - daemon.inputStream - .reader() - .forEachLine { - if (daemonOptions.runFilesPath.isNotEmpty() && it.contains(daemonOptions.runFilesPath)) { - isEchoRead.release() - return@forEachLine + try { + daemon.inputStream + .reader() + .forEachLine { + if (daemonOptions.runFilesPath.isNotEmpty() && it.contains(daemonOptions.runFilesPath)) { + isEchoRead.release() + return@forEachLine + } + reportingTargets.report(DaemonReportCategory.DEBUG, it, "daemon") } - reportingTargets.report(DaemonReportCategory.DEBUG, it, "daemon") - } + } + finally { + daemon.inputStream.close() + daemon.outputStream.close() + daemon.errorStream.close() + } } try { // trying to wait for process diff --git a/update_dependencies.xml b/update_dependencies.xml index cdfb06e5d4b..6f59198f3a4 100644 --- a/update_dependencies.xml +++ b/update_dependencies.xml @@ -45,6 +45,10 @@ + + + + @@ -118,8 +122,50 @@ + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + +