Gradle, native: Add separate classes for targets with different tests
This commit is contained in:
+6
-13
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.generators.gradle.dsl
|
||||
|
||||
import org.jetbrains.kotlin.generators.gradle.dsl.NativeFQNames.Presets
|
||||
import org.jetbrains.kotlin.generators.gradle.dsl.NativeFQNames.Targets
|
||||
import org.jetbrains.kotlin.generators.gradle.dsl.NativeFQNames.TestRuns
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.presetName
|
||||
@@ -23,11 +22,10 @@ internal fun KotlinPresetEntry.typeNames(): Set<TypeName> = setOf(presetType, ta
|
||||
internal const val MPP_PACKAGE = "org.jetbrains.kotlin.gradle.plugin.mpp"
|
||||
|
||||
internal object NativeFQNames {
|
||||
const val nativePackage = "org.jetbrains.kotlin.gradle.targets.native"
|
||||
|
||||
object Targets {
|
||||
const val base = "$MPP_PACKAGE.KotlinNativeTarget"
|
||||
const val withTests = "$MPP_PACKAGE.KotlinNativeTargetWithTests"
|
||||
const val withHostTests = "$MPP_PACKAGE.KotlinNativeTargetWithHostTests"
|
||||
const val withSimulatorTests = "$MPP_PACKAGE.KotlinNativeTargetWithSimulatorTests"
|
||||
}
|
||||
|
||||
object Presets {
|
||||
@@ -35,11 +33,6 @@ internal object NativeFQNames {
|
||||
const val withHostTests = "$MPP_PACKAGE.KotlinNativeTargetWithHostTestsPreset"
|
||||
const val withSimulatorTests = "$MPP_PACKAGE.KotlinNativeTargetWithSimulatorTestsPreset"
|
||||
}
|
||||
|
||||
object TestRuns {
|
||||
const val host = "$nativePackage.KotlinNativeHostTestRun"
|
||||
const val simulator = "$nativePackage.KotlinNativeSimulatorTestRun"
|
||||
}
|
||||
}
|
||||
|
||||
internal val jvmPresetEntry = KotlinPresetEntry(
|
||||
@@ -71,14 +64,14 @@ internal val nativePresetEntries = HostManager().targets
|
||||
|
||||
val (presetType, targetType) = when (target) {
|
||||
in nativeTargetsWithHostTests ->
|
||||
typeName(Presets.withHostTests) to typeName(Targets.withTests, TestRuns.host)
|
||||
Presets.withHostTests to Targets.withHostTests
|
||||
in nativeTargetsWithSimulatorTests ->
|
||||
typeName(Presets.withSimulatorTests) to typeName(Targets.withTests, TestRuns.simulator)
|
||||
Presets.withSimulatorTests to Targets.withSimulatorTests
|
||||
else ->
|
||||
typeName(Presets.simple) to typeName(Targets.base)
|
||||
Presets.simple to Targets.base
|
||||
}
|
||||
|
||||
KotlinPresetEntry(target.presetName, presetType, targetType)
|
||||
KotlinPresetEntry(target.presetName, typeName(presetType), typeName(targetType))
|
||||
}
|
||||
|
||||
internal val allPresetEntries = listOf(
|
||||
|
||||
+14
-15
@@ -9,13 +9,12 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTestsPreset
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTests
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTestsPreset
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithTests
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.native.KotlinNativeHostTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.native.KotlinNativeSimulatorTestRun
|
||||
|
||||
// DO NOT EDIT MANUALLY! Generated by org.jetbrains.kotlin.generators.gradle.dsl.MppPresetFunctionsCodegenKt
|
||||
|
||||
@@ -158,8 +157,8 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
||||
|
||||
fun iosX64(
|
||||
name: String = "iosX64",
|
||||
configure: KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun>.() -> Unit = { }
|
||||
): KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun> =
|
||||
configure: KotlinNativeTargetWithSimulatorTests.() -> Unit = { }
|
||||
): KotlinNativeTargetWithSimulatorTests =
|
||||
configureOrCreate(
|
||||
name,
|
||||
presets.getByName("iosX64") as KotlinNativeTargetWithSimulatorTestsPreset,
|
||||
@@ -203,8 +202,8 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
||||
|
||||
fun watchosX86(
|
||||
name: String = "watchosX86",
|
||||
configure: KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun>.() -> Unit = { }
|
||||
): KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun> =
|
||||
configure: KotlinNativeTargetWithSimulatorTests.() -> Unit = { }
|
||||
): KotlinNativeTargetWithSimulatorTests =
|
||||
configureOrCreate(
|
||||
name,
|
||||
presets.getByName("watchosX86") as KotlinNativeTargetWithSimulatorTestsPreset,
|
||||
@@ -233,8 +232,8 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
||||
|
||||
fun tvosX64(
|
||||
name: String = "tvosX64",
|
||||
configure: KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun>.() -> Unit = { }
|
||||
): KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun> =
|
||||
configure: KotlinNativeTargetWithSimulatorTests.() -> Unit = { }
|
||||
): KotlinNativeTargetWithSimulatorTests =
|
||||
configureOrCreate(
|
||||
name,
|
||||
presets.getByName("tvosX64") as KotlinNativeTargetWithSimulatorTestsPreset,
|
||||
@@ -248,8 +247,8 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
||||
|
||||
fun linuxX64(
|
||||
name: String = "linuxX64",
|
||||
configure: KotlinNativeTargetWithTests<KotlinNativeHostTestRun>.() -> Unit = { }
|
||||
): KotlinNativeTargetWithTests<KotlinNativeHostTestRun> =
|
||||
configure: KotlinNativeTargetWithHostTests.() -> Unit = { }
|
||||
): KotlinNativeTargetWithHostTests =
|
||||
configureOrCreate(
|
||||
name,
|
||||
presets.getByName("linuxX64") as KotlinNativeTargetWithHostTestsPreset,
|
||||
@@ -323,8 +322,8 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
||||
|
||||
fun mingwX64(
|
||||
name: String = "mingwX64",
|
||||
configure: KotlinNativeTargetWithTests<KotlinNativeHostTestRun>.() -> Unit = { }
|
||||
): KotlinNativeTargetWithTests<KotlinNativeHostTestRun> =
|
||||
configure: KotlinNativeTargetWithHostTests.() -> Unit = { }
|
||||
): KotlinNativeTargetWithHostTests =
|
||||
configureOrCreate(
|
||||
name,
|
||||
presets.getByName("mingwX64") as KotlinNativeTargetWithHostTestsPreset,
|
||||
@@ -353,8 +352,8 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
||||
|
||||
fun macosX64(
|
||||
name: String = "macosX64",
|
||||
configure: KotlinNativeTargetWithTests<KotlinNativeHostTestRun>.() -> Unit = { }
|
||||
): KotlinNativeTargetWithTests<KotlinNativeHostTestRun> =
|
||||
configure: KotlinNativeTargetWithHostTests.() -> Unit = { }
|
||||
): KotlinNativeTargetWithHostTests =
|
||||
configureOrCreate(
|
||||
name,
|
||||
presets.getByName("macosX64") as KotlinNativeTargetWithHostTestsPreset,
|
||||
|
||||
+10
-4
@@ -16,8 +16,9 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinNativeBinaryContainer
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
|
||||
import org.jetbrains.kotlin.gradle.targets.native.KotlinNativeBinaryTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.native.KotlinNativeHostTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.native.KotlinNativeSimulatorTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.native.NativeBinaryTestRunSource
|
||||
import org.jetbrains.kotlin.gradle.utils.isGradleVersionAtLeast
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -65,12 +66,17 @@ open class KotlinNativeTarget @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add separate classes for corresponding targets?
|
||||
open class KotlinNativeTargetWithTests<T : KotlinNativeBinaryTestRun> @Inject constructor(
|
||||
abstract class KotlinNativeTargetWithTests<T : KotlinNativeBinaryTestRun>(
|
||||
project: Project,
|
||||
konanTarget: KonanTarget
|
||||
) : KotlinNativeTarget(project, konanTarget), KotlinTargetWithTests<NativeBinaryTestRunSource, T> {
|
||||
|
||||
override lateinit var testRuns: NamedDomainObjectContainer<T>
|
||||
internal set
|
||||
}
|
||||
}
|
||||
|
||||
open class KotlinNativeTargetWithHostTests @Inject constructor(project: Project, konanTarget: KonanTarget) :
|
||||
KotlinNativeTargetWithTests<KotlinNativeHostTestRun>(project, konanTarget)
|
||||
|
||||
open class KotlinNativeTargetWithSimulatorTests @Inject constructor(project: Project, konanTarget: KonanTarget) :
|
||||
KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun>(project, konanTarget)
|
||||
+26
-13
@@ -394,16 +394,19 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget>(
|
||||
}
|
||||
}
|
||||
|
||||
abstract class KotlinNativeTargetWithTestsConfigurator<TaskType : KotlinNativeTest, TestRunType : KotlinNativeBinaryTestRun>(
|
||||
abstract class KotlinNativeTargetWithTestsConfigurator<
|
||||
TargetType : KotlinNativeTargetWithTests<TestRunType>,
|
||||
TestRunType : KotlinNativeBinaryTestRun,
|
||||
TaskType : KotlinNativeTest>(
|
||||
kotlinPluginVersion: String
|
||||
) : KotlinNativeTargetConfigurator<KotlinNativeTargetWithTests<TestRunType>>(kotlinPluginVersion),
|
||||
KotlinTargetWithTestsConfigurator<TestRunType, KotlinNativeTargetWithTests<TestRunType>> {
|
||||
) : KotlinNativeTargetConfigurator<TargetType>(kotlinPluginVersion),
|
||||
KotlinTargetWithTestsConfigurator<TestRunType, TargetType> {
|
||||
|
||||
abstract val testTaskClass: Class<TaskType>
|
||||
|
||||
abstract fun isTestTaskEnabled(target: KotlinNativeTargetWithTests<*>): Boolean
|
||||
abstract fun isTestTaskEnabled(target: TargetType): Boolean
|
||||
|
||||
protected open fun configureTestTask(target: KotlinNativeTargetWithTests<*>, testTask: TaskType) {
|
||||
protected open fun configureTestTask(target: TargetType, testTask: TaskType) {
|
||||
testTask.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||
testTask.description = "Executes Kotlin/Native unit tests for target ${target.name}."
|
||||
testTask.targetName = target.name
|
||||
@@ -415,7 +418,7 @@ abstract class KotlinNativeTargetWithTestsConfigurator<TaskType : KotlinNativeTe
|
||||
testTask.configureConventions()
|
||||
}
|
||||
|
||||
protected open fun configureTestRun(target: KotlinNativeTargetWithTests<*>, testRun: AbstractKotlinNativeTestRun<TaskType>) {
|
||||
protected open fun configureTestRun(target: TargetType, testRun: AbstractKotlinNativeTestRun<TaskType>) {
|
||||
with(testRun) {
|
||||
val project = target.project
|
||||
|
||||
@@ -433,7 +436,12 @@ abstract class KotlinNativeTargetWithTestsConfigurator<TaskType : KotlinNativeTe
|
||||
}
|
||||
|
||||
class KotlinNativeTargetWithHostTestsConfigurator(kotlinPluginVersion: String) :
|
||||
KotlinNativeTargetWithTestsConfigurator<KotlinNativeHostTest, KotlinNativeHostTestRun>(kotlinPluginVersion) {
|
||||
KotlinNativeTargetWithTestsConfigurator<
|
||||
KotlinNativeTargetWithHostTests,
|
||||
KotlinNativeHostTestRun,
|
||||
KotlinNativeHostTest>(
|
||||
kotlinPluginVersion
|
||||
) {
|
||||
|
||||
override val testTaskClass: Class<KotlinNativeHostTest>
|
||||
get() = KotlinNativeHostTest::class.java
|
||||
@@ -441,18 +449,23 @@ class KotlinNativeTargetWithHostTestsConfigurator(kotlinPluginVersion: String) :
|
||||
override val testRunClass: Class<KotlinNativeHostTestRun>
|
||||
get() = KotlinNativeHostTestRun::class.java
|
||||
|
||||
override fun isTestTaskEnabled(target: KotlinNativeTargetWithTests<*>): Boolean =
|
||||
override fun isTestTaskEnabled(target: KotlinNativeTargetWithHostTests): Boolean =
|
||||
target.konanTarget.isCurrentHost
|
||||
|
||||
override fun createTestRun(
|
||||
name: String,
|
||||
target: KotlinNativeTargetWithTests<KotlinNativeHostTestRun>
|
||||
target: KotlinNativeTargetWithHostTests
|
||||
): KotlinNativeHostTestRun =
|
||||
DefaultHostTestRun(name, target).apply { configureTestRun(target, this) }
|
||||
}
|
||||
|
||||
class KotlinNativeTargetWithSimulatorTestsConfigurator(kotlinPluginVersion: String) :
|
||||
KotlinNativeTargetWithTestsConfigurator<KotlinNativeSimulatorTest, KotlinNativeSimulatorTestRun>(kotlinPluginVersion) {
|
||||
KotlinNativeTargetWithTestsConfigurator<
|
||||
KotlinNativeTargetWithSimulatorTests,
|
||||
KotlinNativeSimulatorTestRun,
|
||||
KotlinNativeSimulatorTest>(
|
||||
kotlinPluginVersion
|
||||
) {
|
||||
|
||||
override val testTaskClass: Class<KotlinNativeSimulatorTest>
|
||||
get() = KotlinNativeSimulatorTest::class.java
|
||||
@@ -460,10 +473,10 @@ class KotlinNativeTargetWithSimulatorTestsConfigurator(kotlinPluginVersion: Stri
|
||||
override val testRunClass: Class<KotlinNativeSimulatorTestRun>
|
||||
get() = KotlinNativeSimulatorTestRun::class.java
|
||||
|
||||
override fun isTestTaskEnabled(target: KotlinNativeTargetWithTests<*>): Boolean =
|
||||
override fun isTestTaskEnabled(target: KotlinNativeTargetWithSimulatorTests): Boolean =
|
||||
HostManager.hostIsMac
|
||||
|
||||
override fun configureTestTask(target: KotlinNativeTargetWithTests<*>, testTask: KotlinNativeSimulatorTest) {
|
||||
override fun configureTestTask(target: KotlinNativeTargetWithSimulatorTests, testTask: KotlinNativeSimulatorTest) {
|
||||
super.configureTestTask(target, testTask)
|
||||
|
||||
testTask.deviceId = when (target.konanTarget) {
|
||||
@@ -476,7 +489,7 @@ class KotlinNativeTargetWithSimulatorTestsConfigurator(kotlinPluginVersion: Stri
|
||||
|
||||
override fun createTestRun(
|
||||
name: String,
|
||||
target: KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun>
|
||||
target: KotlinNativeTargetWithSimulatorTests
|
||||
): KotlinNativeSimulatorTestRun =
|
||||
DefaultSimulatorTestRun(name, target).apply { configureTestRun(target, this) }
|
||||
}
|
||||
|
||||
+8
-12
@@ -184,27 +184,23 @@ open class KotlinNativeTargetPreset(name: String, project: Project, konanTarget:
|
||||
}
|
||||
|
||||
open class KotlinNativeTargetWithHostTestsPreset(name: String, project: Project, konanTarget: KonanTarget, kotlinPluginVersion: String) :
|
||||
AbstractKotlinNativeTargetPreset<KotlinNativeTargetWithTests<KotlinNativeHostTestRun>>(name, project, konanTarget, kotlinPluginVersion) {
|
||||
AbstractKotlinNativeTargetPreset<KotlinNativeTargetWithHostTests>(name, project, konanTarget, kotlinPluginVersion) {
|
||||
|
||||
override fun createTargetConfigurator(): KotlinTargetConfigurator<KotlinNativeTargetWithTests<KotlinNativeHostTestRun>> =
|
||||
override fun createTargetConfigurator(): KotlinNativeTargetWithHostTestsConfigurator =
|
||||
KotlinNativeTargetWithHostTestsConfigurator(kotlinPluginVersion)
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun instantiateTarget(name: String): KotlinNativeTargetWithTests<KotlinNativeHostTestRun> =
|
||||
project.objects.newInstance(KotlinNativeTargetWithTests::class.java, project, konanTarget)
|
||||
as KotlinNativeTargetWithTests<KotlinNativeHostTestRun>
|
||||
override fun instantiateTarget(name: String): KotlinNativeTargetWithHostTests =
|
||||
project.objects.newInstance(KotlinNativeTargetWithHostTests::class.java, project, konanTarget)
|
||||
}
|
||||
|
||||
open class KotlinNativeTargetWithSimulatorTestsPreset(name: String, project: Project, konanTarget: KonanTarget, kotlinPluginVersion: String) :
|
||||
AbstractKotlinNativeTargetPreset<KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun>>(name, project, konanTarget, kotlinPluginVersion) {
|
||||
AbstractKotlinNativeTargetPreset<KotlinNativeTargetWithSimulatorTests>(name, project, konanTarget, kotlinPluginVersion) {
|
||||
|
||||
override fun createTargetConfigurator(): KotlinTargetConfigurator<KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun>> =
|
||||
override fun createTargetConfigurator(): KotlinNativeTargetWithSimulatorTestsConfigurator =
|
||||
KotlinNativeTargetWithSimulatorTestsConfigurator(kotlinPluginVersion)
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun instantiateTarget(name: String): KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun> =
|
||||
project.objects.newInstance(KotlinNativeTargetWithTests::class.java, project, konanTarget)
|
||||
as KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun>
|
||||
override fun instantiateTarget(name: String): KotlinNativeTargetWithSimulatorTests =
|
||||
project.objects.newInstance(KotlinNativeTargetWithSimulatorTests::class.java, project, konanTarget)
|
||||
}
|
||||
|
||||
internal val KonanTarget.isCurrentHost: Boolean
|
||||
|
||||
Reference in New Issue
Block a user