[Gradle, JS] NodeJs on binaries
This commit is contained in:
+15
-11
@@ -27,7 +27,8 @@ constructor(
|
|||||||
val project: Project
|
val project: Project
|
||||||
get() = target.project
|
get() = target.project
|
||||||
|
|
||||||
private val nameToBinary = mutableMapOf<String, JsBinary>()
|
private val binaryNames = mutableSetOf<String>()
|
||||||
|
private val compilationToBinaries = mutableMapOf<KotlinJsCompilation, MutableSet<JsBinary>>()
|
||||||
|
|
||||||
private val defaultCompilation: KotlinJsCompilation
|
private val defaultCompilation: KotlinJsCompilation
|
||||||
get() = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
get() = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
||||||
@@ -50,15 +51,12 @@ constructor(
|
|||||||
)
|
)
|
||||||
|
|
||||||
internal fun getBinary(
|
internal fun getBinary(
|
||||||
buildVariantKind: BuildVariantKind,
|
compilation: KotlinJsCompilation,
|
||||||
jsBinaryType: JsBinaryType
|
buildVariantKind: BuildVariantKind
|
||||||
): JsBinary =
|
): JsBinary =
|
||||||
nameToBinary.getValue(
|
compilationToBinaries.getValue(
|
||||||
generateBinaryName(
|
compilation
|
||||||
buildVariantKind,
|
).single { it.type == buildVariantKind }
|
||||||
jsBinaryType
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
private fun <T : JsBinary> createBinaries(
|
private fun <T : JsBinary> createBinaries(
|
||||||
@@ -73,13 +71,19 @@ constructor(
|
|||||||
jsBinaryType
|
jsBinaryType
|
||||||
)
|
)
|
||||||
|
|
||||||
require(name !in nameToBinary) {
|
require(name !in binaryNames) {
|
||||||
"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(name, buildVariantKind, compilation)
|
val binary = create(name, buildVariantKind, compilation)
|
||||||
add(binary)
|
add(binary)
|
||||||
nameToBinary[binary.name] = binary
|
with(compilationToBinaries[compilation]) {
|
||||||
|
if (this != null) {
|
||||||
|
add(binary)
|
||||||
|
} else {
|
||||||
|
compilationToBinaries[compilation] = mutableSetOf<JsBinary>(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) {
|
||||||
extensions.add(binary.name, binary)
|
extensions.add(binary.name, binary)
|
||||||
|
|||||||
+10
-12
@@ -36,6 +36,9 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
protected val binaries: KotlinJsBinaryContainer
|
||||||
|
get() = target.binaries
|
||||||
|
|
||||||
internal fun configure() {
|
internal fun configure() {
|
||||||
target.binaries.testExecutable()
|
target.binaries.testExecutable()
|
||||||
|
|
||||||
@@ -44,15 +47,10 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
configureBuildVariants()
|
configureBuildVariants()
|
||||||
configureTests()
|
configureTests()
|
||||||
|
|
||||||
target.compilations.all {
|
binaries.all { binary ->
|
||||||
val npmProject = it.npmProject
|
val npmProject = binary.compilation.npmProject
|
||||||
listOf(
|
binary.linkTask.configure {
|
||||||
it.productionLinkTask,
|
it.kotlinOptions.outputFile = npmProject.dir.resolve(npmProject.main).canonicalPath
|
||||||
it.developmentLinkTask
|
|
||||||
).forEach { taskProvider ->
|
|
||||||
taskProvider.configure {
|
|
||||||
it.kotlinOptions.outputFile = npmProject.dir.resolve(npmProject.main).canonicalPath
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,9 +95,9 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||||
testJs.description = testTaskDescription
|
testJs.description = testTaskDescription
|
||||||
|
|
||||||
val testExecutableTask = target.binaries.getBinary(
|
val testExecutableTask = binaries.getBinary(
|
||||||
BuildVariantKind.DEVELOPMENT,
|
compilation,
|
||||||
JsBinaryType.TEST
|
BuildVariantKind.DEVELOPMENT
|
||||||
).linkTask
|
).linkTask
|
||||||
|
|
||||||
testJs.inputFileProperty.set(
|
testJs.inputFileProperty.set(
|
||||||
|
|||||||
+7
-2
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||||
|
|
||||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
|
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||||
@@ -30,8 +31,10 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
override fun configureRun(
|
override fun configureRun(
|
||||||
compilation: KotlinJsIrCompilation
|
compilation: KotlinJsIrCompilation
|
||||||
) {
|
) {
|
||||||
|
val developmentExecutable = binaries.getBinary(compilation, BuildVariantKind.DEVELOPMENT)
|
||||||
|
|
||||||
val runTaskHolder = NodeJsExec.create(compilation, disambiguateCamelCased(RUN_TASK_NAME)) {
|
val runTaskHolder = NodeJsExec.create(compilation, disambiguateCamelCased(RUN_TASK_NAME)) {
|
||||||
inputFileProperty.set(compilation.developmentLinkTask.map { it.outputFileProperty.get() })
|
inputFileProperty.set(developmentExecutable.linkTask.map { it.outputFileProperty.get() })
|
||||||
}
|
}
|
||||||
target.runTask.dependsOn(runTaskHolder)
|
target.runTask.dependsOn(runTaskHolder)
|
||||||
}
|
}
|
||||||
@@ -39,8 +42,10 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
override fun configureBuild(
|
override fun configureBuild(
|
||||||
compilation: KotlinJsIrCompilation
|
compilation: KotlinJsIrCompilation
|
||||||
) {
|
) {
|
||||||
|
val productionExecutable = binaries.getBinary(compilation, BuildVariantKind.PRODUCTION)
|
||||||
|
|
||||||
val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
|
val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
|
||||||
assembleTask.dependsOn(compilation.productionLinkTask)
|
assembleTask.dependsOn(productionExecutable.linkTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun configureBuildVariants() {
|
override fun configureBuildVariants() {
|
||||||
|
|||||||
Reference in New Issue
Block a user