diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/CompilerActionInfo.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/CompilerActionInfo.kt index d2521255..e323e474 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/CompilerActionInfo.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/CompilerActionInfo.kt @@ -12,4 +12,5 @@ data class CompilerActionInfo(val directory: String?, val outputDir: File, val compilerArgs: List, val friendPaths: List, - val forceRecompile: Boolean) + val forceRecompile: Boolean, + val compilerSeparateProcess: Boolean = false) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt index 243090ee..7188cf10 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt @@ -79,10 +79,12 @@ open class NewRunCommand(val info: RunCommandInfo) { // Run the command and collect the return code and streams val returnCode = process.waitFor(30, TimeUnit.SECONDS) - val input = if (process.inputStream.available() > 0) fromStream(process.inputStream) - else listOf() - val error = if (process.errorStream.available() > 0) fromStream(process.errorStream) - else listOf() + val input = + if (process.inputStream.available() > 0) fromStream(process.inputStream) + else listOf() + val error = + if (process.errorStream.available() > 0) fromStream(process.errorStream) + else listOf() // Check to see if the command succeeded val isSuccess = diff --git a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt index 71d9e388..ed743b0f 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt @@ -131,7 +131,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va generatedClasses(project, context, config.outputDir))) val flags = listOf() val cai = CompilerActionInfo(project.directory, allDependencies(project), sourceFiles, listOf(".kt"), - buildDirectory, flags, emptyList(), forceRecompile = true) + buildDirectory, flags, emptyList(), forceRecompile = true, compilerSeparateProcess = true) val cr = compilerUtils.invokeCompiler(project, context, kotlinPlugin.compiler, cai) success = cr.failedResult == null @@ -151,6 +151,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va val allDeps = arrayListOf() allDeps.add(annotationProcessorDependency()) allDeps.addAll(aptJarDependencies(project)) + return allDeps } @@ -177,6 +178,11 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va flags.add(toolsJar.absolutePath) } + aptJarDependencies(project).forEach { + flags.add("-Xplugin") + flags.add(it.jarFile.get().absolutePath) + } + // // Pass options to the annotation plugin // @@ -200,12 +206,12 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va listOf(Scope.COMPILE), allDeps) dependencies.forEach { - val jarFile = it.jarFile.get() + val jarFile = it.jarFile.get().absolutePath kaptPluginFlags.add(kaptPluginFlag("apclasspath=$jarFile")) } flags.add(kaptPluginFlags.joinToString(",")) - listOf("-language-version", "1.1", " -api-version", "1.1").forEach { + listOf("-language-version", "1.1", "-api-version", "1.1").forEach { flags.add(it) } @@ -214,7 +220,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va .toList() + generatedSources val buildDirectory = File(KFiles.joinDir(project.directory, generated)) val cai = CompilerActionInfo(project.directory, allDeps, sourceFiles, listOf(".kt"), - buildDirectory, flags, emptyList(), forceRecompile = true) + buildDirectory, flags, emptyList(), forceRecompile = true, compilerSeparateProcess = true) context.logger.log(project.name, 2, " " + kaptPluginFlags.joinToString("\n ")) val cr = compilerUtils.invokeCompiler(project, context, kotlinPlugin.compiler, cai) 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 33b26ec6..d8a1d153 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -89,7 +89,8 @@ class KotlinCompiler @Inject constructor( // the K2JVMCompiler class directly val actualVersion = kotlinVersion(project) - if (settings.kobaltCompilerSeparateProcess || actualVersion != Constants.KOTLIN_COMPILER_VERSION) { + if (settings.kobaltCompilerSeparateProcess || actualVersion != Constants.KOTLIN_COMPILER_VERSION + || info.compilerSeparateProcess) { return invokeCompilerInSeparateProcess(classpath, info, actualVersion, project) } else { @@ -114,20 +115,24 @@ class KotlinCompiler @Inject constructor( val newArgs = listOf( "-classpath", compilerClasspath, K2JVMCompiler::class.java.name, + *info.compilerArgs.toTypedArray(), "-classpath", classpath, "-d", info.outputDir.absolutePath, *xFlagsArray, *info.sourceFiles.toTypedArray()) .filter { ! it.isEmpty() } - log(2, " Invoking separate kotlinc:\n " + java!!.absolutePath + " " + newArgs.joinToString()) + log(2, " Invoking separate kotlinc:\n " + java!!.absolutePath + " " + newArgs.joinToString(" ")) val result = NewRunCommand(RunCommandInfo().apply { command = java.absolutePath args = newArgs directory = File(".") - // The Kotlin compiler issues warnings on stderr :-( - containsErrors = { errors: List -> errors.any { it.contains("rror")} } +// // The Kotlin compiler issues warnings on stderr :-( + useErrorStreamAsErrorIndicator = false +// containsErrors = { +// errors: List -> errors.any { it.contains("rror")} +// } }).invoke() return TaskResult(result == 0, errorMessage = "Error while compiling") } @@ -388,7 +393,8 @@ class KotlinCompiler @Inject constructor( * JvmCompilerPlugin#createCompilerActionInfo instead */ fun compile(project: Project?, context: KobaltContext?, compileDependencies: List, - otherClasspath: List, sourceFiles: List, outputDir: File, args: List) : TaskResult { + otherClasspath: List, sourceFiles: List, outputDir: File, args: List, + compilerSeparateProcess: Boolean) : TaskResult { val executor = executors.newExecutor("KotlinCompiler", 10) @@ -414,7 +420,7 @@ class KotlinCompiler @Inject constructor( emptyList() } val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args, - friendPaths, context?.internalContext?.forceRecompile ?: false) + friendPaths, context?.internalContext?.forceRecompile ?: false, compilerSeparateProcess) return jvmCompiler.doCompile(project, context, compilerAction, info, if (context != null) compilerUtils.sourceCompilerFlags(project, context, info) else emptyList()) @@ -428,6 +434,7 @@ class KConfiguration @Inject constructor(val compiler: KotlinCompiler){ var output: File by Delegates.notNull() val args = arrayListOf() var noIncrementalKotlin = false + var compilerSeparateProcess = false fun sourceFiles(s: String) = source.add(s) @@ -442,7 +449,8 @@ class KConfiguration @Inject constructor(val compiler: KotlinCompiler){ fun compile(project: Project? = null, context: KobaltContext? = null) : TaskResult { val saved = context?.internalContext?.noIncrementalKotlin ?: false if (context != null) context.internalContext.noIncrementalKotlin = noIncrementalKotlin - val result = compiler.compile(project, context, dependencies, classpath, source, output, args) + val result = compiler.compile(project, context, dependencies, classpath, source, output, args, + compilerSeparateProcess) if (context != null) context.internalContext.noIncrementalKotlin = saved return result } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt index 220be8a7..3c437628 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -83,6 +83,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depen sourceFiles(info.sourceFiles) compilerArgs(info.compilerArgs) output = info.outputDir + compilerSeparateProcess = info.compilerSeparateProcess }.compile(project, context) }