Skip to content

Commit

Permalink
[Gradle, JS] Inject ir's classes into legacy for mixed mode #2
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgonmic committed Jan 20, 2020
1 parent 72fbb1b commit afec2c9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.targets.js.npm.PackageJson
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile

open class KotlinJsCompilation(
target: KotlinTarget,
name: String
) : AbstractKotlinCompilationToRunnableFiles<KotlinJsOptions>(target, name), KotlinCompilationWithResources<KotlinJsOptions> {
override val processResourcesTaskName: String
get() = disambiguateName("processResources")
open class KotlinJsCompilation(
target: KotlinTarget,
name: String
) : AbstractKotlinCompilationToRunnableFiles<KotlinJsOptions>(target, name), KotlinCompilationWithResources<KotlinJsOptions> {
override val processResourcesTaskName: String
get() = disambiguateName("processResources")

override val compileKotlinTask: Kotlin2JsCompile
get() = super.compileKotlinTask as Kotlin2JsCompile
override val compileKotlinTask: Kotlin2JsCompile
get() = super.compileKotlinTask as Kotlin2JsCompile

internal val packageJsonHandlers = mutableListOf<PackageJson.() -> Unit>()
internal val packageJsonHandlers = mutableListOf<PackageJson.() -> Unit>()

@Suppress("unused")
fun packageJson(handler: PackageJson.() -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@

package org.jetbrains.kotlin.gradle.targets.js

import org.gradle.api.tasks.TaskProvider
import org.jetbrains.kotlin.gradle.plugin.Kotlin2JsSourceSetProcessor
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor
import org.jetbrains.kotlin.gradle.plugin.KotlinOnlyTargetConfigurator
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTestsConfigurator
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetConfigurator
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
import org.jetbrains.kotlin.gradle.testing.internal.KotlinTestReport
import org.jetbrains.kotlin.gradle.testing.internal.kotlinTestRegistry
import org.jetbrains.kotlin.gradle.testing.testTaskName

open class KotlinJsTargetConfigurator(kotlinPluginVersion: String) :
open class KotlinJsTargetConfigurator(kotlinPluginVersion: String, val irConfigurator: KotlinJsIrTargetConfigurator?) :
KotlinOnlyTargetConfigurator<KotlinJsCompilation, KotlinJsTarget>(true, true, kotlinPluginVersion),
KotlinTargetWithTestsConfigurator<KotlinJsReportAggregatingTestRun, KotlinJsTarget> {

Expand Down Expand Up @@ -60,5 +59,7 @@ open class KotlinJsTargetConfigurator(kotlinPluginVersion: String) :
sourceMapEmbedSources = null
}
}

irConfigurator?.configureCompilations(target.irTarget!!)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTargetConfigurator
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrSingleTargetPreset
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetConfigurator
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetPreset

open class KotlinJsTargetPreset(
project: Project,
kotlinPluginVersion: String,
irPreset: KotlinJsIrTargetPreset?
val irPreset: KotlinJsIrTargetPreset?
) : KotlinOnlyTargetPreset<KotlinJsTarget, KotlinJsCompilation>(
project,
kotlinPluginVersion
Expand Down Expand Up @@ -47,20 +48,29 @@ open class KotlinJsTargetPreset(

val compilationFactory = createCompilationFactory(this)
compilations = project.container(compilationFactory.itemClass, compilationFactory)

if (irTarget != null) {
val irCompilationFactory = irPreset?.createCompilationFactory(irTarget)!!
irTarget.targetName = "${name}Ir"
irTarget.compilations = project.container(irCompilationFactory.itemClass, irCompilationFactory)
}
}

createKotlinTargetConfigurator().configureTarget(result)

return result
}

override fun createKotlinTargetConfigurator() = KotlinJsTargetConfigurator(kotlinPluginVersion)
override fun createKotlinTargetConfigurator() = KotlinJsTargetConfigurator(
kotlinPluginVersion,
irPreset?.let { KotlinJsIrTargetConfigurator(kotlinPluginVersion) }
)

override fun getName(): String = PRESET_NAME

override fun createCompilationFactory(forTarget: KotlinOnlyTarget<KotlinJsCompilation>): KotlinJsCompilationFactory {
forTarget as KotlinJsTarget
return KotlinJsCompilationFactory(project, forTarget, forTarget.irTarget)
return KotlinJsCompilationFactory(project, forTarget, irPreset?.let { forTarget.irTarget })
}

companion object {
Expand All @@ -81,5 +91,8 @@ class KotlinJsSingleTargetPreset(
// In a Kotlin/JS single-platform project, we don't need any disambiguation suffixes or prefixes in the names:
override fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget<KotlinJsCompilation>): String? = null

override fun createKotlinTargetConfigurator() = KotlinJsTargetConfigurator(kotlinPluginVersion)
override fun createKotlinTargetConfigurator() = KotlinJsTargetConfigurator(
kotlinPluginVersion,
irPreset?.let { KotlinJsIrTargetConfigurator(kotlinPluginVersion) }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.plugin.KotlinOnlyTargetConfigurator
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCompilationFactory
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilationFactory
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTargetPreset

Expand All @@ -32,7 +31,8 @@ open class KotlinJsIrTargetPreset(

override fun getName(): String = PRESET_NAME

override fun createCompilationFactory(
//TODO[Ilya Goncharov] remove public morozov
public override fun createCompilationFactory(
forTarget: KotlinOnlyTarget<KotlinJsIrCompilation>
): KotlinCompilationFactory<KotlinJsIrCompilation> =
KotlinJsIrCompilationFactory(project, forTarget)
Expand Down

0 comments on commit afec2c9

Please sign in to comment.