[Gradle, JS] Fix naming for webpack tasks

- while webpack is actual only for executable it is not necessary to add executable part
This commit is contained in:
Ilya Goncharov
2020-02-17 12:05:18 +03:00
parent 5828f8cbf2
commit 2b4f9302dc
4 changed files with 98 additions and 89 deletions
@@ -8,11 +8,13 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.TaskProvider
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.targets.js.dsl.BuildVariantKind import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsBinaryContainer.Companion.generateBinaryName
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
sealed class JsBinary( sealed class JsBinary(
internal val target: KotlinTarget, internal val compilation: KotlinJsCompilation,
internal val name: String, internal val name: String,
internal val type: BuildVariantKind internal val type: BuildVariantKind
) { ) {
@@ -26,32 +28,31 @@ sealed class JsBinary(
private fun linkTaskName(): String = private fun linkTaskName(): String =
lowerCamelCaseName( lowerCamelCaseName(
"compile", "compile",
type.name.toLowerCase(),
name, name,
"Kotlin", "Kotlin",
target.targetName target.targetName
) )
val target: KotlinTarget
get() = compilation.target
val project: Project val project: Project
get() = target.project get() = target.project
} }
class Executable( class Executable(
target: KotlinTarget, compilation: KotlinJsCompilation,
name: String, name: String,
type: BuildVariantKind type: BuildVariantKind
) : JsBinary( ) : JsBinary(
target, compilation,
name, name,
type type
) ) {
val executeTaskBaseName: String =
class TestExecutable( generateBinaryName(
target: KotlinTarget, compilation,
name: String, type,
type: BuildVariantKind null
) : JsBinary( )
target, }
name,
type
)
@@ -6,6 +6,5 @@
package org.jetbrains.kotlin.gradle.targets.js.ir package org.jetbrains.kotlin.gradle.targets.js.ir
enum class JsBinaryType { enum class JsBinaryType {
EXECUTABLE, EXECUTABLE
TEST
} }
@@ -64,12 +64,16 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
val commonRunTask = project.registerTask<Task>(disambiguateCamelCased(RUN_TASK_NAME)) {} val commonRunTask = project.registerTask<Task>(disambiguateCamelCased(RUN_TASK_NAME)) {}
compilation.binaries.all { binary -> compilation.binaries
.matching { it is Executable }
.all { binary ->
binary as Executable
val type = binary.type val type = binary.type
val runTask = project.registerTask<KotlinWebpack>( val runTask = project.registerTask<KotlinWebpack>(
disambiguateCamelCased( disambiguateCamelCased(
binary.name, binary.executeTaskBaseName,
RUN_TASK_NAME RUN_TASK_NAME
) )
) { ) {
@@ -132,11 +136,15 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME) val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
assembleTask.dependsOn(distributeResourcesTask) assembleTask.dependsOn(distributeResourcesTask)
compilation.binaries.all { binary -> compilation.binaries
.matching { it is Executable }
.all { binary ->
binary as Executable
val type = binary.type val type = binary.type
val webpackTask = project.registerTask<KotlinWebpack>( val webpackTask = project.registerTask<KotlinWebpack>(
disambiguateCamelCased( disambiguateCamelCased(
binary.name, binary.executeTaskBaseName,
WEBPACK_TASK_NAME WEBPACK_TASK_NAME
) )
) { ) {
@@ -9,7 +9,6 @@ import org.gradle.api.DomainObjectSet
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware import org.gradle.api.plugins.ExtensionAware
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
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.plugin.mpp.KotlinTargetWithBinaries import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinTargetWithBinaries
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
@@ -38,9 +37,11 @@ constructor(
compilation: KotlinJsCompilation = defaultCompilation compilation: KotlinJsCompilation = defaultCompilation
) { ) {
if (compilation !is KotlinJsIrCompilation) { if (compilation !is KotlinJsIrCompilation) {
throw IllegalArgumentException( project.logger.warn(
"Unable to create executable for $compilation. Use IR compiler (kotlin.js.compiler=true) instead." "binaries.executable configuration is useless with IR compiler." +
"Use produceExecutable() instead"
) )
return
} }
(target as KotlinJsSubTargetContainerDsl).whenBrowserConfigured { (target as KotlinJsSubTargetContainerDsl).whenBrowserConfigured {
@@ -70,7 +71,7 @@ constructor(
compilation: KotlinJsCompilation, compilation: KotlinJsCompilation,
buildVariantKinds: Collection<BuildVariantKind> = listOf(PRODUCTION, DEVELOPMENT), buildVariantKinds: Collection<BuildVariantKind> = listOf(PRODUCTION, DEVELOPMENT),
jsBinaryType: JsBinaryType, jsBinaryType: JsBinaryType,
create: (target: KotlinTarget, name: String, buildVariantKind: BuildVariantKind) -> T create: (compilation: KotlinJsCompilation, name: String, buildVariantKind: BuildVariantKind) -> T
) { ) {
buildVariantKinds.forEach { buildVariantKind -> buildVariantKinds.forEach { buildVariantKind ->
val name = generateBinaryName( val name = generateBinaryName(
@@ -83,7 +84,7 @@ constructor(
"Cannot create binary $name: binary with such a name already exists" "Cannot create binary $name: binary with such a name already exists"
} }
val binary = create(target, name, buildVariantKind) val binary = create(compilation, name, buildVariantKind)
add(binary) add(binary)
// Allow accessing binaries as properties of the container in Groovy DSL. // Allow accessing binaries as properties of the container in Groovy DSL.
if (this is ExtensionAware) { if (this is ExtensionAware) {
@@ -96,12 +97,12 @@ constructor(
internal fun generateBinaryName( internal fun generateBinaryName(
compilation: KotlinJsCompilation, compilation: KotlinJsCompilation,
buildVariantKind: BuildVariantKind, buildVariantKind: BuildVariantKind,
jsBinaryType: JsBinaryType jsBinaryType: JsBinaryType?
) = ) =
lowerCamelCaseName( lowerCamelCaseName(
compilation.name.let { if (it == KotlinCompilation.MAIN_COMPILATION_NAME) null else it }, compilation.name.let { if (it == KotlinCompilation.MAIN_COMPILATION_NAME) null else it },
buildVariantKind.name.toLowerCase(), buildVariantKind.name.toLowerCase(),
jsBinaryType.name.toLowerCase() jsBinaryType?.name?.toLowerCase()
) )
} }
} }