Set coroutines setting for JS in Gradle plugin

This commit is contained in:
Alexey Tsvetkov
2016-12-15 20:25:49 +03:00
committed by Stanislav Erokhin
parent c0a3d3568a
commit 3e1edf006f
3 changed files with 17 additions and 17 deletions
@@ -17,11 +17,12 @@
package org.jetbrains.kotlin.gradle.plugin
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.*
import kotlin.reflect.KMutableProperty1
fun mapKotlinTaskProperties(project: Project, task: KotlinCompile) {
fun mapKotlinTaskProperties(project: Project, task: AbstractKotlinCompile<*>) {
propertyMappings.forEach { it.apply(project, task) }
val localPropertiesFile = project.rootProject.file("local.properties")
@@ -33,26 +34,26 @@ fun mapKotlinTaskProperties(project: Project, task: KotlinCompile) {
}
private val propertyMappings = listOf(
KotlinPropertyMapping("kotlin.incremental", KotlinCompile::incremental, String::toBoolean),
KotlinPropertyMapping("kotlin.coroutines", KotlinCompile::coroutines) { CoroutineSupport.byCompilerArgument(it) }
KotlinPropertyMapping("kotlin.incremental", AbstractKotlinCompile<*>::incremental, String::toBoolean),
KotlinPropertyMapping("kotlin.coroutines", AbstractKotlinCompile<*>::coroutines) { CoroutineSupport.byCompilerArgument(it) }
)
private class KotlinPropertyMapping<T>(
private val projectPropName: String,
private val taskProperty: KMutableProperty1<KotlinCompile, T>,
private val taskProperty: KMutableProperty1<AbstractKotlinCompile<*>, T>,
private val transform: (String) -> T
) {
fun apply(project: Project, task: KotlinCompile) {
fun apply(project: Project, task: AbstractKotlinCompile<*>) {
if (!project.hasProperty(projectPropName)) return
setPropertyValue(task, project.property(projectPropName))
}
fun apply(properties: Properties, task: KotlinCompile) {
fun apply(properties: Properties, task: AbstractKotlinCompile<*>) {
setPropertyValue(task, properties.getProperty(projectPropName))
}
private fun setPropertyValue(task: KotlinCompile, value: Any?) {
private fun setPropertyValue(task: AbstractKotlinCompile<*>, value: Any?) {
if (value !is String) return
val transformedValue = transform(value) ?: return
@@ -105,12 +105,20 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
sourceRoots.log(this.name, logger)
val args = populateCompilerArguments()
args.setupCoroutineSupportArgs()
compilerCalled = true
callCompiler(args, sourceRoots, ChangedFiles(inputs))
}
internal abstract fun getSourceRoots(): SourceRoots
internal abstract fun callCompiler(args: T, sourceRoots: SourceRoots, changedFiles: ChangedFiles)
private fun CommonCompilerArguments.setupCoroutineSupportArgs() {
coroutinesEnable = coroutines == CoroutineSupport.ENABLED
coroutinesWarn = coroutines == CoroutineSupport.ENABLED_WITH_WARNING
coroutinesError = coroutines == CoroutineSupport.DISABLED
}
}
open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), KotlinJvmCompile {
@@ -186,12 +194,6 @@ 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
logger.warn("Using kotlin.coroutines=${coroutines.compilerArgument}")
if (!incremental) {
anyClassesCompiled = true
processCompilerExitCode(compileJvmNotIncrementally(
@@ -357,10 +359,6 @@ 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
}
@@ -41,6 +41,7 @@ internal open class KotlinTasksProvider {
project.tasks.create(name, KotlinCompileCommon::class.java).apply {
this.sourceSetName = sourceSetName
friendTaskName = taskToFriendTaskMapper[this]
mapKotlinTaskProperties(project, this)
}
protected open val taskToFriendTaskMapper: TaskToFriendTaskMapper =