[Gradle, JS] Extract KotlinJsLinkTask
This commit is contained in:
+2
-2
@@ -356,8 +356,8 @@ internal class KotlinJsIrSourceSetProcessor(
|
|||||||
val compilation = kotlinCompilation as KotlinJsIrCompilation
|
val compilation = kotlinCompilation as KotlinJsIrCompilation
|
||||||
|
|
||||||
listOf(
|
listOf(
|
||||||
compilation.productionCompileTaskName,
|
compilation.productionLinkTaskName,
|
||||||
compilation.developmentCompileTaskName
|
compilation.developmentLinkTaskName
|
||||||
).map { taskName ->
|
).map { taskName ->
|
||||||
registerKotlinCompileTask(
|
registerKotlinCompileTask(
|
||||||
taskName
|
taskName
|
||||||
|
|||||||
+4
-9
@@ -9,7 +9,6 @@ import org.gradle.api.NamedDomainObjectContainer
|
|||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.plugins.BasePluginConvention
|
import org.gradle.api.plugins.BasePluginConvention
|
||||||
import org.gradle.api.tasks.Copy
|
import org.gradle.api.tasks.Copy
|
||||||
import org.gradle.api.tasks.TaskProvider
|
|
||||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
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 project = compilation.target.project
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
val compileKotlinTask = compilation.compileKotlinTask
|
|
||||||
|
|
||||||
buildVariants.all { buildVariant ->
|
buildVariants.all { buildVariant ->
|
||||||
val kind = buildVariant.kind
|
val kind = buildVariant.kind
|
||||||
val runTask = project.registerTask<KotlinWebpack>(
|
val runTask = project.registerTask<KotlinWebpack>(
|
||||||
@@ -87,8 +84,8 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
nodeJs.npmInstallTask,
|
nodeJs.npmInstallTask,
|
||||||
getByKind(
|
getByKind(
|
||||||
kind,
|
kind,
|
||||||
compilation.productionCompileTask,
|
compilation.productionLinkTask,
|
||||||
compilation.developmentCompileTask
|
compilation.developmentLinkTask
|
||||||
),
|
),
|
||||||
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
||||||
)
|
)
|
||||||
@@ -126,8 +123,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
val project = compilation.target.project
|
val project = compilation.target.project
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
val compileKotlinTask = compilation.compileKotlinTask
|
|
||||||
|
|
||||||
val basePluginConvention = project.convention.plugins["base"] as BasePluginConvention?
|
val basePluginConvention = project.convention.plugins["base"] as BasePluginConvention?
|
||||||
|
|
||||||
val baseDist = project.buildDir.resolve(basePluginConvention!!.distsDirName)
|
val baseDist = project.buildDir.resolve(basePluginConvention!!.distsDirName)
|
||||||
@@ -157,8 +152,8 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
nodeJs.npmInstallTask,
|
nodeJs.npmInstallTask,
|
||||||
getByKind(
|
getByKind(
|
||||||
kind,
|
kind,
|
||||||
compilation.productionCompileTask,
|
compilation.productionLinkTask,
|
||||||
compilation.developmentCompileTask
|
compilation.developmentLinkTask
|
||||||
),
|
),
|
||||||
target.project.tasks.getByName(compilation.processResourcesTaskName),
|
target.project.tasks.getByName(compilation.processResourcesTaskName),
|
||||||
distributionTask
|
distributionTask
|
||||||
|
|||||||
+30
-19
@@ -5,35 +5,46 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
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.KotlinCompilation
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
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
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
|
|
||||||
class KotlinJsIrCompilation(
|
class KotlinJsIrCompilation(
|
||||||
target: KotlinTarget,
|
target: KotlinTarget,
|
||||||
name: String
|
name: String
|
||||||
) : KotlinJsCompilation(target, name) {
|
) : KotlinJsCompilation(target, name) {
|
||||||
val productionCompileTaskName: String = lowerCamelCaseName(
|
val productionLinkTaskName: String = linkTaskName(PRODUCTION)
|
||||||
"compile",
|
|
||||||
"production",
|
|
||||||
compilationName.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME },
|
|
||||||
"Kotlin",
|
|
||||||
target.targetName
|
|
||||||
)
|
|
||||||
|
|
||||||
val productionCompileTask: Kotlin2JsCompile
|
val productionLinkTask: KotlinJsIrLink
|
||||||
get() = (target.project.tasks.getByName(productionCompileTaskName) as Kotlin2JsCompile)
|
get() = (target.project.tasks.getByName(productionLinkTaskName) as KotlinJsIrLink)
|
||||||
|
|
||||||
val developmentCompileTaskName: String = lowerCamelCaseName(
|
val developmentLinkTaskName: String = linkTaskName(DEVELOPMENT)
|
||||||
"compile",
|
|
||||||
"development",
|
|
||||||
compilationName.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME },
|
|
||||||
"Kotlin",
|
|
||||||
target.targetName
|
|
||||||
)
|
|
||||||
|
|
||||||
val developmentCompileTask: Kotlin2JsCompile
|
val developmentLinkTask: KotlinJsIrLink
|
||||||
get() = (target.project.tasks.getByName(developmentCompileTaskName) as Kotlin2JsCompile)
|
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 {
|
target.compilations.all {
|
||||||
it.compileKotlinTask.kotlinOptions {
|
it.compileKotlinTask.kotlinOptions {
|
||||||
configureOptions(DISABLE_PRE_IR)
|
configureOptions()
|
||||||
|
|
||||||
|
freeCompilerArgs += DISABLE_PRE_IR
|
||||||
}
|
}
|
||||||
|
|
||||||
it.productionCompileTask.kotlinOptions {
|
it.productionLinkTask.configure()
|
||||||
configureOptions(ENABLE_DCE, GENERATE_D_TS)
|
|
||||||
}
|
|
||||||
|
|
||||||
it.developmentCompileTask.kotlinOptions {
|
it.developmentLinkTask.configure()
|
||||||
configureOptions(GENERATE_D_TS)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KotlinJsOptions.configureOptions(vararg additionalCompilerArgs: String) {
|
private fun KotlinJsOptions.configureOptions() {
|
||||||
moduleKind = "umd"
|
moduleKind = "umd"
|
||||||
sourceMap = true
|
sourceMap = true
|
||||||
|
|
||||||
freeCompilerArgs += additionalCompilerArgs.toList()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun defineConfigurationsForTarget(target: KotlinJsIrTarget) {
|
override fun defineConfigurationsForTarget(target: KotlinJsIrTarget) {
|
||||||
|
|||||||
Reference in New Issue
Block a user