[Gradle, JS] Remove DCE from ir tooling
This commit is contained in:
-10
@@ -141,16 +141,6 @@ interface KotlinJsIrBrowserDsl : KotlinJsIrSubTargetDsl {
|
|||||||
ConfigureUtil.configure(fn, this)
|
ConfigureUtil.configure(fn, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExperimentalDceDsl
|
|
||||||
fun dceTask(body: KotlinJsDce.() -> Unit)
|
|
||||||
|
|
||||||
@ExperimentalDceDsl
|
|
||||||
fun dceTask(fn: Closure<*>) {
|
|
||||||
dceTask {
|
|
||||||
ConfigureUtil.configure(fn, this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface KotlinJsNodeDsl : KotlinJsSubTargetDsl {
|
interface KotlinJsNodeDsl : KotlinJsSubTargetDsl {
|
||||||
|
|||||||
+6
-85
@@ -9,14 +9,10 @@ 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.dsl.KotlinJsDce
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||||
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
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.subtargets.BrowserDistribution
|
import org.jetbrains.kotlin.gradle.targets.js.subtargets.BrowserDistribution
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
|
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
|
||||||
@@ -24,10 +20,7 @@ import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
|
|||||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Devtool
|
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Devtool
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Mode
|
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Mode
|
||||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
|
||||||
import java.io.File
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinJsDce as KotlinJsDceTask
|
|
||||||
|
|
||||||
open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||||
KotlinJsIrSubTarget(target, "browser"),
|
KotlinJsIrSubTarget(target, "browser"),
|
||||||
@@ -35,7 +28,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
|
|
||||||
private val commonWebpackConfigurations: MutableList<KotlinWebpack.() -> Unit> = mutableListOf()
|
private val commonWebpackConfigurations: MutableList<KotlinWebpack.() -> Unit> = mutableListOf()
|
||||||
private val commonRunConfigurations: MutableList<KotlinWebpack.() -> Unit> = mutableListOf()
|
private val commonRunConfigurations: MutableList<KotlinWebpack.() -> Unit> = mutableListOf()
|
||||||
private val dceConfigurations: MutableList<KotlinJsDce.() -> Unit> = mutableListOf()
|
|
||||||
private val distribution: Distribution = BrowserDistribution()
|
private val distribution: Distribution = BrowserDistribution()
|
||||||
|
|
||||||
private lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
private lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
||||||
@@ -62,21 +54,13 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
commonWebpackConfigurations.add(body)
|
commonWebpackConfigurations.add(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExperimentalDceDsl
|
|
||||||
override fun dceTask(body: KotlinJsDce.() -> Unit) {
|
|
||||||
dceConfigurations.add(body)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun configureMain(compilation: KotlinJsCompilation) {
|
override fun configureMain(compilation: KotlinJsCompilation) {
|
||||||
val dceTaskProvider = configureDce(compilation)
|
configureRun(compilation)
|
||||||
|
configureBuild(compilation)
|
||||||
configureRun(compilation, dceTaskProvider)
|
|
||||||
configureBuild(compilation, dceTaskProvider)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureRun(
|
private fun configureRun(
|
||||||
compilation: KotlinJsCompilation,
|
compilation: KotlinJsCompilation
|
||||||
dceTaskProvider: TaskProvider<KotlinJsDceTask>
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val project = compilation.target.project
|
val project = compilation.target.project
|
||||||
@@ -94,6 +78,7 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
) {
|
) {
|
||||||
it.dependsOn(
|
it.dependsOn(
|
||||||
nodeJs.npmInstallTask,
|
nodeJs.npmInstallTask,
|
||||||
|
compileKotlinTask,
|
||||||
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -110,21 +95,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
|
|
||||||
it.outputs.upToDateWhen { false }
|
it.outputs.upToDateWhen { false }
|
||||||
|
|
||||||
when (kind) {
|
|
||||||
BuildVariantKind.PRODUCTION -> {
|
|
||||||
// Breaking of Task Configuration Avoidance is not so critical
|
|
||||||
// because this task is dependent on DCE task
|
|
||||||
it.entry = dceTaskProvider.get()
|
|
||||||
.destinationDir
|
|
||||||
.resolve(compileKotlinTask.outputFile.name)
|
|
||||||
it.resolveFromModulesFirst = true
|
|
||||||
it.dependsOn(dceTaskProvider)
|
|
||||||
}
|
|
||||||
BuildVariantKind.DEVELOPMENT -> {
|
|
||||||
it.dependsOn(compileKotlinTask)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
commonRunConfigurations.forEach { configure ->
|
commonRunConfigurations.forEach { configure ->
|
||||||
it.configure()
|
it.configure()
|
||||||
}
|
}
|
||||||
@@ -140,8 +110,7 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun configureBuild(
|
private fun configureBuild(
|
||||||
compilation: KotlinJsCompilation,
|
compilation: KotlinJsCompilation
|
||||||
dceTaskProvider: TaskProvider<KotlinJsDceTask>
|
|
||||||
) {
|
) {
|
||||||
val project = compilation.target.project
|
val project = compilation.target.project
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
@@ -176,6 +145,7 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
) {
|
) {
|
||||||
it.dependsOn(
|
it.dependsOn(
|
||||||
nodeJs.npmInstallTask,
|
nodeJs.npmInstallTask,
|
||||||
|
compileKotlinTask,
|
||||||
target.project.tasks.getByName(compilation.processResourcesTaskName),
|
target.project.tasks.getByName(compilation.processResourcesTaskName),
|
||||||
distributionTask
|
distributionTask
|
||||||
)
|
)
|
||||||
@@ -186,21 +156,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
||||||
it.destinationDirectory = distribution.directory
|
it.destinationDirectory = distribution.directory
|
||||||
|
|
||||||
when (kind) {
|
|
||||||
BuildVariantKind.PRODUCTION -> {
|
|
||||||
// Breaking of Task Configuration Avoidance is not so critical
|
|
||||||
// because this task is dependent on DCE task
|
|
||||||
it.entry = dceTaskProvider.get()
|
|
||||||
.destinationDir
|
|
||||||
.resolve(compileKotlinTask.outputFile.name)
|
|
||||||
it.resolveFromModulesFirst = true
|
|
||||||
it.dependsOn(dceTaskProvider)
|
|
||||||
}
|
|
||||||
BuildVariantKind.DEVELOPMENT -> {
|
|
||||||
it.dependsOn(compileKotlinTask)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
commonWebpackConfigurations.forEach { configure ->
|
commonWebpackConfigurations.forEach { configure ->
|
||||||
it.configure()
|
it.configure()
|
||||||
}
|
}
|
||||||
@@ -215,35 +170,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureDce(compilation: KotlinJsCompilation): TaskProvider<KotlinJsDceTask> {
|
|
||||||
val project = compilation.target.project
|
|
||||||
|
|
||||||
val dceTaskName = lowerCamelCaseName(
|
|
||||||
DCE_TASK_PREFIX,
|
|
||||||
compilation.target.disambiguationClassifier,
|
|
||||||
compilation.name.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME },
|
|
||||||
DCE_TASK_SUFFIX
|
|
||||||
)
|
|
||||||
|
|
||||||
val kotlinTask = compilation.compileKotlinTask
|
|
||||||
|
|
||||||
return project.registerTask(dceTaskName) {
|
|
||||||
dceConfigurations.forEach { configure ->
|
|
||||||
it.configure()
|
|
||||||
}
|
|
||||||
|
|
||||||
it.dependsOn(kotlinTask)
|
|
||||||
|
|
||||||
it.kotlinFilesOnly = true
|
|
||||||
|
|
||||||
it.classpath = project.configurations.getByName(compilation.runtimeDependencyConfigurationName)
|
|
||||||
it.destinationDir = it.dceOptions.outputDirectory?.let { File(it) }
|
|
||||||
?: compilation.npmProject.dir.resolve(DCE_DIR)
|
|
||||||
|
|
||||||
it.source(kotlinTask.outputFile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun KotlinWebpack.configureOptimization(kind: BuildVariantKind) {
|
private fun KotlinWebpack.configureOptimization(kind: BuildVariantKind) {
|
||||||
mode = getByKind(
|
mode = getByKind(
|
||||||
kind = kind,
|
kind = kind,
|
||||||
@@ -278,11 +204,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val DCE_TASK_PREFIX = "processDce"
|
|
||||||
const val DCE_TASK_SUFFIX = "kotlinJs"
|
|
||||||
|
|
||||||
const val DCE_DIR = "kotlin-dce"
|
|
||||||
|
|
||||||
const val PRODUCTION = "production"
|
const val PRODUCTION = "production"
|
||||||
const val DEVELOPMENT = "development"
|
const val DEVELOPMENT = "development"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user