[Gradle, JS] Extract KotlinJsLinkTask
This commit is contained in:
+2
-2
@@ -356,8 +356,8 @@ internal class KotlinJsIrSourceSetProcessor(
|
||||
val compilation = kotlinCompilation as KotlinJsIrCompilation
|
||||
|
||||
listOf(
|
||||
compilation.productionCompileTaskName,
|
||||
compilation.developmentCompileTaskName
|
||||
compilation.productionLinkTaskName,
|
||||
compilation.developmentLinkTaskName
|
||||
).map { taskName ->
|
||||
registerKotlinCompileTask(
|
||||
taskName
|
||||
|
||||
+4
-9
@@ -9,7 +9,6 @@ import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.plugins.BasePluginConvention
|
||||
import org.gradle.api.tasks.Copy
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||
@@ -73,8 +72,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
val project = compilation.target.project
|
||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
val compileKotlinTask = compilation.compileKotlinTask
|
||||
|
||||
buildVariants.all { buildVariant ->
|
||||
val kind = buildVariant.kind
|
||||
val runTask = project.registerTask<KotlinWebpack>(
|
||||
@@ -87,8 +84,8 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
nodeJs.npmInstallTask,
|
||||
getByKind(
|
||||
kind,
|
||||
compilation.productionCompileTask,
|
||||
compilation.developmentCompileTask
|
||||
compilation.productionLinkTask,
|
||||
compilation.developmentLinkTask
|
||||
),
|
||||
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
||||
)
|
||||
@@ -126,8 +123,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
val project = compilation.target.project
|
||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
val compileKotlinTask = compilation.compileKotlinTask
|
||||
|
||||
val basePluginConvention = project.convention.plugins["base"] as BasePluginConvention?
|
||||
|
||||
val baseDist = project.buildDir.resolve(basePluginConvention!!.distsDirName)
|
||||
@@ -157,8 +152,8 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
nodeJs.npmInstallTask,
|
||||
getByKind(
|
||||
kind,
|
||||
compilation.productionCompileTask,
|
||||
compilation.developmentCompileTask
|
||||
compilation.productionLinkTask,
|
||||
compilation.developmentLinkTask
|
||||
),
|
||||
target.project.tasks.getByName(compilation.processResourcesTaskName),
|
||||
distributionTask
|
||||
|
||||
+30
-19
@@ -5,35 +5,46 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.gradle.api.file.SourceDirectorySet
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrType.DEVELOPMENT
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrType.PRODUCTION
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
|
||||
class KotlinJsIrCompilation(
|
||||
target: KotlinTarget,
|
||||
name: String
|
||||
) : KotlinJsCompilation(target, name) {
|
||||
val productionCompileTaskName: String = lowerCamelCaseName(
|
||||
"compile",
|
||||
"production",
|
||||
compilationName.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME },
|
||||
"Kotlin",
|
||||
target.targetName
|
||||
)
|
||||
val productionLinkTaskName: String = linkTaskName(PRODUCTION)
|
||||
|
||||
val productionCompileTask: Kotlin2JsCompile
|
||||
get() = (target.project.tasks.getByName(productionCompileTaskName) as Kotlin2JsCompile)
|
||||
val productionLinkTask: KotlinJsIrLink
|
||||
get() = (target.project.tasks.getByName(productionLinkTaskName) as KotlinJsIrLink)
|
||||
|
||||
val developmentCompileTaskName: String = lowerCamelCaseName(
|
||||
"compile",
|
||||
"development",
|
||||
compilationName.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME },
|
||||
"Kotlin",
|
||||
target.targetName
|
||||
)
|
||||
val developmentLinkTaskName: String = linkTaskName(DEVELOPMENT)
|
||||
|
||||
val developmentCompileTask: Kotlin2JsCompile
|
||||
get() = (target.project.tasks.getByName(developmentCompileTaskName) as Kotlin2JsCompile)
|
||||
val developmentLinkTask: KotlinJsIrLink
|
||||
get() = (target.project.tasks.getByName(developmentLinkTaskName) as KotlinJsIrLink)
|
||||
|
||||
private fun linkTaskName(type: KotlinJsIrType): String =
|
||||
lowerCamelCaseName(
|
||||
"compile",
|
||||
type.name.toLowerCase(),
|
||||
compilationName.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME },
|
||||
"Kotlin",
|
||||
target.targetName
|
||||
)
|
||||
|
||||
internal val allSources: MutableSet<SourceDirectorySet> = mutableSetOf()
|
||||
|
||||
override fun addSourcesToCompileTask(sourceSet: KotlinSourceSet, addAsCommonSources: Lazy<Boolean>) {
|
||||
super.addSourcesToCompileTask(sourceSet, addAsCommonSources)
|
||||
allSources.add(sourceSet.kotlin)
|
||||
|
||||
listOf(productionLinkTask, developmentLinkTask).forEach {
|
||||
it.sourceFilesExtensions(sourceSet.customSourceFilesExtensions)
|
||||
}
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.gradle.api.file.FileTree
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFiles
|
||||
import org.gradle.api.tasks.SkipWhenEmpty
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrType.DEVELOPMENT
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrType.PRODUCTION
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinJsIrLink : Kotlin2JsCompile() {
|
||||
@Input
|
||||
lateinit var type: KotlinJsIrType
|
||||
|
||||
@InputFiles
|
||||
@SkipWhenEmpty
|
||||
override fun getSource(): FileTree {
|
||||
// compile from sources, support compile from klib whe it will be supported
|
||||
val jsIrCompilation = taskData.compilation as KotlinJsIrCompilation
|
||||
return project.files(jsIrCompilation.allSources).asFileTree
|
||||
}
|
||||
|
||||
internal fun configure() {
|
||||
when (type) {
|
||||
PRODUCTION -> {
|
||||
kotlinOptions.configureOptions(ENABLE_DCE, GENERATE_D_TS)
|
||||
}
|
||||
DEVELOPMENT -> {
|
||||
kotlinOptions.configureOptions(GENERATE_D_TS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun KotlinJsOptions.configureOptions(vararg additionalCompilerArgs: String) {
|
||||
moduleKind = "umd"
|
||||
sourceMap = true
|
||||
|
||||
freeCompilerArgs += additionalCompilerArgs.toList()
|
||||
}
|
||||
}
|
||||
|
||||
enum class KotlinJsIrType {
|
||||
PRODUCTION,
|
||||
DEVELOPMENT
|
||||
}
|
||||
+6
-10
@@ -54,24 +54,20 @@ open class KotlinJsIrTargetConfigurator(kotlinPluginVersion: String) :
|
||||
|
||||
target.compilations.all {
|
||||
it.compileKotlinTask.kotlinOptions {
|
||||
configureOptions(DISABLE_PRE_IR)
|
||||
configureOptions()
|
||||
|
||||
freeCompilerArgs += DISABLE_PRE_IR
|
||||
}
|
||||
|
||||
it.productionCompileTask.kotlinOptions {
|
||||
configureOptions(ENABLE_DCE, GENERATE_D_TS)
|
||||
}
|
||||
it.productionLinkTask.configure()
|
||||
|
||||
it.developmentCompileTask.kotlinOptions {
|
||||
configureOptions(GENERATE_D_TS)
|
||||
}
|
||||
it.developmentLinkTask.configure()
|
||||
}
|
||||
}
|
||||
|
||||
private fun KotlinJsOptions.configureOptions(vararg additionalCompilerArgs: String) {
|
||||
private fun KotlinJsOptions.configureOptions() {
|
||||
moduleKind = "umd"
|
||||
sourceMap = true
|
||||
|
||||
freeCompilerArgs += additionalCompilerArgs.toList()
|
||||
}
|
||||
|
||||
override fun defineConfigurationsForTarget(target: KotlinJsIrTarget) {
|
||||
|
||||
Reference in New Issue
Block a user