Move daemon session flag files to daemon discovery dir by default + minor fixes:

- Move flag files from the temp dir, because right now JPS cleans temp dir on each build start. Should fix KT-15707, also may affect KT-15562.
- change compiler runner to allow the fix above
- Fix flag file name filtering
- Fix ifAlive handling on the new compile method in the daemon.
This commit is contained in:
Ilya Chernikov
2017-01-27 19:49:43 +01:00
parent ddbb476211
commit 7c0cdf90cf
5 changed files with 12 additions and 13 deletions
@@ -57,8 +57,7 @@ abstract class KotlinCompilerRunner<in Env : CompilerEnvironment> {
protected abstract fun getDaemonConnection(environment: Env): DaemonConnection
@Synchronized
protected fun newDaemonConnection(compilerId: CompilerId, flagFile: File, environment: Env): DaemonConnection {
val daemonOptions = configureDaemonOptions()
protected fun newDaemonConnection(compilerId: CompilerId, flagFile: File, environment: Env, daemonOptions: DaemonOptions = configureDaemonOptions()): DaemonConnection {
val daemonJVMOptions = configureDaemonJVMOptions(inheritMemoryLimits = true, inheritAdditionalProperties = true)
val daemonReportMessages = ArrayList<DaemonReportMessage>()
@@ -60,7 +60,7 @@ object KotlinCompilerClient {
?.check { !it.isBlank() }
?.let(::File)
?.check(File::exists)
?: makeAutodeletingFlagFile()
?: makeAutodeletingFlagFile(baseDir = File(daemonOptions.runFilesPathOrDefault))
return connectToCompileService(compilerId, flagFile, daemonJVMOptions, daemonOptions, reportingTargets, autostart)
}
@@ -81,10 +81,10 @@ private inline fun tryConnectToDaemon(port: Int, report: (DaemonReportCategory,
return null
}
private const val validFlagFileKeywordChars = "abcdefghijklmnopqrstuvwxyz0123456789-_"
fun makeAutodeletingFlagFile(keyword: String = "compiler-client"): File {
val validChars = "^a-zA-Z0-9-_"
val flagFile = File.createTempFile("kotlin-${keyword.filter { validChars.contains(it) }}-", "-is-running")
fun makeAutodeletingFlagFile(keyword: String = "compiler-client", baseDir: File? = null): File {
val flagFile = File.createTempFile("kotlin-${keyword.filter { validFlagFileKeywordChars.contains(it.toLowerCase()) }}-", "-is-running", baseDir?.takeIf { it.isDirectory && it.exists() })
flagFile.deleteOnExit()
return flagFile
}
@@ -328,7 +328,7 @@ class CompileServiceImpl(
compilationOptions: CompilationOptions,
servicesFacade: CompilerServicesFacadeBase,
compilationResults: CompilationResults?
): CompileService.CallResult<Int> {
): CompileService.CallResult<Int> = ifAlive {
val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions)
val daemonReporter = DaemonMessageReporter(servicesFacade, compilationOptions)
val compilerMode = compilationOptions.compilerMode
@@ -342,10 +342,10 @@ class CompileServiceImpl(
}
catch (e: IllegalArgumentException) {
messageCollector.report(CompilerMessageSeverity.EXCEPTION, e.stackTraceStr, CompilerMessageLocation.NO_LOCATION)
return CompileService.CallResult.Error("Could not deserialize compiler arguments")
return@ifAlive CompileService.CallResult.Error("Could not deserialize compiler arguments")
}
return when (compilerMode) {
return@ifAlive when (compilerMode) {
CompilerMode.JPS_COMPILER -> {
val jpsServicesFacade = servicesFacade as JpsCompilerServicesFacade
@@ -206,10 +206,10 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, environment.messageCollector)
val compilerPath = File(libPath, "kotlin-compiler.jar")
val compilerId = CompilerId.makeCompilerId(compilerPath)
val flagFile = File.createTempFile("kotlin-compiler-jps-session-", "-is-running").apply {
deleteOnExit()
}
jpsDaemonConnection = newDaemonConnection(compilerId, flagFile, environment)
// TODO: pass daemon options to newDaemonConnection
val daemonOptions = configureDaemonOptions()
val flagFile = makeAutodeletingFlagFile("compiler-jps-session-", File(daemonOptions.runFilesPathOrDefault))
jpsDaemonConnection = newDaemonConnection(compilerId, flagFile, environment, daemonOptions)
}
return jpsDaemonConnection!!
}