[K/N][gradle] Automatic cleaning of the class loaders map
This commit is contained in:
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.CompareDistributionSignatures
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
import org.jetbrains.kotlin.UtilsKt
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
buildscript {
|
||||
apply from: "gradle/kotlinGradlePlugin.gradle"
|
||||
@@ -95,6 +96,9 @@ ext {
|
||||
|
||||
konanVersionFull = ext.kotlinNativeVersion
|
||||
gradlePluginVersion = konanVersionFull
|
||||
|
||||
// A separate map for each build for automatic cleaning the daemon after the build have finished.
|
||||
toolClassLoadersMap = new ConcurrentHashMap<Object, URLClassLoader>()
|
||||
}
|
||||
|
||||
allprojects {
|
||||
|
||||
+12
-2
@@ -28,6 +28,8 @@ import java.io.File
|
||||
import java.util.Properties
|
||||
import org.jetbrains.kotlin.compilerRunner.KotlinToolRunner
|
||||
import org.jetbrains.kotlin.konan.target.AbstractToolConfig
|
||||
import java.net.URLClassLoader
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
internal interface KonanToolRunner {
|
||||
fun run(args: List<String>)
|
||||
@@ -68,10 +70,15 @@ internal abstract class KonanCliRunner(
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
data class IsolatedClassLoaderCacheKey(val classpath: Set<java.io.File>, val project: Project)
|
||||
data class IsolatedClassLoaderCacheKey(val classpath: Set<File>)
|
||||
|
||||
// TODO: can't we use this for other implementations too?
|
||||
final override val isolatedClassLoaderCacheKey get() = IsolatedClassLoaderCacheKey(classpath, project)
|
||||
final override val isolatedClassLoaderCacheKey get() = IsolatedClassLoaderCacheKey(classpath)
|
||||
|
||||
// A separate map for each build for automatic cleaning the daemon after the build have finished.
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
final override val isolatedClassLoaders get() =
|
||||
project.project(":kotlin-native").ext["toolClassLoadersMap"] as ConcurrentHashMap<Any, URLClassLoader>
|
||||
|
||||
override fun transformArgs(args: List<String>) = listOf(toolName) + args
|
||||
|
||||
@@ -110,6 +117,9 @@ private val load0 = Runtime::class.java.getDeclaredMethod("load0", Class::class.
|
||||
|
||||
internal class CliToolConfig(konanHome: String, target: String) : AbstractToolConfig(konanHome, target, emptyMap()) {
|
||||
override fun loadLibclang() {
|
||||
// Load libclang into the system class loader. This is needed to allow developers to make changes
|
||||
// in the tooling infrastructure without having to stop the daemon (otherwise libclang might end up
|
||||
// loaded in two different class loaders which is not allowed by the JVM).
|
||||
load0.invoke(Runtime.getRuntime(), String::class.java, libclang)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user