[Gradle, JS] Extract common interface for JsBinary
This commit is contained in:
+11
-8
@@ -38,6 +38,7 @@ 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.KotlinJsBinaryType
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryType
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.ir.JsBinary
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
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.jvm.KotlinJvmTarget
|
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||||
@@ -352,16 +353,18 @@ internal class KotlinJsIrSourceSetProcessor(
|
|||||||
|
|
||||||
val compilation = kotlinCompilation as KotlinJsIrCompilation
|
val compilation = kotlinCompilation as KotlinJsIrCompilation
|
||||||
|
|
||||||
compilation.binaries.all { binary ->
|
compilation.binaries
|
||||||
registerKotlinCompileTask(
|
.withType(JsBinary::class.java)
|
||||||
binary.linkTaskName
|
.all { binary ->
|
||||||
) { project, name, action ->
|
registerKotlinCompileTask(
|
||||||
registerJsLink(project, name, binary.type) { compileTask ->
|
binary.linkTaskName
|
||||||
action(compileTask)
|
) { project, name, action ->
|
||||||
compileTask.dependsOn(kotlinTask)
|
registerJsLink(project, name, binary.type) { compileTask ->
|
||||||
|
action(compileTask)
|
||||||
|
compileTask.dependsOn(kotlinTask)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 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) {
|
||||||
|
|||||||
+10
-4
@@ -13,11 +13,17 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryType
|
|||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsBinaryContainer.Companion.generateBinaryName
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsBinaryContainer.Companion.generateBinaryName
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
|
|
||||||
|
interface JsBinary2 {
|
||||||
|
val compilation: KotlinJsCompilation
|
||||||
|
val name: String
|
||||||
|
val type: KotlinJsBinaryType
|
||||||
|
}
|
||||||
|
|
||||||
sealed class JsBinary(
|
sealed class JsBinary(
|
||||||
internal val compilation: KotlinJsCompilation,
|
override val compilation: KotlinJsCompilation,
|
||||||
internal val name: String,
|
override val name: String,
|
||||||
internal val type: KotlinJsBinaryType
|
override val type: KotlinJsBinaryType
|
||||||
) {
|
) : JsBinary2 {
|
||||||
val linkTaskName: String = linkTaskName()
|
val linkTaskName: String = linkTaskName()
|
||||||
|
|
||||||
val linkTask: TaskProvider<KotlinJsIrLink>
|
val linkTask: TaskProvider<KotlinJsIrLink>
|
||||||
|
|||||||
+20
-5
@@ -24,8 +24,8 @@ open class KotlinJsBinaryContainer
|
|||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
val target: KotlinTargetWithBinaries<KotlinJsCompilation, KotlinJsBinaryContainer>,
|
val target: KotlinTargetWithBinaries<KotlinJsCompilation, KotlinJsBinaryContainer>,
|
||||||
backingContainer: DomainObjectSet<JsBinary>
|
backingContainer: DomainObjectSet<JsBinary2>
|
||||||
) : DomainObjectSet<JsBinary> by backingContainer {
|
) : DomainObjectSet<JsBinary2> by backingContainer {
|
||||||
val project: Project
|
val project: Project
|
||||||
get() = target.project
|
get() = target.project
|
||||||
|
|
||||||
@@ -45,6 +45,8 @@ constructor(
|
|||||||
target.whenNodejsConfigured {
|
target.whenNodejsConfigured {
|
||||||
(this as KotlinJsIrSubTarget).produceExecutable()
|
(this as KotlinJsIrSubTarget).produceExecutable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compilation.binaries.executableInternal(compilation)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target is KotlinJsTarget) {
|
if (target is KotlinJsTarget) {
|
||||||
@@ -58,9 +60,9 @@ constructor(
|
|||||||
target.whenNodejsConfigured {
|
target.whenNodejsConfigured {
|
||||||
(this as KotlinJsSubTarget).produceExecutable()
|
(this as KotlinJsSubTarget).produceExecutable()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
compilation.binaries.executableInternal(compilation)
|
compilation.binaries.executableLegacyInternal(compilation)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun executableInternal(compilation: KotlinJsCompilation) = createBinaries(
|
internal fun executableInternal(compilation: KotlinJsCompilation) = createBinaries(
|
||||||
@@ -69,13 +71,26 @@ constructor(
|
|||||||
create = ::Executable
|
create = ::Executable
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private fun executableLegacyInternal(compilation: KotlinJsCompilation) = createBinaries(
|
||||||
|
compilation = compilation,
|
||||||
|
jsBinaryType = JsBinaryType.EXECUTABLE,
|
||||||
|
create = { compilation, name, type ->
|
||||||
|
object : JsBinary2 {
|
||||||
|
override val compilation: KotlinJsCompilation = compilation
|
||||||
|
override val name: String = name
|
||||||
|
override val type: KotlinJsBinaryType = type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
internal fun getBinary(
|
internal fun getBinary(
|
||||||
type: KotlinJsBinaryType
|
type: KotlinJsBinaryType
|
||||||
): JsBinary =
|
): JsBinary =
|
||||||
matching { it.type == type }
|
matching { it.type == type }
|
||||||
|
.withType(JsBinary::class.java)
|
||||||
.single()
|
.single()
|
||||||
|
|
||||||
private fun <T : JsBinary> createBinaries(
|
private fun <T : JsBinary2> createBinaries(
|
||||||
compilation: KotlinJsCompilation,
|
compilation: KotlinJsCompilation,
|
||||||
types: Collection<KotlinJsBinaryType> = listOf(PRODUCTION, DEVELOPMENT),
|
types: Collection<KotlinJsBinaryType> = listOf(PRODUCTION, DEVELOPMENT),
|
||||||
jsBinaryType: JsBinaryType,
|
jsBinaryType: JsBinaryType,
|
||||||
|
|||||||
+6
-4
@@ -43,11 +43,13 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
|
|
||||||
target.compilations.all {
|
target.compilations.all {
|
||||||
val npmProject = it.npmProject
|
val npmProject = it.npmProject
|
||||||
it.binaries.all { binary ->
|
it.binaries
|
||||||
binary.linkTask.configure {
|
.withType(JsBinary::class.java)
|
||||||
it.kotlinOptions.outputFile = npmProject.dir.resolve(npmProject.main).canonicalPath
|
.all { binary ->
|
||||||
|
binary.linkTask.configure {
|
||||||
|
it.kotlinOptions.outputFile = npmProject.dir.resolve(npmProject.main).canonicalPath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-4
@@ -117,11 +117,13 @@ constructor(
|
|||||||
compilations.all {
|
compilations.all {
|
||||||
it.compileKotlinTask.configureCommonJsOptions()
|
it.compileKotlinTask.configureCommonJsOptions()
|
||||||
|
|
||||||
binaries.forEach {
|
binaries
|
||||||
it.linkTask.configure { linkTask ->
|
.filterIsInstance<JsBinary>()
|
||||||
linkTask.configureCommonJsOptions()
|
.forEach {
|
||||||
|
it.linkTask.configure { linkTask ->
|
||||||
|
linkTask.configureCommonJsOptions()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-4
@@ -73,11 +73,13 @@ open class KotlinJsIrTargetConfigurator(kotlinPluginVersion: String) :
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
it.binaries.forEach {
|
it.binaries
|
||||||
it.linkTask.configure { linkTask ->
|
.filterIsInstance<JsBinary>()
|
||||||
linkTask.kotlinOptions.configureOptions()
|
.forEach {
|
||||||
|
it.linkTask.configure { linkTask ->
|
||||||
|
linkTask.kotlinOptions.configureOptions()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user