Update KotlinJsDce task to use compiler options
^KT-27301 In Progress
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.tasks
|
||||
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.Nested
|
||||
import org.jetbrains.kotlin.gradle.dsl.CompilerCommonToolOptions
|
||||
|
||||
interface KotlinToolTask<out TO : CompilerCommonToolOptions> : Task {
|
||||
@get:Nested
|
||||
val toolOptions: TO
|
||||
|
||||
fun toolOptions(configure: TO.() -> Unit) {
|
||||
configure(toolOptions)
|
||||
}
|
||||
|
||||
fun toolOptions(configure: Action<in TO>) {
|
||||
configure.execute(toolOptions)
|
||||
}
|
||||
}
|
||||
+15
@@ -33,16 +33,31 @@ interface KotlinJvmCompile : KotlinJvmCompileApi
|
||||
interface KotlinCommonCompile : KotlinCompile<KotlinMultiplatformCommonOptions>
|
||||
|
||||
interface KotlinJsDce : Task {
|
||||
@Suppress("DEPRECATION")
|
||||
@Deprecated(
|
||||
message = "Replaced with toolOptions",
|
||||
replaceWith = ReplaceWith("toolOptions")
|
||||
)
|
||||
@get:Internal
|
||||
val dceOptions: KotlinJsDceOptions
|
||||
|
||||
@get:Input
|
||||
val keep: MutableList<String>
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@Deprecated(
|
||||
message = "Replaced with toolOptions()",
|
||||
replaceWith = ReplaceWith("toolOptions(fn)")
|
||||
)
|
||||
fun dceOptions(fn: KotlinJsDceOptions.() -> Unit) {
|
||||
dceOptions.fn()
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@Deprecated(
|
||||
message = "Replaced with toolOptions()",
|
||||
replaceWith = ReplaceWith("toolOptions(fn)")
|
||||
)
|
||||
fun dceOptions(fn: Closure<*>) {
|
||||
fn.delegate = dceOptions
|
||||
fn.call()
|
||||
|
||||
+16
-9
@@ -28,12 +28,14 @@ import org.jetbrains.kotlin.cli.common.arguments.DevModeOverwritingStrategies
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSDceArguments
|
||||
import org.jetbrains.kotlin.cli.js.dce.K2JSDce
|
||||
import org.jetbrains.kotlin.compilerRunner.runToolInSeparateProcess
|
||||
import org.jetbrains.kotlin.gradle.dsl.CompilerJsDceOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.CompilerJsDceOptionsDefault
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDce
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDceOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDceOptionsImpl
|
||||
import org.jetbrains.kotlin.gradle.logging.GradleKotlinLogger
|
||||
import org.jetbrains.kotlin.gradle.utils.canonicalPathWithoutExtension
|
||||
import org.jetbrains.kotlin.gradle.utils.fileExtensionCasePermutations
|
||||
import org.jetbrains.kotlin.gradle.utils.newInstance
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -41,6 +43,7 @@ import javax.inject.Inject
|
||||
abstract class KotlinJsDce @Inject constructor(
|
||||
objectFactory: ObjectFactory
|
||||
) : AbstractKotlinCompileTool<K2JSDceArguments>(objectFactory),
|
||||
KotlinToolTask<CompilerJsDceOptions>,
|
||||
KotlinJsDce {
|
||||
|
||||
init {
|
||||
@@ -50,22 +53,26 @@ abstract class KotlinJsDce @Inject constructor(
|
||||
include("js".fileExtensionCasePermutations().map { "**/*.$it" })
|
||||
}
|
||||
|
||||
override val toolOptions: CompilerJsDceOptions = objectFactory.newInstance<CompilerJsDceOptionsDefault>()
|
||||
|
||||
override fun createCompilerArgs(): K2JSDceArguments = K2JSDceArguments()
|
||||
|
||||
override fun setupCompilerArgs(args: K2JSDceArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
dceOptionsImpl.updateArguments(args)
|
||||
(toolOptions as CompilerJsDceOptionsDefault).fillCompilerArguments(args)
|
||||
args.declarationsToKeep = keep.toTypedArray()
|
||||
}
|
||||
|
||||
private val dceOptionsImpl = KotlinJsDceOptionsImpl()
|
||||
|
||||
// DCE can be broken in case of non-kotlin js files or modules
|
||||
@Internal
|
||||
var kotlinFilesOnly: Boolean = false
|
||||
|
||||
@Deprecated("Replaced with toolOptions", replaceWith = ReplaceWith("toolOptions"))
|
||||
@Suppress("DEPRECATION")
|
||||
@get:Internal
|
||||
override val dceOptions: KotlinJsDceOptions
|
||||
get() = dceOptionsImpl
|
||||
override val dceOptions: KotlinJsDceOptions = object : KotlinJsDceOptions {
|
||||
override val options: CompilerJsDceOptions
|
||||
get() = toolOptions
|
||||
}
|
||||
|
||||
@get:Input
|
||||
override val keep: MutableList<String> = mutableListOf()
|
||||
@@ -93,11 +100,11 @@ abstract class KotlinJsDce @Inject constructor(
|
||||
private val buildDir = project.layout.buildDirectory
|
||||
|
||||
private val isDevMode
|
||||
get() = dceOptions.devMode || "-dev-mode" in dceOptions.freeCompilerArgs
|
||||
get() = toolOptions.devMode.get() || toolOptions.freeCompilerArgs.get().contains("-dev-mode")
|
||||
|
||||
private val isExplicitDevModeAllStrategy
|
||||
get() = strategyAllArg in dceOptions.freeCompilerArgs ||
|
||||
strategyOlderArg !in dceOptions.freeCompilerArgs &&
|
||||
get() = strategyAllArg in toolOptions.freeCompilerArgs.get() ||
|
||||
strategyOlderArg !in toolOptions.freeCompilerArgs.get() &&
|
||||
System.getProperty("kotlin.js.dce.devmode.overwriting.strategy") == DevModeOverwritingStrategies.ALL
|
||||
|
||||
@TaskAction
|
||||
|
||||
Reference in New Issue
Block a user