@@ -28,7 +28,6 @@ import org.gradle.process.ExecOperations
28
28
import org.gradle.workers.WorkerExecutor
29
29
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporter
30
30
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporterImpl
31
- import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
32
31
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
33
32
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
34
33
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
@@ -52,6 +51,13 @@ import org.jetbrains.kotlin.utils.JsLibraryUtils
52
51
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
53
52
import java.io.File
54
53
import javax.inject.Inject
54
+ import org.jetbrains.kotlin.gradle.dsl.CompilerCommonOptions
55
+ import org.jetbrains.kotlin.gradle.dsl.CompilerCommonOptionsDefault
56
+ import org.jetbrains.kotlin.gradle.dsl.CompilerJsOptions
57
+ import org.jetbrains.kotlin.gradle.dsl.CompilerJsOptionsDefault
58
+ import org.jetbrains.kotlin.gradle.dsl.CompilerJvmOptions
59
+ import org.jetbrains.kotlin.gradle.dsl.CompilerJvmOptionsDefault
60
+ import org.jetbrains.kotlin.gradle.logging.GradleErrorMessageCollector
55
61
56
62
internal inline fun <reified T : Any ? > ObjectFactory.property () = property(T ::class .java)
57
63
internal inline fun <reified T : Any ? > ObjectFactory.property (initialValue : T ) = property<T >().value(initialValue)
@@ -86,9 +92,10 @@ abstract class KotlinCompilerRunnerImpl @Inject constructor(
86
92
@Internal
87
93
internal fun prepareEnvironment (allWarningsAsErrors : Boolean , outputs : List <File >): GradleCompilerEnvironment {
88
94
val messageCollector = GradlePrintingMessageCollector (GradleKotlinLogger (logger), allWarningsAsErrors)
95
+ val errorMessageCollector = GradleErrorMessageCollector (messageCollector)
89
96
val outputItemCollector = OutputItemsCollectorImpl ()
90
97
return GradleCompilerEnvironment (
91
- compilerClasspath.files.toList(), messageCollector , outputItemCollector,
98
+ compilerClasspath.files.toList(), errorMessageCollector , outputItemCollector,
92
99
reportingSettings = ReportingSettings (),
93
100
outputFiles = outputs
94
101
)
@@ -110,49 +117,32 @@ abstract class KotlinCompilerRunnerImpl @Inject constructor(
110
117
}
111
118
}
112
119
113
- internal fun CommonCompilerArguments.copyFrom (args : KotlinCompilerArguments ) {
114
- freeArgs = args.freeArgs
115
- verbose = args.verbose
116
- allWarningsAsErrors = args.allWarningsAsErrors
117
- languageVersion = args.languageVersion
118
- apiVersion = args.apiVersion
119
- useK2 = args.useK2
120
- incrementalCompilation = args.incrementalCompilation
121
- pluginOptions = args.pluginOptions.toTypedArray()
122
- pluginClasspaths = args.pluginClasspaths.map { it.absolutePath }.toTypedArray()
123
- expectActualLinker = args.expectActualLinker
124
- multiPlatform = args.multiPlatform
125
- }
126
-
127
120
abstract class KotlinJvmCompilerRunnerImpl @Inject constructor(
128
121
task : Task ,
129
122
objectFactory : ObjectFactory ,
130
123
workerExecutor : WorkerExecutor
131
124
) : KotlinCompilerRunnerImpl(task, objectFactory, workerExecutor), KotlinJvmCompilerRunner {
132
125
133
126
override fun runJvmCompilerAsync (
134
- args : KotlinJvmCompilerArguments ,
127
+ options : CompilerJvmOptions ,
128
+ freeArgs : List <String >,
135
129
sources : List <File >,
136
130
commonSources : List <File >,
137
- outputs : List <File >
131
+ friendPaths : List <File >,
132
+ libraries : List <File >,
133
+ outputs : List <File >,
134
+ destination : File
138
135
) {
139
- val environment = prepareEnvironment(args .allWarningsAsErrors, outputs)
136
+ val environment = prepareEnvironment(options .allWarningsAsErrors.get() , outputs)
140
137
val compilerRunner = prepareCompilerRunner()
141
138
val compilerArgs = K2JVMCompilerArguments ().apply {
142
- copyFrom(args)
143
-
144
- friendPaths = args.friendPaths.map { it.absolutePath }.toTypedArray()
145
- classpath = args.libraries.map { it.absolutePath }.joinToString(File .pathSeparator)
146
- destination = args.destination?.absolutePath
147
-
148
- noJdk = args.noJdk
149
- noStdlib = args.noStdlib
150
- noReflect = args.noReflect
151
- moduleName = args.moduleName
152
- jvmTarget = args.jvmTarget
153
- jdkRelease = args.jdkRelease
154
- allowNoSourceFiles = args.allowNoSourceFiles
155
- javaSourceRoots = args.javaSourceRoots.map { it.absolutePath }.toTypedArray()
139
+ options as CompilerJvmOptionsDefault
140
+ options.fillCompilerArguments(this )
141
+
142
+ this @apply.friendPaths = friendPaths.map { it.absolutePath }.toTypedArray()
143
+ this @apply.classpath = libraries.map { it.absolutePath }.joinToString(File .pathSeparator)
144
+ this @apply.freeArgs = options.freeCompilerArgs.get() + freeArgs
145
+ this @apply.destination = destination.absolutePath
156
146
}
157
147
158
148
compilerRunner.runJvmCompilerAsync(
@@ -191,30 +181,34 @@ abstract class KotlinJsCompilerRunnerImpl @Inject constructor(
191
181
}
192
182
193
183
override fun runJsCompilerAsync (
194
- args : KotlinJsCompilerArguments ,
184
+ options : CompilerJsOptions ,
185
+ freeArgs : List <String >,
195
186
sources : List <File >,
196
187
commonSources : List <File >,
197
- outputs : List <File >
188
+ friendPaths : List <File >,
189
+ libraries : List <File >,
190
+ outputs : List <File >,
191
+ destination : File
198
192
) {
199
- val environment = prepareEnvironment(args .allWarningsAsErrors, outputs)
193
+ val environment = prepareEnvironment(options .allWarningsAsErrors.get() , outputs)
200
194
val compilerRunner = prepareCompilerRunner()
201
195
val compilerArgs = K2JSCompilerArguments ().apply {
202
- copyFrom(args)
196
+ options as CompilerJsOptionsDefault
197
+ options.fillCompilerArguments(this )
203
198
204
- outputFile = args.destination?.absolutePath
199
+ this @apply.freeArgs = options.freeCompilerArgs.get() + freeArgs
200
+ this @apply.outputFile = destination.absolutePath
205
201
206
- noStdlib = args.noStdlib
207
- irOnly = args.irOnly
208
- irProduceJs = args.irProduceJs
209
- irProduceKlibDir = args.irProduceKlibDir
210
- irProduceKlibFile = args.irProduceKlibFile
211
- irBuildCache = args.irBuildCache
212
- wasm = args.wasm
213
- target = args.target
202
+ irOnly = this @apply.freeArgs.contains(" -Xir-only" )
203
+ irProduceJs = this @apply.freeArgs.contains(" -Xir-produce-js" )
204
+ irProduceKlibDir = this @apply.freeArgs.contains(" -Xir-produce-klib-dir" )
205
+ irProduceKlibFile = this @apply.freeArgs.contains(" -Xir-produce-klib-file" )
206
+ irBuildCache = this @apply.freeArgs.contains(" -Xir-build-cache" )
207
+ wasm = this @apply.freeArgs.contains(" -Xwasm" )
214
208
215
- friendModules = args. friendPaths.filter { libFilter(this , it) }
209
+ this @apply. friendModules = friendPaths.filter { libFilter(this , it) }
216
210
.map { it.absolutePath }.joinToString(File .pathSeparator)
217
- libraries = args. libraries.filter { libFilter(this , it) }
211
+ this @apply. libraries = libraries.filter { libFilter(this , it) }
218
212
.map { it.absolutePath }.joinToString(File .pathSeparator)
219
213
}
220
214
@@ -229,19 +223,25 @@ abstract class KotlinMetadataCompilerRunnerImpl @Inject constructor(
229
223
) : KotlinCompilerRunnerImpl(task, objectFactory, workerExecutor), KotlinMetadataCompilerRunner {
230
224
231
225
override fun runMetadataCompilerAsync (
232
- args : KotlinMetadataCompilerArguments ,
226
+ options : CompilerCommonOptions ,
227
+ freeArgs : List <String >,
233
228
sources : List <File >,
234
229
commonSources : List <File >,
235
- outputs : List <File >
230
+ friendPaths : List <File >,
231
+ libraries : List <File >,
232
+ outputs : List <File >,
233
+ destination : File
236
234
) {
237
- val environment = prepareEnvironment(args .allWarningsAsErrors, outputs)
235
+ val environment = prepareEnvironment(options .allWarningsAsErrors.get() , outputs)
238
236
val compilerRunner = prepareCompilerRunner()
239
237
val compilerArgs = K2MetadataCompilerArguments ().apply {
240
- copyFrom(args)
238
+ options as CompilerCommonOptionsDefault
239
+ options.fillCompilerArguments(this )
241
240
242
- friendPaths = args.friendPaths.map { it.absolutePath }.toTypedArray()
243
- classpath = args.libraries.map { it.absolutePath }.joinToString(File .pathSeparator)
244
- destination = args.destination?.absolutePath
241
+ this @apply.friendPaths = friendPaths.map { it.absolutePath }.toTypedArray()
242
+ this @apply.classpath = libraries.map { it.absolutePath }.joinToString(File .pathSeparator)
243
+ this @apply.freeArgs = options.freeCompilerArgs.get() + freeArgs
244
+ this @apply.destination = destination.absolutePath
245
245
}
246
246
247
247
compilerRunner.runMetadataCompilerAsync(sources, commonSources, compilerArgs, environment)
@@ -259,45 +259,47 @@ abstract class KotlinNativeCompilerRunnerImpl @Inject constructor(
259
259
.KotlinNativeCompilerRunner .Settings .fromProject(task.project)
260
260
261
261
override fun runNativeCompilerAsync (
262
- args : KotlinNativeCompilerArguments ,
262
+ options : CompilerCommonOptions ,
263
+ freeArgs : List <String >,
263
264
sources : List <File >,
264
265
commonSources : List <File >,
266
+ friendPaths : List <File >,
267
+ libraries : List <File >,
265
268
outputs : List <File >,
269
+ destination : File ,
270
+ target : String
266
271
) {
267
272
val output = File (outputs.first(), " dummy.out" )
268
273
269
- val target = KonanTarget .predefinedTargets.get(args. target!! )!!
274
+ val target = KonanTarget .predefinedTargets.get(target)!!
270
275
val buildArgs: MutableList <String > = mutableListOf (
271
276
" -o" , output.path,
272
277
" -target" , target.name,
273
278
" -p" , " library" ,
274
279
" -Xmulti-platform"
275
280
)
276
- args. libraries.flatMap { listOf (" -l" , it.absolutePath) }.let { buildArgs.addAll(it) }
277
- args. friendPaths.ifNotEmpty {
281
+ libraries.flatMap { listOf (" -l" , it.absolutePath) }.let { buildArgs.addAll(it) }
282
+ friendPaths.ifNotEmpty {
278
283
buildArgs.add(" -friend-modules" )
279
284
buildArgs.add(joinToString(File .pathSeparator))
280
285
}
281
286
282
- if (args .verbose)
287
+ if (options .verbose.get() )
283
288
buildArgs.add(" -verbose" )
284
- if (args .allWarningsAsErrors)
289
+ if (options .allWarningsAsErrors.get() )
285
290
buildArgs.add(" -Werror" )
286
291
287
- args.pluginClasspaths.map { " -Xplugin=${it.absolutePath} " }.let { buildArgs.addAll(it) }
288
- args.pluginOptions.flatMap { listOf (" -P" , it) }.let { buildArgs.addAll(it) }
289
-
290
- args.languageVersion?.let {
292
+ options.languageVersion.getOrNull()?.let {
291
293
buildArgs.add(" -language-version" )
292
- buildArgs.add(it)
294
+ buildArgs.add(it.version )
293
295
}
294
- args .apiVersion?.let {
296
+ options .apiVersion.getOrNull() ?.let {
295
297
buildArgs.add(" -api-version" )
296
- buildArgs.add(it)
298
+ buildArgs.add(it.version )
297
299
}
298
300
299
301
buildArgs.addAll(sources.map { it.absolutePath })
300
- buildArgs.addAll(args. freeArgs)
302
+ buildArgs.addAll(freeArgs)
301
303
buildArgs.addAll(commonSources.map { it.absolutePath })
302
304
303
305
org.jetbrains.kotlin.compilerRunner.KotlinNativeCompilerRunner (
0 commit comments