incremental compilation via daemon

This commit is contained in:
ligee
2015-08-11 15:44:30 +02:00
committed by Ilya Chernikov
parent 06b3ca8343
commit b55894499f
8 changed files with 117 additions and 21 deletions
+1
View File
@@ -9,5 +9,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlin-runtime" level="project" />
<orderEntry type="module" module-name="rmi-interface" />
<orderEntry type="module" module-name="frontend.java" />
</component>
</module>
@@ -16,14 +16,17 @@
package org.jetbrains.kotlin.rmi.kotlinr
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.rmi.CompilerFacade
import java.io.OutputStream
import java.rmi.registry.LocateRegistry
import kotlin.platform.platformStatic
public class KotlinCompilerClient {
companion object {
platformStatic public fun main(vararg args: String) {
public fun connectToCompilerServer(): CompilerFacade? {
val compilerObj = LocateRegistry.getRegistry("localhost", 17031).lookup("KotlinJvmCompilerService")
if (compilerObj == null)
println("Unable to find compiler service")
@@ -31,19 +34,39 @@ public class KotlinCompilerClient {
val compiler = compilerObj as? CompilerFacade
if (compiler == null)
println("Unable to cast compiler service: ${compilerObj.javaClass}")
else {
return compiler
}
return null
}
public fun incrementalCompile(compiler: CompilerFacade, args: Array<String>, caches: Map<String, IncrementalCache>, out: OutputStream): Int {
val outStrm = RemoteOutputStreamServer(out)
val cacheServers = hashMapOf<String, RemoteIncrementalCacheServer>()
try {
caches.forEach { cacheServers.put( it.getKey(), RemoteIncrementalCacheServer( it.getValue())) }
val res = compiler.remoteIncrementalCompile(args, cacheServers, outStrm, CompilerFacade.OutputFormat.XML)
return res
}
finally {
cacheServers.forEach { it.getValue().disconnect() }
outStrm.disconnect()
}
}
platformStatic public fun main(vararg args: String) {
connectToCompilerServer()?.let {
println("Executing daemon compilation with args: " + args.joinToString(" "))
val outStrm = RemoteOutputStreamServer(System.out)
try {
val res = compiler.remoteCompile(args, outStrm, CompilerFacade.OutputFormat.PLAIN)
val res = it.remoteCompile(args, outStrm, CompilerFacade.OutputFormat.PLAIN)
println("Compilation result code: $res")
}
finally {
outStrm.close()
outStrm.disconnect()
}
}
}
}
}
}
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.rmi.kotlinr
import org.jetbrains.kotlin.rmi.CompilerFacade
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache;
import java.rmi.server.UnicastRemoteObject
public class RemoteIncrementalCacheServer(val cache: IncrementalCache) : CompilerFacade.RemoteIncrementalCache {
init {
UnicastRemoteObject.exportObject(this, 0)
}
override fun getObsoletePackageParts(): Collection<String> = cache.getObsoletePackageParts()
override fun getPackageData(fqName: String): ByteArray? = cache.getPackageData(fqName)
override fun close() {
cache.close()
}
public fun disconnect() {
UnicastRemoteObject.unexportObject(this, true)
}
}
@@ -27,9 +27,12 @@ class RemoteOutputStreamServer(val out: OutputStream) : RemoteOutputStream {
UnicastRemoteObject.exportObject(this, 0)
}
public fun disconnect() {
UnicastRemoteObject.unexportObject(this, true)
}
override fun close() {
out.close()
UnicastRemoteObject.unexportObject(this, true)
}
override fun write(data: ByteArray, start: Int, length: Int) {
@@ -7,6 +7,7 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlin-runtime" level="project" />
<orderEntry type="module" module-name="cli-common" />
<orderEntry type="module" module-name="frontend.java" />
</component>