@@ -28,7 +28,6 @@ import org.gradle.process.ExecOperations
2828import  org.gradle.workers.WorkerExecutor 
2929import  org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporter 
3030import  org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporterImpl 
31- import  org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments 
3231import  org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments 
3332import  org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments 
3433import  org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments 
@@ -52,6 +51,13 @@ import org.jetbrains.kotlin.utils.JsLibraryUtils
5251import  org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty 
5352import  java.io.File 
5453import  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 
5561
5662internal  inline  fun  <reified  T  : Any ? > ObjectFactory.property () =  property(T ::class .java)
5763internal  inline  fun  <reified  T  : Any ? > ObjectFactory.property (initialValue :  T ) =  property<T >().value(initialValue)
@@ -86,9 +92,10 @@ abstract class KotlinCompilerRunnerImpl @Inject constructor(
8692    @Internal
8793    internal  fun  prepareEnvironment (allWarningsAsErrors :  Boolean , outputs :  List <File >): GradleCompilerEnvironment  {
8894        val  messageCollector =  GradlePrintingMessageCollector (GradleKotlinLogger (logger), allWarningsAsErrors)
95+         val  errorMessageCollector =  GradleErrorMessageCollector (messageCollector)
8996        val  outputItemCollector =  OutputItemsCollectorImpl ()
9097        return  GradleCompilerEnvironment (
91-             compilerClasspath.files.toList(), messageCollector , outputItemCollector,
98+             compilerClasspath.files.toList(), errorMessageCollector , outputItemCollector,
9299            reportingSettings =  ReportingSettings (),
93100            outputFiles =  outputs
94101        )
@@ -110,49 +117,32 @@ abstract class KotlinCompilerRunnerImpl @Inject constructor(
110117    }
111118}
112119
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- 
127120abstract  class  KotlinJvmCompilerRunnerImpl  @Inject constructor(
128121    task :  Task ,
129122    objectFactory :  ObjectFactory ,
130123    workerExecutor :  WorkerExecutor 
131124) : KotlinCompilerRunnerImpl(task, objectFactory, workerExecutor), KotlinJvmCompilerRunner {
132125
133126    override  fun  runJvmCompilerAsync (
134-         args :  KotlinJvmCompilerArguments ,
127+         options :  CompilerJvmOptions ,
128+         freeArgs :  List <String >,
135129        sources :  List <File >,
136130        commonSources :  List <File >,
137-         outputs :  List <File >
131+         friendPaths :  List <File >,
132+         libraries :  List <File >,
133+         outputs :  List <File >,
134+         destination :  File 
138135    ) {
139-         val  environment =  prepareEnvironment(args .allWarningsAsErrors, outputs)
136+         val  environment =  prepareEnvironment(options .allWarningsAsErrors.get() , outputs)
140137        val  compilerRunner =  prepareCompilerRunner()
141138        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
156146        }
157147
158148        compilerRunner.runJvmCompilerAsync(
@@ -191,30 +181,34 @@ abstract class KotlinJsCompilerRunnerImpl @Inject constructor(
191181        }
192182
193183    override  fun  runJsCompilerAsync (
194-         args :  KotlinJsCompilerArguments ,
184+         options :  CompilerJsOptions ,
185+         freeArgs :  List <String >,
195186        sources :  List <File >,
196187        commonSources :  List <File >,
197-         outputs :  List <File >
188+         friendPaths :  List <File >,
189+         libraries :  List <File >,
190+         outputs :  List <File >,
191+         destination :  File 
198192    ) {
199-         val  environment =  prepareEnvironment(args .allWarningsAsErrors, outputs)
193+         val  environment =  prepareEnvironment(options .allWarningsAsErrors.get() , outputs)
200194        val  compilerRunner =  prepareCompilerRunner()
201195        val  compilerArgs =  K2JSCompilerArguments ().apply  {
202-             copyFrom(args)
196+             options as  CompilerJsOptionsDefault 
197+             options.fillCompilerArguments(this )
203198
204-             outputFile =  args.destination?.absolutePath
199+             this @apply.freeArgs =  options.freeCompilerArgs.get() +  freeArgs
200+             this @apply.outputFile =  destination.absolutePath
205201
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" 
214208
215-             friendModules =  args. friendPaths.filter { libFilter(this , it) }
209+             this @apply. friendModules =  friendPaths.filter { libFilter(this , it) }
216210                .map { it.absolutePath }.joinToString(File .pathSeparator)
217-             libraries =  args. libraries.filter { libFilter(this , it) }
211+             this @apply. libraries =  libraries.filter { libFilter(this , it) }
218212                .map { it.absolutePath }.joinToString(File .pathSeparator)
219213        }
220214
@@ -229,19 +223,25 @@ abstract class KotlinMetadataCompilerRunnerImpl @Inject constructor(
229223) : KotlinCompilerRunnerImpl(task, objectFactory, workerExecutor), KotlinMetadataCompilerRunner {
230224
231225    override  fun  runMetadataCompilerAsync (
232-         args :  KotlinMetadataCompilerArguments ,
226+         options :  CompilerCommonOptions ,
227+         freeArgs :  List <String >,
233228        sources :  List <File >,
234229        commonSources :  List <File >,
235-         outputs :  List <File >
230+         friendPaths :  List <File >,
231+         libraries :  List <File >,
232+         outputs :  List <File >,
233+         destination :  File 
236234    ) {
237-         val  environment =  prepareEnvironment(args .allWarningsAsErrors, outputs)
235+         val  environment =  prepareEnvironment(options .allWarningsAsErrors.get() , outputs)
238236        val  compilerRunner =  prepareCompilerRunner()
239237        val  compilerArgs =  K2MetadataCompilerArguments ().apply  {
240-             copyFrom(args)
238+             options as  CompilerCommonOptionsDefault 
239+             options.fillCompilerArguments(this )
241240
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
245245        }
246246
247247        compilerRunner.runMetadataCompilerAsync(sources, commonSources, compilerArgs, environment)
@@ -259,45 +259,47 @@ abstract class KotlinNativeCompilerRunnerImpl @Inject constructor(
259259        .KotlinNativeCompilerRunner .Settings .fromProject(task.project)
260260
261261    override  fun  runNativeCompilerAsync (
262-         args :  KotlinNativeCompilerArguments ,
262+         options :  CompilerCommonOptions ,
263+         freeArgs :  List <String >,
263264        sources :  List <File >,
264265        commonSources :  List <File >,
266+         friendPaths :  List <File >,
267+         libraries :  List <File >,
265268        outputs :  List <File >,
269+         destination :  File ,
270+         target :  String 
266271    ) {
267272        val  output =  File (outputs.first(), " dummy.out" 
268273
269-         val  target =  KonanTarget .predefinedTargets.get(args. target!! )!! 
274+         val  target =  KonanTarget .predefinedTargets.get(target)!! 
270275        val  buildArgs:  MutableList <String > =  mutableListOf (
271276            " -o" 
272277            " -target" 
273278            " -p" " library" 
274279            " -Xmulti-platform" 
275280        )
276-         args. libraries.flatMap { listOf (" -l" let  { buildArgs.addAll(it) }
277-         args. friendPaths.ifNotEmpty {
281+         libraries.flatMap { listOf (" -l" let  { buildArgs.addAll(it) }
282+         friendPaths.ifNotEmpty {
278283            buildArgs.add(" -friend-modules" 
279284            buildArgs.add(joinToString(File .pathSeparator))
280285        }
281286
282-         if  (args .verbose)
287+         if  (options .verbose.get() )
283288            buildArgs.add(" -verbose" 
284-         if  (args .allWarningsAsErrors)
289+         if  (options .allWarningsAsErrors.get() )
285290            buildArgs.add(" -Werror" 
286291
287-         args.pluginClasspaths.map { " -Xplugin=${it.absolutePath} " let  { buildArgs.addAll(it) }
288-         args.pluginOptions.flatMap { listOf (" -P" let  { buildArgs.addAll(it) }
289- 
290-         args.languageVersion?.let  {
292+         options.languageVersion.getOrNull()?.let  {
291293            buildArgs.add(" -language-version" 
292-             buildArgs.add(it)
294+             buildArgs.add(it.version )
293295        }
294-         args .apiVersion?.let  {
296+         options .apiVersion.getOrNull() ?.let  {
295297            buildArgs.add(" -api-version" 
296-             buildArgs.add(it)
298+             buildArgs.add(it.version )
297299        }
298300
299301        buildArgs.addAll(sources.map { it.absolutePath })
300-         buildArgs.addAll(args. freeArgs)
302+         buildArgs.addAll(freeArgs)
301303        buildArgs.addAll(commonSources.map { it.absolutePath })
302304
303305        org.jetbrains.kotlin.compilerRunner.KotlinNativeCompilerRunner (
0 commit comments