@@ -11,15 +11,15 @@ import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
11
11
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
12
12
import org.jetbrains.kotlin.cli.js.K2JSCompiler
13
13
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
14
+ import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
14
15
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
16
+ import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
15
17
import org.jetbrains.kotlin.config.Services
16
18
import org.jetbrains.kotlin.load.java.JvmAbi
17
19
import org.jetbrains.kotlin.util.ServiceLoaderLite
18
20
import java.io.File
19
21
import java.io.OutputStream
20
22
import java.io.PrintStream
21
- import java.lang.reflect.InvocationTargetException
22
- import java.lang.reflect.ReflectPermission
23
23
import java.net.URI
24
24
import java.nio.file.Files
25
25
import java.nio.file.Paths
@@ -29,6 +29,7 @@ import java.nio.file.Paths
29
29
* functionality. Should not be used outside of this library as it is an
30
30
* implementation detail.
31
31
*/
32
+ @ExperimentalCompilerApi
32
33
abstract class AbstractKotlinCompilation <A : CommonCompilerArguments > internal constructor() {
33
34
/* * Working directory for the compilation */
34
35
var workingDir: File by default {
@@ -49,10 +50,29 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
49
50
*/
50
51
var pluginClasspaths: List <File > = emptyList()
51
52
53
+
54
+ @Suppress(" DEPRECATION" )
55
+ @Deprecated(
56
+ " Renamed to componentRegistrars due to introduction of CompilerPluginRegistrar" ,
57
+ ReplaceWith (" componentRegistrars" ),
58
+ DeprecationLevel .ERROR
59
+ )
60
+ var compilerPlugins: List <ComponentRegistrar > = emptyList()
61
+
62
+
63
+
64
+ /* *
65
+ * Legacy compiler plugins that should be added to the compilation.
66
+ * This option will be removed in the future; you should migrate to [CompilerPluginRegistrar].
67
+ */
68
+ @Suppress(" DEPRECATION" )
69
+ @Deprecated(" Deprecated in Kotlin compiler. Migrate to compilerPluginRegistrars instead" )
70
+ var componentRegistrars: List <ComponentRegistrar > = emptyList()
71
+
52
72
/* *
53
73
* Compiler plugins that should be added to the compilation
54
74
*/
55
- var compilerPlugins : List <ComponentRegistrar > = emptyList()
75
+ var compilerPluginRegistrars : List <CompilerPluginRegistrar > = emptyList()
56
76
57
77
/* *
58
78
* Commandline processors for compiler plugins that should be added to the compilation
@@ -115,6 +135,9 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
115
135
HostEnvironment .kotlinStdLibCommonJar
116
136
}
117
137
138
+ /* * Enable support for the new K2 compiler. */
139
+ var supportsK2 = false
140
+
118
141
// Directory for input source files
119
142
protected val sourcesDir get() = workingDir.resolve(" sources" )
120
143
@@ -188,11 +211,14 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
188
211
* To avoid that the annotation processors are executed twice,
189
212
* the list is set to empty
190
213
*/
191
- MainComponentRegistrar .threadLocalParameters.set(
192
- MainComponentRegistrar .ThreadLocalParameters (
214
+ @Suppress(" DEPRECATION" )
215
+ MainComponentAndPluginRegistrar .threadLocalParameters.set(
216
+ MainComponentAndPluginRegistrar .ThreadLocalParameters (
193
217
listOf (),
194
218
KaptOptions .Builder (),
195
- compilerPlugins
219
+ componentRegistrars,
220
+ compilerPluginRegistrars,
221
+ supportsK2
196
222
)
197
223
)
198
224
@@ -207,14 +233,15 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
207
233
} else {
208
234
emptyList()
209
235
}
236
+ @Suppress(" DEPRECATION" )
210
237
args.pluginClasspaths = (args.pluginClasspaths ? : emptyArray()) +
211
238
/* * The resources path contains the MainComponentRegistrar and MainCommandLineProcessor which will
212
239
be found by the Kotlin compiler's service loader. We add it only when the user has actually given
213
240
us ComponentRegistrar instances to be loaded by the MainComponentRegistrar because the experimental
214
241
K2 compiler doesn't support plugins yet. This way, users of K2 can prevent MainComponentRegistrar
215
- from being loaded and crashing K2 by setting both [compilerPlugins ] and [commandLineProcessors] to
216
- the emptyList. */
217
- if (compilerPlugins.isNotEmpty() || commandLineProcessors.isNotEmpty())
242
+ from being loaded and crashing K2 by setting both [componentRegistrars ] and [commandLineProcessors]
243
+ and [compilerPluginRegistrars] to the emptyList. */
244
+ if (componentRegistrars.union(compilerPluginRegistrars).union( commandLineProcessors) .isNotEmpty())
218
245
arrayOf(getResourcesPath())
219
246
else emptyArray()
220
247
}
@@ -229,7 +256,7 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
229
256
}
230
257
231
258
protected fun getResourcesPath (): String {
232
- val resourceName = " META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar "
259
+ val resourceName = " META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar "
233
260
return this ::class .java.classLoader.getResources(resourceName)
234
261
.asSequence()
235
262
.mapNotNull { url ->
@@ -241,9 +268,9 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
241
268
}.toAbsolutePath()
242
269
}
243
270
.find { resourcesPath ->
244
- ServiceLoaderLite .findImplementations(ComponentRegistrar ::class .java, listOf (resourcesPath.toFile()))
245
- .any { implementation -> implementation == MainComponentRegistrar ::class .java.name }
246
- }?.toString() ? : throw AssertionError (" Could not get path to ComponentRegistrar service from META-INF" )
271
+ ServiceLoaderLite .findImplementations(CompilerPluginRegistrar ::class .java, listOf (resourcesPath.toFile()))
272
+ .any { implementation -> implementation == MainComponentAndPluginRegistrar ::class .java.name }
273
+ }?.toString() ? : throw AssertionError (" Could not get path to CompilerPluginRegistrar service from META-INF" )
247
274
}
248
275
249
276
/* * Searches compiler log for known errors that are hard to debug for the user */
@@ -298,7 +325,6 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
298
325
299
326
internal fun convertKotlinExitCode (code : ExitCode ) = when (code) {
300
327
ExitCode .OK -> KotlinCompilation .ExitCode .OK
301
- ExitCode .OOM_ERROR ,
302
328
ExitCode .INTERNAL_ERROR -> KotlinCompilation .ExitCode .INTERNAL_ERROR
303
329
ExitCode .COMPILATION_ERROR -> KotlinCompilation .ExitCode .COMPILATION_ERROR
304
330
ExitCode .SCRIPT_EXECUTION_ERROR -> KotlinCompilation .ExitCode .SCRIPT_EXECUTION_ERROR
0 commit comments