[Gradle, JS] Binaries dsl
This commit is contained in:
+20
-4
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinBinaryContainer
|
|||||||
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.dsl.BuildVariantKind.DEVELOPMENT
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind.DEVELOPMENT
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind.PRODUCTION
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind.PRODUCTION
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetContainerDsl
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -34,9 +35,20 @@ constructor(
|
|||||||
|
|
||||||
fun executable(
|
fun executable(
|
||||||
compilation: KotlinJsIrCompilation = defaultCompilation
|
compilation: KotlinJsIrCompilation = defaultCompilation
|
||||||
) = compilation.binaries.executable()
|
) {
|
||||||
|
(target as KotlinJsSubTargetContainerDsl).whenBrowserConfigured {
|
||||||
|
(this as KotlinJsIrSubTarget).produceExecutable()
|
||||||
|
}
|
||||||
|
|
||||||
internal fun executable() = createBinaries(
|
target.whenNodejsConfigured {
|
||||||
|
(this as KotlinJsIrSubTarget).produceExecutable()
|
||||||
|
}
|
||||||
|
|
||||||
|
compilation.binaries.executableInternal(compilation)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun executableInternal(compilation: KotlinJsIrCompilation) = createBinaries(
|
||||||
|
compilation = compilation,
|
||||||
jsBinaryType = JsBinaryType.EXECUTABLE,
|
jsBinaryType = JsBinaryType.EXECUTABLE,
|
||||||
create = ::Executable
|
create = ::Executable
|
||||||
)
|
)
|
||||||
@@ -48,12 +60,14 @@ constructor(
|
|||||||
.single()
|
.single()
|
||||||
|
|
||||||
private fun <T : JsBinary> createBinaries(
|
private fun <T : JsBinary> createBinaries(
|
||||||
|
compilation: KotlinJsIrCompilation,
|
||||||
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: (target: KotlinTarget, name: String, buildVariantKind: BuildVariantKind) -> T
|
||||||
) {
|
) {
|
||||||
buildVariantKinds.forEach { buildVariantKind ->
|
buildVariantKinds.forEach { buildVariantKind ->
|
||||||
val name = generateBinaryName(
|
val name = generateBinaryName(
|
||||||
|
compilation,
|
||||||
buildVariantKind,
|
buildVariantKind,
|
||||||
jsBinaryType
|
jsBinaryType
|
||||||
)
|
)
|
||||||
@@ -73,12 +87,14 @@ constructor(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
internal fun generateBinaryName(
|
internal fun generateBinaryName(
|
||||||
|
compilation: KotlinJsIrCompilation,
|
||||||
buildVariantKind: BuildVariantKind,
|
buildVariantKind: BuildVariantKind,
|
||||||
jsBinaryType: JsBinaryType
|
jsBinaryType: JsBinaryType
|
||||||
) =
|
) =
|
||||||
lowerCamelCaseName(
|
lowerCamelCaseName(
|
||||||
buildVariantKind.name,
|
compilation.name.let { if (it == KotlinCompilation.MAIN_COMPILATION_NAME) null else it },
|
||||||
jsBinaryType.name
|
buildVariantKind.name.toLowerCase(),
|
||||||
|
jsBinaryType.name.toLowerCase()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-12
@@ -10,7 +10,6 @@ import org.gradle.util.WrapUtil
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
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.plugin.mpp.KotlinJsCompilation
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetContainerDsl
|
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
|
|
||||||
class KotlinJsIrCompilation(
|
class KotlinJsIrCompilation(
|
||||||
@@ -22,17 +21,7 @@ class KotlinJsIrCompilation(
|
|||||||
target.project.objects.newInstance(
|
target.project.objects.newInstance(
|
||||||
KotlinJsBinaryContainer::class.java,
|
KotlinJsBinaryContainer::class.java,
|
||||||
target,
|
target,
|
||||||
WrapUtil.toDomainObjectSet(JsBinary::class.java).apply {
|
WrapUtil.toDomainObjectSet(JsBinary::class.java)
|
||||||
matching { it is Executable }.all {
|
|
||||||
(target as KotlinJsSubTargetContainerDsl).whenBrowserConfigured {
|
|
||||||
(this as KotlinJsIrSubTarget).produceExecutable()
|
|
||||||
}
|
|
||||||
|
|
||||||
(target as KotlinJsSubTargetContainerDsl).whenNodejsConfigured {
|
|
||||||
(this as KotlinJsIrSubTarget).produceExecutable()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internal val allSources: MutableSet<SourceDirectorySet> = mutableSetOf()
|
internal val allSources: MutableSet<SourceDirectorySet> = mutableSetOf()
|
||||||
|
|||||||
+1
-1
@@ -76,7 +76,7 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
|
|
||||||
protected open fun configureTestRunDefaults(testRun: KotlinJsPlatformTestRun) {
|
protected open fun configureTestRunDefaults(testRun: KotlinJsPlatformTestRun) {
|
||||||
target.compilations.matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME }.all { compilation ->
|
target.compilations.matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME }.all { compilation ->
|
||||||
compilation.binaries.executable()
|
compilation.binaries.executableInternal(compilation)
|
||||||
configureTestsRun(testRun, compilation)
|
configureTestsRun(testRun, compilation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user