[Gradle, JS] Add dce to development

^KT-32273 fixed
^KT-36451 fixed
^KT-37258 fixed
This commit is contained in:
Ilya Goncharov
2020-05-26 19:45:47 +03:00
parent 9d8eb65a5e
commit 65db6bb2a5
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2020 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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -65,17 +65,33 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
} }
override fun configureMain(compilation: KotlinJsCompilation) { override fun configureMain(compilation: KotlinJsCompilation) {
val dceTaskProvider = configureDce(compilation) val dceTaskProvider = configureDce(
compilation = compilation,
dev = false
)
configureRun(compilation, dceTaskProvider) val devDceTaskProvider = configureDce(
configureBuild(compilation, dceTaskProvider) compilation = compilation,
dev = true
)
configureRun(
compilation = compilation,
dceTaskProvider = dceTaskProvider,
devDceTaskProvider = devDceTaskProvider
)
configureBuild(
compilation = compilation,
dceTaskProvider = dceTaskProvider,
devDceTaskProvider = devDceTaskProvider
)
} }
private fun configureRun( private fun configureRun(
compilation: KotlinJsCompilation, compilation: KotlinJsCompilation,
dceTaskProvider: TaskProvider<KotlinJsDceTask> dceTaskProvider: TaskProvider<KotlinJsDceTask>,
devDceTaskProvider: TaskProvider<KotlinJsDceTask>
) { ) {
val project = compilation.target.project val project = compilation.target.project
val nodeJs = NodeJsRootPlugin.apply(project.rootProject) val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
@@ -111,21 +127,21 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
it.outputs.upToDateWhen { false } it.outputs.upToDateWhen { false }
when (type) { val actualDceTaskProvider = when (type) {
KotlinJsBinaryType.PRODUCTION -> { KotlinJsBinaryType.PRODUCTION -> dceTaskProvider
// Breaking of Task Configuration Avoidance is not so critical KotlinJsBinaryType.DEVELOPMENT -> devDceTaskProvider
// because this task is dependent on DCE task
it.entry = dceTaskProvider.get()
.destinationDir
.resolve(compileKotlinTask.outputFile.name)
it.resolveFromModulesFirst = true
it.dependsOn(dceTaskProvider)
}
KotlinJsBinaryType.DEVELOPMENT -> {
it.dependsOn(compileKotlinTask)
}
} }
// Breaking of Task Configuration Avoidance is not so critical
// because this task is dependent on DCE task
it.entry = actualDceTaskProvider.get()
.destinationDir
.resolve(compileKotlinTask.outputFile.name)
it.dependsOn(actualDceTaskProvider)
it.resolveFromModulesFirst = true
commonRunConfigurations.forEach { configure -> commonRunConfigurations.forEach { configure ->
it.configure() it.configure()
} }
@@ -142,7 +158,8 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
private fun configureBuild( private fun configureBuild(
compilation: KotlinJsCompilation, compilation: KotlinJsCompilation,
dceTaskProvider: TaskProvider<KotlinJsDceTask> dceTaskProvider: TaskProvider<KotlinJsDceTask>,
devDceTaskProvider: TaskProvider<KotlinJsDceTask>
) { ) {
val project = compilation.target.project val project = compilation.target.project
val nodeJs = NodeJsRootPlugin.apply(project.rootProject) val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
@@ -186,21 +203,19 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
it.description = "build webpack ${type.name.toLowerCase()} bundle" it.description = "build webpack ${type.name.toLowerCase()} bundle"
it._destinationDirectory = distribution.directory it._destinationDirectory = distribution.directory
when (type) { val actualDceTaskProvider = when (type) {
KotlinJsBinaryType.PRODUCTION -> { KotlinJsBinaryType.PRODUCTION -> dceTaskProvider
// Breaking of Task Configuration Avoidance is not so critical KotlinJsBinaryType.DEVELOPMENT -> devDceTaskProvider
// because this task is dependent on DCE task
it.entry = dceTaskProvider.get()
.destinationDir
.resolve(compileKotlinTask.outputFile.name)
it.resolveFromModulesFirst = true
it.dependsOn(dceTaskProvider)
}
KotlinJsBinaryType.DEVELOPMENT -> {
it.dependsOn(compileKotlinTask)
}
} }
// Breaking of Task Configuration Avoidance is not so critical
// because this task is dependent on DCE task
it.entry = actualDceTaskProvider.get()
.destinationDir
.resolve(compileKotlinTask.outputFile.name)
it.dependsOn(actualDceTaskProvider)
commonWebpackConfigurations.forEach { configure -> commonWebpackConfigurations.forEach { configure ->
it.configure() it.configure()
} }
@@ -223,11 +238,15 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
} }
} }
private fun configureDce(compilation: KotlinJsCompilation): TaskProvider<KotlinJsDceTask> { private fun configureDce(
compilation: KotlinJsCompilation,
dev: Boolean
): TaskProvider<KotlinJsDceTask> {
val project = compilation.target.project val project = compilation.target.project
val dceTaskName = lowerCamelCaseName( val dceTaskName = lowerCamelCaseName(
DCE_TASK_PREFIX, DCE_TASK_PREFIX,
if (dev) DCE_DEV_PART else null,
compilation.target.disambiguationClassifier, compilation.target.disambiguationClassifier,
compilation.name.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME }, compilation.name.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME },
DCE_TASK_SUFFIX DCE_TASK_SUFFIX
@@ -236,8 +255,12 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
val kotlinTask = compilation.compileKotlinTask val kotlinTask = compilation.compileKotlinTask
return project.registerTask(dceTaskName) { return project.registerTask(dceTaskName) {
dceConfigurations.forEach { configure -> if (dev) {
it.configure() it.dceOptions.devMode = true
} else {
dceConfigurations.forEach { configure ->
it.configure()
}
} }
it.dependsOn(kotlinTask) it.dependsOn(kotlinTask)
@@ -246,7 +269,7 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
it.classpath = project.configurations.getByName(compilation.runtimeDependencyConfigurationName) it.classpath = project.configurations.getByName(compilation.runtimeDependencyConfigurationName)
it.destinationDir = it.dceOptions.outputDirectory?.let { File(it) } it.destinationDir = it.dceOptions.outputDirectory?.let { File(it) }
?: compilation.npmProject.dir.resolve(DCE_DIR) ?: compilation.npmProject.dir.resolve(if (dev) DCE_DEV_DIR else DCE_DIR)
it.source(kotlinTask.outputFile) it.source(kotlinTask.outputFile)
} }
@@ -277,9 +300,11 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
companion object { companion object {
const val DCE_TASK_PREFIX = "processDce" const val DCE_TASK_PREFIX = "processDce"
private const val DCE_DEV_PART = "dev"
const val DCE_TASK_SUFFIX = "kotlinJs" const val DCE_TASK_SUFFIX = "kotlinJs"
const val DCE_DIR = "kotlin-dce" const val DCE_DIR = "kotlin-dce"
const val DCE_DEV_DIR = "kotlin-dce-dev"
const val PRODUCTION = "production" const val PRODUCTION = "production"
const val DEVELOPMENT = "development" const val DEVELOPMENT = "development"