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