Attempt to add property go kotlin gradle plugin

This commit is contained in:
Mikhail Zarechenskiy
2016-12-15 01:25:22 +03:00
committed by Stanislav Erokhin
parent 957af61464
commit 6697c902fc
2 changed files with 32 additions and 1 deletions
@@ -33,7 +33,8 @@ fun mapKotlinTaskProperties(project: Project, task: KotlinCompile) {
}
private val propertyMappings = listOf(
KotlinPropertyMapping("kotlin.incremental", KotlinCompile::incremental, String::toBoolean)
KotlinPropertyMapping("kotlin.incremental", KotlinCompile::incremental, String::toBoolean),
KotlinPropertyMapping("kotlin.coroutines", KotlinCompile::coroutines) { CoroutineSupport.byCompilerArgument(it) }
)
private class KotlinPropertyMapping<T>(
@@ -57,4 +58,18 @@ private class KotlinPropertyMapping<T>(
val transformedValue = transform(value) ?: return
taskProperty.set(task, transformedValue)
}
}
enum class CoroutineSupport(val compilerArgument: String) {
ENABLED("enable"),
ENABLED_WITH_WARNING("warn"),
DISABLED("error");
companion object {
val DEFAULT = ENABLED_WITH_WARNING
fun byCompilerArgument(argument: String): CoroutineSupport {
return CoroutineSupport.values().find { it.compilerArgument == argument } ?: DEFAULT
}
}
}
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.plugin.CoroutineSupport
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
import org.jetbrains.kotlin.gradle.plugin.kotlinInfo
import org.jetbrains.kotlin.gradle.utils.ParsedGradleVersion
@@ -70,6 +71,13 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
System.setProperty("kotlin.incremental.compilation.experimental", value.toString())
}
var coroutines: CoroutineSupport = CoroutineSupport.DEFAULT
get() = field
set(value) {
field = value
logger.kotlinDebug { "Set $this.coroutines=${value.compilerArgument}" }
}
internal var compilerCalled: Boolean = false
// TODO: consider more reliable approach (see usage)
internal var anyClassesCompiled: Boolean = false
@@ -178,6 +186,10 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
val outputDir = destinationDir
args.coroutinesEnable = coroutines == CoroutineSupport.ENABLED
args.coroutinesWarn = coroutines == CoroutineSupport.ENABLED_WITH_WARNING
args.coroutinesError = coroutines == CoroutineSupport.DISABLED
if (!incremental) {
anyClassesCompiled = true
processCompilerExitCode(compileJvmNotIncrementally(
@@ -343,6 +355,10 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
destinationDir.mkdirs()
args.freeArgs = args.freeArgs + sourceRoots.kotlinSourceFiles.map { it.absolutePath }
args.coroutinesEnable = coroutines == CoroutineSupport.ENABLED
args.coroutinesWarn = coroutines == CoroutineSupport.ENABLED_WITH_WARNING
args.coroutinesError = coroutines == CoroutineSupport.DISABLED
if (args.outputFile == null) {
args.outputFile = defaultOutputFile.canonicalPath
}