@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
10
10
import org.jetbrains.kotlin.cli.common.arguments.cliArgument
11
11
import org.jetbrains.kotlin.cli.js.K2JSCompiler
12
12
import org.jetbrains.kotlin.js.test.ir.AbstractJsCompilerInvocationTest.CompilerType
13
+ import org.jetbrains.kotlin.js.test.klib.JsKlibTestSettings
13
14
import org.jetbrains.kotlin.js.testOld.V8JsTestChecker
14
15
import org.jetbrains.kotlin.klib.KlibCompilerEdition
15
16
import org.jetbrains.kotlin.klib.KlibCompilerInvocationTestUtils
@@ -22,8 +23,6 @@ import org.junit.jupiter.api.AfterEach
22
23
import java.io.ByteArrayOutputStream
23
24
import java.io.File
24
25
import java.io.PrintStream
25
- import java.lang.ref.SoftReference
26
- import java.net.URLClassLoader
27
26
import kotlin.io.path.createTempDirectory
28
27
29
28
/* *
@@ -59,72 +58,14 @@ private class ModuleDetails(val name: ModuleName, val outputDir: File) {
59
58
constructor (dependency: Dependency ) : this (dependency.moduleName, dependency.libraryFile.parentFile)
60
59
}
61
60
62
- private fun customCompilerCall (): (PrintStream , Array <String >) -> ExitCode {
63
- val customCompiler = JsKlibTestSettings .customJsCompiler
64
-
65
- val compilerClass = Class .forName(" org.jetbrains.kotlin.cli.js.K2JSCompiler" , true , customCompiler.classLoader)
66
- val entryPoint = compilerClass.getMethod(
67
- " execFullPathsInMessages" ,
68
- PrintStream ::class .java,
69
- Array <String >::class .java
70
- )
71
-
72
- return { printStream: PrintStream , allCompilerArgs: Array <String > ->
73
- val result = entryPoint.invoke(compilerClass.getDeclaredConstructor().newInstance(), printStream, allCompilerArgs)
74
- ExitCode .valueOf(result.toString())
75
- }
61
+ private fun customCompilerCall (): (PrintStream , Array <String >) -> ExitCode = { printStream: PrintStream , allCompilerArgs: Array <String > ->
62
+ JsKlibTestSettings .customJsCompiler.callCompiler(args = allCompilerArgs, output = printStream)
76
63
}
77
64
78
65
private fun currentCompilerCall () = { printStream: PrintStream , args: Array <String > ->
79
66
K2JSCompiler ().execFullPathsInMessages(printStream, args)
80
67
}
81
68
82
- internal class CustomJsCompiler (private val jsHome : CustomJsCompilerArtifacts ) {
83
- private var softClassLoader: SoftReference <URLClassLoader >? = null
84
- val classLoader: URLClassLoader
85
- get() {
86
- return softClassLoader?.get() ? : synchronized(this ) {
87
- softClassLoader?.get() ? : createClassLoader(jsHome).also {
88
- softClassLoader = SoftReference (it)
89
- }
90
- }
91
- }
92
- }
93
-
94
- private fun createClassLoader (jsHome : CustomJsCompilerArtifacts ): URLClassLoader {
95
- val jsClassPath = setOf (
96
- jsHome.compilerEmbeddable,
97
- jsHome.baseStdLib,
98
- )
99
- .map { it.toURI().toURL() }
100
- .toTypedArray()
101
-
102
- return URLClassLoader (jsClassPath, null )
103
- .apply { setDefaultAssertionStatus(true ) }
104
- }
105
-
106
- internal class CustomJsCompilerArtifacts (val dir : File , version : String ) {
107
- val compilerEmbeddable: File = dir.resolve(" kotlin-compiler-embeddable-$version .jar" )
108
- val baseStdLib: File = dir.resolve(" kotlin-stdlib-$version .jar" )
109
- val jsStdLib: File = dir.resolve(" kotlin-stdlib-js-$version .klib" )
110
- }
111
-
112
- internal object JsKlibTestSettings {
113
- val customJsCompilerArtifacts by lazy {
114
- val location = System .getProperty(" kotlin.internal.js.test.compat.customCompilerArtifactsDir" )
115
- requireNotNull(location) { " Custom compiler location is not specified" }
116
-
117
- val version = System .getProperty(" kotlin.internal.js.test.compat.customCompilerVersion" )
118
- requireNotNull(version) { " Custom compiler version is not specified" }
119
-
120
- CustomJsCompilerArtifacts (File (location), version)
121
- }
122
-
123
- val customJsCompiler by lazy {
124
- CustomJsCompiler (customJsCompilerArtifacts)
125
- }
126
- }
127
-
128
69
internal class JsCompilerInvocationTestConfiguration (
129
70
override val buildDir : File ,
130
71
val compilerType : CompilerType ,
0 commit comments