[Gradle, JS] Simplify JsBinary
This commit is contained in:
+3
-9
@@ -5,18 +5,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
|
|
||||||
|
|
||||||
sealed class JsBinary(
|
sealed class JsBinary(
|
||||||
internal val name: String,
|
internal val name: String
|
||||||
private val buildKind: BuildVariantKind
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Executable(
|
class Executable(
|
||||||
name: String,
|
name: String
|
||||||
buildKind: BuildVariantKind,
|
|
||||||
compilation: KotlinJsIrCompilation
|
|
||||||
) : JsBinary(
|
) : JsBinary(
|
||||||
name,
|
name
|
||||||
buildKind
|
|
||||||
)
|
)
|
||||||
+17
-32
@@ -5,12 +5,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||||
|
|
||||||
import org.gradle.api.*
|
import org.gradle.api.DomainObjectSet
|
||||||
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.plugins.ExtensionAware
|
import org.gradle.api.plugins.ExtensionAware
|
||||||
import org.gradle.util.WrapUtil
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
|
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -20,47 +17,35 @@ open class KotlinJsBinaryContainer
|
|||||||
constructor(
|
constructor(
|
||||||
val target: KotlinJsIrTarget,
|
val target: KotlinJsIrTarget,
|
||||||
backingContainer: DomainObjectSet<JsBinary>
|
backingContainer: DomainObjectSet<JsBinary>
|
||||||
) : DomainObjectSet<JsBinary> by backingContainer
|
) : DomainObjectSet<JsBinary> by backingContainer {
|
||||||
{
|
|
||||||
val project: Project
|
val project: Project
|
||||||
get() = target.project
|
get() = target.project
|
||||||
|
|
||||||
private val defaultCompilation: KotlinJsIrCompilation
|
|
||||||
get() = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
|
||||||
|
|
||||||
private val nameToBinary = mutableMapOf<String, JsBinary>()
|
private val nameToBinary = mutableMapOf<String, JsBinary>()
|
||||||
|
|
||||||
fun executable(
|
fun executable() = createBinaries(project.name, ::Executable)
|
||||||
buildTypes: Collection<BuildVariantKind> = listOf(BuildVariantKind.PRODUCTION, BuildVariantKind.DEVELOPMENT),
|
|
||||||
configure: Executable.() -> Unit = {}
|
|
||||||
) = createBinaries(project.name, buildTypes, ::Executable, configure)
|
|
||||||
|
|
||||||
private fun <T : JsBinary> createBinaries(
|
private fun <T : JsBinary> createBinaries(
|
||||||
baseName: String,
|
baseName: String,
|
||||||
buildKinds: Collection<BuildVariantKind>,
|
create: (name: String) -> T
|
||||||
create: (name: String, buildType: BuildVariantKind, compilation: KotlinJsIrCompilation) -> T,
|
|
||||||
configure: T.() -> Unit
|
|
||||||
) {
|
) {
|
||||||
buildKinds.forEach { buildKind ->
|
val name = generateBinaryName(baseName)
|
||||||
val name = generateBinaryName(baseName, buildKind)
|
|
||||||
|
|
||||||
require(name !in nameToBinary) {
|
require(name !in nameToBinary) {
|
||||||
"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(baseName, buildKind, defaultCompilation)
|
val binary = create(baseName)
|
||||||
add(binary)
|
add(binary)
|
||||||
nameToBinary[binary.name] = binary
|
nameToBinary[binary.name] = 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)
|
||||||
}
|
|
||||||
binary.configure()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
internal fun generateBinaryName(name: String, buildKind: BuildVariantKind) =
|
internal fun generateBinaryName(name: String) =
|
||||||
lowerCamelCaseName(name, buildKind.name)
|
lowerCamelCaseName(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user