[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
|
||||
|
||||
interface Distribution {
|
||||
var name: String?
|
||||
var directory: File
|
||||
}
|
||||
+8
-2
@@ -24,11 +24,11 @@ interface JsBinary {
|
||||
|
||||
sealed class JsIrBinary(
|
||||
final override val compilation: KotlinJsCompilation,
|
||||
override val name: String,
|
||||
final override val name: String,
|
||||
override val mode: KotlinJsBinaryMode
|
||||
) : JsBinary {
|
||||
override val distribution: Distribution =
|
||||
DefaultDistribution(compilation.target.project)
|
||||
DefaultDistribution(compilation.target.project, name)
|
||||
|
||||
val linkTaskName: String = linkTaskName()
|
||||
|
||||
@@ -61,6 +61,12 @@ class Executable(
|
||||
name,
|
||||
mode
|
||||
) {
|
||||
override val distribution: Distribution =
|
||||
DefaultDistribution(
|
||||
compilation.target.project,
|
||||
if (mode == KotlinJsBinaryMode.PRODUCTION) null else super.distribution.name
|
||||
)
|
||||
|
||||
val executeTaskBaseName: String =
|
||||
generateBinaryName(
|
||||
compilation,
|
||||
|
||||
+37
-33
@@ -152,26 +152,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
binary as Executable
|
||||
|
||||
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>(
|
||||
disambiguateCamelCased(
|
||||
@@ -183,25 +163,49 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
it.into(binary.distribution.directory)
|
||||
}
|
||||
|
||||
if (mode == KotlinJsBinaryMode.PRODUCTION) {
|
||||
assembleTaskProvider.dependsOn(webpackTask)
|
||||
val webpackCommonTask = registerSubTargetTask<Task>(
|
||||
disambiguateCamelCased(WEBPACK_TASK_NAME)
|
||||
) {
|
||||
it.dependsOn(webpackTask)
|
||||
}
|
||||
val webpackTask = registerSubTargetTask<KotlinWebpack>(
|
||||
disambiguateCamelCased(
|
||||
binary.executeTaskBaseName,
|
||||
WEBPACK_TASK_NAME
|
||||
),
|
||||
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
|
||||
)
|
||||
|
||||
assembleTaskProvider.dependsOn(distributeResourcesTask)
|
||||
task.commonConfigure(
|
||||
compilation = compilation,
|
||||
mode = mode,
|
||||
entryFileProvider = entryFileProvider,
|
||||
configurationActions = webpackTaskConfigurations,
|
||||
nodeJs = nodeJs
|
||||
)
|
||||
}
|
||||
|
||||
registerSubTargetTask<Task>(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) {
|
||||
it.dependsOn(webpackCommonTask)
|
||||
it.dependsOn(distributeResourcesTask)
|
||||
val distributionTask = registerSubTargetTask<Task>(
|
||||
disambiguateCamelCased(
|
||||
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 distribution: Distribution = DefaultDistribution(project)
|
||||
|
||||
@ExperimentalDistributionDsl
|
||||
override fun distribution(body: Distribution.() -> Unit) {
|
||||
distribution.body()
|
||||
target.binaries
|
||||
.all {
|
||||
it.distribution.body()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun configure() {
|
||||
@@ -228,19 +229,19 @@ abstract class KotlinJsIrSubTarget(
|
||||
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) {
|
||||
assembleTaskProvider.dependsOn(prepareJsLibrary)
|
||||
|
||||
registerSubTargetTask<Task>(
|
||||
disambiguateCamelCased(
|
||||
binary.name,
|
||||
DISTRIBUTION_TASK_NAME
|
||||
)
|
||||
) {
|
||||
it.dependsOn(prepareJsLibrary)
|
||||
|
||||
it.outputs.dir(project.newFileProperty { distribution.directory })
|
||||
}
|
||||
assembleTaskProvider.dependsOn(distributionTask)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -261,6 +262,6 @@ abstract class KotlinJsIrSubTarget(
|
||||
const val DISTRIBUTE_RESOURCES_TASK_NAME = "distributeResources"
|
||||
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 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
|
||||
get() = project.convention.plugins["base"] as BasePluginConvention
|
||||
|
||||
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