Ant: Add support for fork-mode
#KT-44293
This commit is contained in:
committed by
Alexander Udalov
parent
ee952db1a2
commit
0110b4e4b4
@@ -16,9 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.ant
|
||||
|
||||
import org.apache.tools.ant.types.Path
|
||||
import org.apache.tools.ant.types.Reference
|
||||
import org.apache.tools.ant.BuildException
|
||||
import org.apache.tools.ant.taskdefs.Execute
|
||||
import org.apache.tools.ant.taskdefs.Redirector
|
||||
import org.apache.tools.ant.types.*
|
||||
import java.io.File.pathSeparator
|
||||
import java.io.File.separator
|
||||
|
||||
class Kotlin2JvmTask : KotlinCompilerBaseTask() {
|
||||
override val compilerFqName = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"
|
||||
@@ -28,6 +31,9 @@ class Kotlin2JvmTask : KotlinCompilerBaseTask() {
|
||||
|
||||
var noReflect: Boolean = false
|
||||
|
||||
private val cmdl = CommandlineJava()
|
||||
var fork: Boolean = false
|
||||
|
||||
private var compileClasspath: Path? = null
|
||||
|
||||
fun setClasspath(classpath: Path) {
|
||||
@@ -73,4 +79,47 @@ class Kotlin2JvmTask : KotlinCompilerBaseTask() {
|
||||
if (noReflect) args.add("-no-reflect")
|
||||
if (includeRuntime) args.add("-include-runtime")
|
||||
}
|
||||
|
||||
override fun execute() {
|
||||
if (!fork)
|
||||
super.execute()
|
||||
else {
|
||||
exec()
|
||||
}
|
||||
}
|
||||
|
||||
private fun exec() {
|
||||
val javaHome = System.getProperty("java.home")
|
||||
val javaBin = javaHome + separator + "bin" + separator + "java"
|
||||
val redirector = Redirector(this)
|
||||
|
||||
fillArguments()
|
||||
|
||||
val command = ArrayList<String>()
|
||||
command.add(javaBin)
|
||||
command.addAll(cmdl.vmCommand.arguments) // jvm args
|
||||
command.add("-Dorg.jetbrains.kotlin.cliMessageRenderer=FullPath") // same MessageRenderer as non-forking mode
|
||||
command.add("-cp")
|
||||
command.add(KotlinAntTaskUtil.compilerJar.canonicalPath)
|
||||
command.add(compilerFqName)
|
||||
command.addAll(args) // compiler args
|
||||
|
||||
// streamHandler: used to handle the input and output streams of the subprocess.
|
||||
// watchdog: a watchdog for the subprocess or <code>null</code> to disable a timeout for the subprocess.
|
||||
// TODO: support timeout for the subprocess
|
||||
val exe = Execute(redirector.createHandler(), null)
|
||||
exe.setAntRun(getProject())
|
||||
exe.commandline = command.toTypedArray()
|
||||
log("Executing command: ${command.joinToString(" ")}", LogLevel.DEBUG.level)
|
||||
log("Compiling ${src!!.list().toList()} => [${output!!.canonicalPath}]")
|
||||
val exitCode = exe.execute()
|
||||
redirector.complete()
|
||||
if (failOnError && exitCode != 0) {
|
||||
throw BuildException("Compile failed; see the compiler error output for details.")
|
||||
}
|
||||
}
|
||||
|
||||
fun createJvmarg(): Commandline.Argument {
|
||||
return cmdl.createVmArgument()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ abstract class KotlinCompilerBaseTask : Task() {
|
||||
fillSpecificArguments()
|
||||
}
|
||||
|
||||
final override fun execute() {
|
||||
override fun execute() {
|
||||
fillArguments()
|
||||
|
||||
val compilerClass = KotlinAntTaskUtil.getOrCreateClassLoader().loadClass(compilerFqName)
|
||||
|
||||
Reference in New Issue
Block a user