[Gradle, JS] Register executable tasks for binaries
This commit is contained in:
+11
-10
@@ -38,7 +38,6 @@ import org.jetbrains.kotlin.gradle.model.builder.KotlinModelBuilder
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||||
import org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin
|
import org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin
|
||||||
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.KotlinJsIrCompilation
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||||
@@ -267,7 +266,9 @@ internal class Kotlin2JsSourceSetProcessor(
|
|||||||
kotlinCompilation: AbstractKotlinCompilation<*>,
|
kotlinCompilation: AbstractKotlinCompilation<*>,
|
||||||
private val kotlinPluginVersion: String
|
private val kotlinPluginVersion: String
|
||||||
) : KotlinSourceSetProcessor<Kotlin2JsCompile>(
|
) : KotlinSourceSetProcessor<Kotlin2JsCompile>(
|
||||||
tasksProvider, taskDescription = "Compiles the Kotlin sources in $kotlinCompilation to JavaScript.", kotlinCompilation = kotlinCompilation
|
tasksProvider,
|
||||||
|
taskDescription = "Compiles the Kotlin sources in $kotlinCompilation to JavaScript.",
|
||||||
|
kotlinCompilation = kotlinCompilation
|
||||||
) {
|
) {
|
||||||
override fun doRegisterTask(
|
override fun doRegisterTask(
|
||||||
project: Project,
|
project: Project,
|
||||||
@@ -349,15 +350,15 @@ internal class KotlinJsIrSourceSetProcessor(
|
|||||||
it.dependsOn(kotlinTask)
|
it.dependsOn(kotlinTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
val compilation = kotlinCompilation as KotlinJsIrCompilation
|
(kotlinCompilation.target as KotlinJsIrTarget).binaries
|
||||||
|
.matching { it.compilation == kotlinCompilation }
|
||||||
(compilation.target as KotlinJsIrTarget).binaries.all { binary ->
|
.all { binary ->
|
||||||
registerKotlinCompileTask(
|
registerKotlinCompileTask(
|
||||||
binary.linkTaskName
|
binary.linkTaskName
|
||||||
) { project, name, action ->
|
) { project, name, action ->
|
||||||
registerJsLink(project, name, binary.type, action)
|
registerJsLink(project, name, binary.type, action)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// outputFile can be set later during the configuration phase, get it only after the phase:
|
// outputFile can be set later during the configuration phase, get it only after the phase:
|
||||||
project.runOnceAfterEvaluated("KotlinJsIrSourceSetProcessor.doTargetSpecificProcessing", kotlinTask) {
|
project.runOnceAfterEvaluated("KotlinJsIrSourceSetProcessor.doTargetSpecificProcessing", kotlinTask) {
|
||||||
|
|||||||
+6
-7
@@ -35,20 +35,25 @@ constructor(
|
|||||||
private val defaultTestCompilation: KotlinJsCompilation
|
private val defaultTestCompilation: KotlinJsCompilation
|
||||||
get() = target.compilations.getByName(KotlinCompilation.TEST_COMPILATION_NAME)
|
get() = target.compilations.getByName(KotlinCompilation.TEST_COMPILATION_NAME)
|
||||||
|
|
||||||
fun executable() = createBinaries(
|
fun executable(
|
||||||
|
compilation: KotlinJsCompilation = defaultCompilation
|
||||||
|
) = createBinaries(
|
||||||
baseName = project.name,
|
baseName = project.name,
|
||||||
|
compilation = compilation,
|
||||||
jsBinaryType = JsBinaryType.EXECUTABLE,
|
jsBinaryType = JsBinaryType.EXECUTABLE,
|
||||||
create = ::Executable
|
create = ::Executable
|
||||||
)
|
)
|
||||||
|
|
||||||
internal fun testExecutable() = createBinaries(
|
internal fun testExecutable() = createBinaries(
|
||||||
baseName = project.name,
|
baseName = project.name,
|
||||||
|
compilation = defaultTestCompilation,
|
||||||
jsBinaryType = JsBinaryType.TEST,
|
jsBinaryType = JsBinaryType.TEST,
|
||||||
create = ::TestExecutable
|
create = ::TestExecutable
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun <T : JsBinary> createBinaries(
|
private fun <T : JsBinary> createBinaries(
|
||||||
baseName: String,
|
baseName: String,
|
||||||
|
compilation: KotlinJsCompilation,
|
||||||
buildVariantKinds: Collection<BuildVariantKind> = listOf(PRODUCTION, DEVELOPMENT),
|
buildVariantKinds: Collection<BuildVariantKind> = listOf(PRODUCTION, DEVELOPMENT),
|
||||||
jsBinaryType: JsBinaryType,
|
jsBinaryType: JsBinaryType,
|
||||||
create: (name: String, buildVariantKind: BuildVariantKind, compilation: KotlinJsCompilation) -> T
|
create: (name: String, buildVariantKind: BuildVariantKind, compilation: KotlinJsCompilation) -> T
|
||||||
@@ -64,12 +69,6 @@ constructor(
|
|||||||
"Cannot create binary $name: binary with such a name already exists"
|
"Cannot create binary $name: binary with such a name already exists"
|
||||||
}
|
}
|
||||||
|
|
||||||
val compilation = if (jsBinaryType == JsBinaryType.TEST) {
|
|
||||||
defaultTestCompilation
|
|
||||||
} else {
|
|
||||||
defaultCompilation
|
|
||||||
}
|
|
||||||
|
|
||||||
val binary = create(name, buildVariantKind, compilation)
|
val binary = create(name, buildVariantKind, compilation)
|
||||||
add(binary)
|
add(binary)
|
||||||
nameToBinary[binary.name] = binary
|
nameToBinary[binary.name] = binary
|
||||||
|
|||||||
Reference in New Issue
Block a user