[Gradle] Deprecate native target shortcuts ...

... in favor of default hierarchy template

^KT-58676 Verification Pending
This commit is contained in:
Sebastian Sellmair
2023-06-21 12:14:52 +02:00
committed by Space Team
parent 845c8bd1c3
commit 0b57dac738
4 changed files with 88 additions and 25 deletions
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.plugin.hierarchy.default
import javax.inject.Inject
@Suppress("DEPRECATION")
@KotlinGradlePluginDsl
abstract class KotlinMultiplatformExtension
@InternalKotlinGradlePluginApi constructor(project: Project) :
@@ -3,6 +3,8 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
package org.jetbrains.kotlin.gradle.dsl
import org.gradle.api.Action
@@ -14,7 +16,12 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet.Companion.COMMON_TEST_
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetContainer
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
private const val SHORTCUTS_DEPRECATION_MESSAGE = "Use applyDefaultHierarchyTemplate() instead. " +
"Deprecated since 1.9.20, scheduled for removal in 2.0"
@KotlinGradlePluginDsl
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPresetFunctions, KotlinSourceSetContainer {
private data class DefaultSourceSets(val main: KotlinSourceSet, val test: KotlinSourceSet)
@@ -35,7 +42,7 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
private fun createIntermediateSourceSet(
name: String,
children: List<KotlinSourceSet>,
parent: KotlinSourceSet? = null
parent: KotlinSourceSet? = null,
): KotlinSourceSet =
sourceSets.maybeCreate(name).apply {
parent?.let { dependsOn(parent) }
@@ -47,16 +54,17 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
private fun createIntermediateSourceSets(
namePrefix: String,
children: List<DefaultSourceSets>,
parent: DefaultSourceSets? = null
parent: DefaultSourceSets? = null,
): DefaultSourceSets {
val main = createIntermediateSourceSet("${namePrefix}Main", children.map { it.main }, parent?.main)
val test = createIntermediateSourceSet("${namePrefix}Test", children.map { it.test }, parent?.test)
return DefaultSourceSets(main, test)
}
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun ios(
namePrefix: String = "ios",
configure: KotlinNativeTarget.() -> Unit = {}
configure: KotlinNativeTarget.() -> Unit = {},
) {
val targets = listOf(
iosArm64("${namePrefix}Arm64"),
@@ -66,14 +74,35 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
targets.forEach { it.configure() }
}
/**
* Deprecated:
* Declare targets explicitly like
* ```kotlin
* kotlin {
* applyDefaultHierarchyTemplate() /* <- optional; is applied by default, when compatible */
*
* iosX64()
* iosArm64()
* iosSimulatorArm64() // <- Note: This target was previously not registered by the ios() shortcut!
*
* /* ... more targets! */
* }
* ```
*/
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun ios() = ios("ios") { }
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun ios(namePrefix: String) = ios(namePrefix) { }
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun ios(namePrefix: String, configure: Action<KotlinNativeTarget>) = ios(namePrefix) { configure.execute(this) }
fun ios(configure: Action<KotlinNativeTarget>) = ios { configure.execute(this) }
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun tvos(
namePrefix: String = "tvos",
configure: KotlinNativeTarget.() -> Unit
configure: KotlinNativeTarget.() -> Unit,
) {
val targets = listOf(
tvosArm64("${namePrefix}Arm64"),
@@ -83,14 +112,37 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
targets.forEach { it.configure() }
}
/**
* Deprecated:
* Declare targets explicitly like
* ```kotlin
* kotlin {
* applyDefaultHierarchyTemplate() /* <- optional; is applied by default, when compatible */
*
* tvosArm64()
* tvosX64()
* tvosSimulatorArm64() // <- Note: This target was previously not registered by the tvos() shortcut!
*
* /* ... more targets! */
* }
* ```
*/
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun tvos() = tvos("tvos") { }
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun tvos(namePrefix: String) = tvos(namePrefix) { }
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun tvos(namePrefix: String, configure: Action<KotlinNativeTarget>) = tvos(namePrefix) { configure.execute(this) }
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun tvos(configure: Action<KotlinNativeTarget>) = tvos { configure.execute(this) }
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun watchos(
namePrefix: String = "watchos",
configure: KotlinNativeTarget.() -> Unit = {}
configure: KotlinNativeTarget.() -> Unit = {},
) {
val device32 = watchosArm32("${namePrefix}Arm32")
val device64 = watchosArm64("${namePrefix}Arm64")
@@ -111,8 +163,32 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
listOf(device32, device64, simulatorX64).forEach { it.configure() }
}
/**
* Deprecated:
* Declare targets explicitly like
* ```kotlin
* kotlin {
* applyDefaultHierarchyTemplate() /* <- optional; is applied by default, when compatible */
*
* watchosArm64()
* watchosX64()
* watchosSimulatorArm64() // <- Note: This target was previously not registered by the watchos() shortcut!
* watchosArm32() //<- Note: This target was previously applied, but is likely not needed anymore
*
*
* /* ... more targets! */
* }
* ```
*/
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun watchos() = watchos("watchos") { }
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun watchos(namePrefix: String) = watchos(namePrefix) { }
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun watchos(namePrefix: String, configure: Action<KotlinNativeTarget>) = watchos(namePrefix) { configure.execute(this) }
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
fun watchos(configure: Action<KotlinNativeTarget>) = watchos { configure.execute(this) }
}
@@ -509,7 +509,8 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
kotlin {
jvm()
js().nodejs()
ios()
iosX64()
iosArm64()
}
}
project.evaluate()
@@ -127,10 +127,12 @@ class InternalKotlinSourceSetTest {
fun `test getHostSpecificMainSharedSourceSets`() {
val project = buildProjectWithMPP {
kotlin {
applyDefaultHierarchyTemplate()
jvm()
linuxX64()
linuxArm64()
ios() // host specific from preset
iosX64()
iosArm64()
}
}
@@ -147,11 +149,6 @@ class InternalKotlinSourceSetTest {
val iosX64Test = getByName("iosX64Test")
val iosArm64Test = getByName("iosArm64Test")
val linuxX64Main = getByName("linuxX64Main")
val linuxArm64Main = getByName("linuxArm64Main")
val linuxX64Test = getByName("linuxX64Test")
val linuxArm64Test = getByName("linuxArm64Test")
// common -> ios2 -> ios
create("ios2Main") { it.dependsOn(commonMain); iosMain.dependsOn(it) }
create("ios2Test") { it.dependsOn(commonTest); iosTest.dependsOn(it) }
@@ -161,23 +158,11 @@ class InternalKotlinSourceSetTest {
create("ios2X64Test") { it.dependsOn(iosTest); iosX64Test.dependsOn(it) }
create("ios2Arm64Main") { it.dependsOn(iosMain); iosArm64Main.dependsOn(it) }
create("ios2Arm64Test") { it.dependsOn(iosTest); iosArm64Test.dependsOn(it) }
// common -> linux
create("linuxMain") {
it.dependsOn(commonMain)
linuxX64Main.dependsOn(it)
linuxArm64Main.dependsOn(it)
}
create("linuxTest") {
it.dependsOn(commonTest)
linuxX64Test.dependsOn(it)
linuxArm64Test.dependsOn(it)
}
}
project.evaluate()
val expected = listOf("iosMain", "ios2Main").sorted()
val expected = listOf("appleMain", "iosMain", "ios2Main").sorted()
val actual = project.future { getHostSpecificMainSharedSourceSets(project).map { it.name }.sorted() }.getOrThrow()
assertEquals(expected, actual)