[Gradle, JS] Add binaries for javascript
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
|
||||
|
||||
sealed class JsBinary(
|
||||
internal val name: String,
|
||||
private val buildKind: BuildVariantKind
|
||||
)
|
||||
|
||||
class Executable(
|
||||
name: String,
|
||||
buildKind: BuildVariantKind,
|
||||
compilation: KotlinJsIrCompilation
|
||||
) : JsBinary(
|
||||
name,
|
||||
buildKind
|
||||
)
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.gradle.api.*
|
||||
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 javax.inject.Inject
|
||||
|
||||
|
||||
open class KotlinJsBinaryContainer
|
||||
@Inject
|
||||
constructor(
|
||||
val target: KotlinJsIrTarget,
|
||||
backingContainer: DomainObjectSet<JsBinary>
|
||||
) : DomainObjectSet<JsBinary> by backingContainer
|
||||
{
|
||||
val project: Project
|
||||
get() = target.project
|
||||
|
||||
private val defaultCompilation: KotlinJsIrCompilation
|
||||
get() = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
||||
|
||||
private val nameToBinary = mutableMapOf<String, JsBinary>()
|
||||
|
||||
fun executable(
|
||||
buildTypes: Collection<BuildVariantKind> = listOf(BuildVariantKind.PRODUCTION, BuildVariantKind.DEVELOPMENT),
|
||||
configure: Executable.() -> Unit = {}
|
||||
) = createBinaries(project.name, buildTypes, ::Executable, configure)
|
||||
|
||||
private fun <T : JsBinary> createBinaries(
|
||||
baseName: String,
|
||||
buildKinds: Collection<BuildVariantKind>,
|
||||
create: (name: String, buildType: BuildVariantKind, compilation: KotlinJsIrCompilation) -> T,
|
||||
configure: T.() -> Unit
|
||||
) {
|
||||
buildKinds.forEach { buildKind ->
|
||||
val name = generateBinaryName(baseName, buildKind)
|
||||
|
||||
require(name !in nameToBinary) {
|
||||
"Cannot create binary $name: binary with such a name already exists"
|
||||
}
|
||||
|
||||
val binary = create(baseName, buildKind, defaultCompilation)
|
||||
add(binary)
|
||||
nameToBinary[binary.name] = binary
|
||||
// Allow accessing binaries as properties of the container in Groovy DSL.
|
||||
if (this is ExtensionAware) {
|
||||
extensions.add(binary.name, binary)
|
||||
}
|
||||
binary.configure()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
internal fun generateBinaryName(name: String, buildKind: BuildVariantKind) =
|
||||
lowerCamelCaseName(name, buildKind.name)
|
||||
}
|
||||
}
|
||||
+14
-1
@@ -8,11 +8,16 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.util.WrapUtil
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinNativeBinaryContainer
|
||||
import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator.Companion.runTaskNameSuffix
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinBinaryContainer
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBinary
|
||||
import org.jetbrains.kotlin.gradle.plugin.removeJsCompilerSuffix
|
||||
import org.jetbrains.kotlin.gradle.targets.js.JsAggregatingExecutionSource
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsProducingType
|
||||
@@ -29,7 +34,7 @@ constructor(
|
||||
platformType: KotlinPlatformType,
|
||||
internal val mixedMode: Boolean
|
||||
) :
|
||||
KotlinOnlyTarget<KotlinJsIrCompilation>(project, platformType),
|
||||
KotlinBinaryContainer<KotlinJsIrCompilation, KotlinJsBinaryContainer>(project, platformType),
|
||||
KotlinTargetWithTests<JsAggregatingExecutionSource, KotlinJsReportAggregatingTestRun>,
|
||||
KotlinJsTargetDsl,
|
||||
KotlinJsSubTargetContainerDsl {
|
||||
@@ -41,6 +46,14 @@ constructor(
|
||||
|
||||
var producingType: KotlinJsProducingType? = null
|
||||
|
||||
override val binaries: KotlinJsBinaryContainer =
|
||||
// Use newInstance to allow accessing binaries by their names in Groovy using the extension mechanism.
|
||||
project.objects.newInstance(
|
||||
KotlinJsBinaryContainer::class.java,
|
||||
this,
|
||||
WrapUtil.toDomainObjectSet(JsBinary::class.java)
|
||||
)
|
||||
|
||||
private val runTaskName get() = lowerCamelCaseName(disambiguationClassifier, runTaskNameSuffix)
|
||||
val runTask: Task
|
||||
get() = project.tasks.maybeCreate(runTaskName).also {
|
||||
|
||||
Reference in New Issue
Block a user