From 49d058e3e17c465374f98b712c01e3caecc3c0da Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 11 Apr 2017 10:43:27 -0700 Subject: [PATCH] GH-403: Honor Kotlin compiler flags in process. Fixes https://github.com/cbeust/kobalt/issues/403 --- .../kobalt/plugin/kotlin/KotlinCompiler.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index df46a947..5fa6af71 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -90,7 +90,7 @@ class KotlinCompiler @Inject constructor( return invokeCompilerInSeparateProcess(classpath, info, actualVersion, project) } else { - return invokeCompilerDirectly(projectName ?: "kobalt-" + Random().nextInt(), outputDir, + return invokeCompilerDirectly(project, projectName ?: "kobalt-" + Random().nextInt(), outputDir, info, classpath, filesToCompile) } } @@ -129,11 +129,20 @@ class KotlinCompiler @Inject constructor( return TaskResult(result == 0, errorMessage = "Error while compiling") } - private fun invokeCompilerDirectly(projectName: String, outputDir: String?, info: CompilerActionInfo, - classpathString: String, filesToCompile: Int): TaskResult { + private fun invokeCompilerDirectly(project: Project?, projectName: String, outputDir: String?, + info: CompilerActionInfo, classpathString: String, filesToCompile: Int): TaskResult { val sourceFiles = info.sourceFiles val friends = info.friendPaths.toTypedArray() - val args = K2JVMCompilerArguments().apply { + + // Collect the compiler args from kotlinCompiler{} and from settings.xml and parse them + val args2 = (kotlinConfig(project)?.args ?: arrayListOf()) + + (settings.kobaltCompilerFlags?.split(" ") ?: listOf()) + val args = K2JVMCompilerArguments() + val compiler = K2JVMCompiler() + compiler.parseArguments(args2.toTypedArray(), args) + + // Override important arguments with our values + args.apply { moduleName = projectName destination = outputDir classpath = classpathString @@ -224,7 +233,7 @@ class KotlinCompiler @Inject constructor( if (cliArgs.noIncrementalKotlin || Kobalt.context?.internalContext?.noIncrementalKotlin ?: false) { log(2, " Kotlin incremental compilation is disabled") val duration = benchmarkMillis { - K2JVMCompiler().exec(collector, Services.Builder().build(), args) + compiler.exec(collector, Services.Builder().build(), args) } log(1, " Regular compilation time: ${duration.first} ms") TaskResult(duration.second == ExitCode.OK)