[Gradle, JS] Different distributions for different binaries
^KT-41566 fixed
This commit is contained in:
+1
@@ -8,5 +8,6 @@ package org.jetbrains.kotlin.gradle.targets.js.dsl
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
interface Distribution {
|
interface Distribution {
|
||||||
|
var name: String?
|
||||||
var directory: File
|
var directory: File
|
||||||
}
|
}
|
||||||
+8
-2
@@ -24,11 +24,11 @@ interface JsBinary {
|
|||||||
|
|
||||||
sealed class JsIrBinary(
|
sealed class JsIrBinary(
|
||||||
final override val compilation: KotlinJsCompilation,
|
final override val compilation: KotlinJsCompilation,
|
||||||
override val name: String,
|
final override val name: String,
|
||||||
override val mode: KotlinJsBinaryMode
|
override val mode: KotlinJsBinaryMode
|
||||||
) : JsBinary {
|
) : JsBinary {
|
||||||
override val distribution: Distribution =
|
override val distribution: Distribution =
|
||||||
DefaultDistribution(compilation.target.project)
|
DefaultDistribution(compilation.target.project, name)
|
||||||
|
|
||||||
val linkTaskName: String = linkTaskName()
|
val linkTaskName: String = linkTaskName()
|
||||||
|
|
||||||
@@ -61,6 +61,12 @@ class Executable(
|
|||||||
name,
|
name,
|
||||||
mode
|
mode
|
||||||
) {
|
) {
|
||||||
|
override val distribution: Distribution =
|
||||||
|
DefaultDistribution(
|
||||||
|
compilation.target.project,
|
||||||
|
if (mode == KotlinJsBinaryMode.PRODUCTION) null else super.distribution.name
|
||||||
|
)
|
||||||
|
|
||||||
val executeTaskBaseName: String =
|
val executeTaskBaseName: String =
|
||||||
generateBinaryName(
|
generateBinaryName(
|
||||||
compilation,
|
compilation,
|
||||||
|
|||||||
+37
-33
@@ -152,26 +152,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
binary as Executable
|
binary as Executable
|
||||||
|
|
||||||
val mode = binary.mode
|
val mode = binary.mode
|
||||||
val webpackTask = registerSubTargetTask<KotlinWebpack>(
|
|
||||||
disambiguateCamelCased(
|
|
||||||
binary.executeTaskBaseName,
|
|
||||||
WEBPACK_TASK_NAME
|
|
||||||
),
|
|
||||||
listOf(compilation)
|
|
||||||
) { task ->
|
|
||||||
val entryFileProvider = binary.linkTask.map { it.outputFile }
|
|
||||||
|
|
||||||
task.description = "build webpack ${mode.name.toLowerCase()} bundle"
|
|
||||||
task._destinationDirectory = distribution.directory
|
|
||||||
|
|
||||||
task.commonConfigure(
|
|
||||||
compilation = compilation,
|
|
||||||
mode = mode,
|
|
||||||
entryFileProvider = entryFileProvider,
|
|
||||||
configurationActions = webpackTaskConfigurations,
|
|
||||||
nodeJs = nodeJs
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val distributeResourcesTask = registerSubTargetTask<Copy>(
|
val distributeResourcesTask = registerSubTargetTask<Copy>(
|
||||||
disambiguateCamelCased(
|
disambiguateCamelCased(
|
||||||
@@ -183,25 +163,49 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
it.into(binary.distribution.directory)
|
it.into(binary.distribution.directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == KotlinJsBinaryMode.PRODUCTION) {
|
val webpackTask = registerSubTargetTask<KotlinWebpack>(
|
||||||
assembleTaskProvider.dependsOn(webpackTask)
|
disambiguateCamelCased(
|
||||||
val webpackCommonTask = registerSubTargetTask<Task>(
|
binary.executeTaskBaseName,
|
||||||
disambiguateCamelCased(WEBPACK_TASK_NAME)
|
WEBPACK_TASK_NAME
|
||||||
) {
|
),
|
||||||
it.dependsOn(webpackTask)
|
listOf(compilation)
|
||||||
}
|
) { task ->
|
||||||
|
val entryFileProvider = binary.linkTask.map { it.outputFile }
|
||||||
|
|
||||||
webpackTask.dependsOn(
|
task.description = "build webpack ${mode.name.toLowerCase()} bundle"
|
||||||
|
task._destinationDirectory = binary.distribution.directory
|
||||||
|
|
||||||
|
task.dependsOn(
|
||||||
distributeResourcesTask
|
distributeResourcesTask
|
||||||
)
|
)
|
||||||
|
|
||||||
assembleTaskProvider.dependsOn(distributeResourcesTask)
|
task.commonConfigure(
|
||||||
|
compilation = compilation,
|
||||||
|
mode = mode,
|
||||||
|
entryFileProvider = entryFileProvider,
|
||||||
|
configurationActions = webpackTaskConfigurations,
|
||||||
|
nodeJs = nodeJs
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
registerSubTargetTask<Task>(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) {
|
val distributionTask = registerSubTargetTask<Task>(
|
||||||
it.dependsOn(webpackCommonTask)
|
disambiguateCamelCased(
|
||||||
it.dependsOn(distributeResourcesTask)
|
if (binary.mode == KotlinJsBinaryMode.PRODUCTION) "" else binary.name,
|
||||||
|
DISTRIBUTION_TASK_NAME
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
it.dependsOn(webpackTask)
|
||||||
|
it.dependsOn(distributeResourcesTask)
|
||||||
|
|
||||||
it.outputs.dir(project.newFileProperty { distribution.directory })
|
it.outputs.dir(project.newFileProperty { binary.distribution.directory })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode == KotlinJsBinaryMode.PRODUCTION) {
|
||||||
|
assembleTaskProvider.dependsOn(distributionTask)
|
||||||
|
registerSubTargetTask<Task>(
|
||||||
|
disambiguateCamelCased(WEBPACK_TASK_NAME)
|
||||||
|
) {
|
||||||
|
it.dependsOn(webpackTask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-16
@@ -48,11 +48,12 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
|
|
||||||
protected val taskGroupName = "Kotlin $disambiguationClassifier"
|
protected val taskGroupName = "Kotlin $disambiguationClassifier"
|
||||||
|
|
||||||
protected val distribution: Distribution = DefaultDistribution(project)
|
|
||||||
|
|
||||||
@ExperimentalDistributionDsl
|
@ExperimentalDistributionDsl
|
||||||
override fun distribution(body: Distribution.() -> Unit) {
|
override fun distribution(body: Distribution.() -> Unit) {
|
||||||
distribution.body()
|
target.binaries
|
||||||
|
.all {
|
||||||
|
it.distribution.body()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun configure() {
|
internal fun configure() {
|
||||||
@@ -228,19 +229,19 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
it.into(binary.distribution.directory)
|
it.into(binary.distribution.directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val distributionTask = registerSubTargetTask<Task>(
|
||||||
|
disambiguateCamelCased(
|
||||||
|
binary.name,
|
||||||
|
DISTRIBUTION_TASK_NAME
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
it.dependsOn(prepareJsLibrary)
|
||||||
|
|
||||||
|
it.outputs.dir(project.newFileProperty { binary.distribution.directory })
|
||||||
|
}
|
||||||
|
|
||||||
if (mode == KotlinJsBinaryMode.PRODUCTION) {
|
if (mode == KotlinJsBinaryMode.PRODUCTION) {
|
||||||
assembleTaskProvider.dependsOn(prepareJsLibrary)
|
assembleTaskProvider.dependsOn(distributionTask)
|
||||||
|
|
||||||
registerSubTargetTask<Task>(
|
|
||||||
disambiguateCamelCased(
|
|
||||||
binary.name,
|
|
||||||
DISTRIBUTION_TASK_NAME
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
it.dependsOn(prepareJsLibrary)
|
|
||||||
|
|
||||||
it.outputs.dir(project.newFileProperty { distribution.directory })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,6 +262,6 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
const val DISTRIBUTE_RESOURCES_TASK_NAME = "distributeResources"
|
const val DISTRIBUTE_RESOURCES_TASK_NAME = "distributeResources"
|
||||||
const val DISTRIBUTION_TASK_NAME = "distribution"
|
const val DISTRIBUTION_TASK_NAME = "distribution"
|
||||||
|
|
||||||
const val PREPARE_JS_LIBRARY_TASK_NAME = "prepareJsLibrary"
|
const val PREPARE_JS_LIBRARY_TASK_NAME = "prepare"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+8
-2
@@ -11,12 +11,18 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.Distribution
|
|||||||
import org.jetbrains.kotlin.gradle.utils.property
|
import org.jetbrains.kotlin.gradle.utils.property
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class DefaultDistribution(private val project: Project) : Distribution {
|
class DefaultDistribution(
|
||||||
|
private val project: Project,
|
||||||
|
override var name: String? = null
|
||||||
|
) : Distribution {
|
||||||
|
|
||||||
private val basePluginConvention: BasePluginConvention
|
private val basePluginConvention: BasePluginConvention
|
||||||
get() = project.convention.plugins["base"] as BasePluginConvention
|
get() = project.convention.plugins["base"] as BasePluginConvention
|
||||||
|
|
||||||
override var directory: File by property {
|
override var directory: File by property {
|
||||||
project.buildDir.resolve(basePluginConvention.distsDirName)
|
project.buildDir
|
||||||
|
.let { buildDir ->
|
||||||
|
name?.let { buildDir.resolve(it) } ?: buildDir.resolve(basePluginConvention.distsDirName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user