[Gradle] Deprecate native target shortcuts ...
... in favor of default hierarchy template ^KT-58676 Verification Pending
This commit is contained in:
committed by
Space Team
parent
845c8bd1c3
commit
0b57dac738
+1
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.hierarchy.default
|
import org.jetbrains.kotlin.gradle.plugin.hierarchy.default
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
@KotlinGradlePluginDsl
|
@KotlinGradlePluginDsl
|
||||||
abstract class KotlinMultiplatformExtension
|
abstract class KotlinMultiplatformExtension
|
||||||
@InternalKotlinGradlePluginApi constructor(project: Project) :
|
@InternalKotlinGradlePluginApi constructor(project: Project) :
|
||||||
|
|||||||
+81
-5
@@ -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.
|
* 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
|
package org.jetbrains.kotlin.gradle.dsl
|
||||||
|
|
||||||
import org.gradle.api.Action
|
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.KotlinSourceSetContainer
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
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
|
@KotlinGradlePluginDsl
|
||||||
|
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
|
||||||
interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPresetFunctions, KotlinSourceSetContainer {
|
interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPresetFunctions, KotlinSourceSetContainer {
|
||||||
|
|
||||||
private data class DefaultSourceSets(val main: KotlinSourceSet, val test: KotlinSourceSet)
|
private data class DefaultSourceSets(val main: KotlinSourceSet, val test: KotlinSourceSet)
|
||||||
@@ -35,7 +42,7 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
|||||||
private fun createIntermediateSourceSet(
|
private fun createIntermediateSourceSet(
|
||||||
name: String,
|
name: String,
|
||||||
children: List<KotlinSourceSet>,
|
children: List<KotlinSourceSet>,
|
||||||
parent: KotlinSourceSet? = null
|
parent: KotlinSourceSet? = null,
|
||||||
): KotlinSourceSet =
|
): KotlinSourceSet =
|
||||||
sourceSets.maybeCreate(name).apply {
|
sourceSets.maybeCreate(name).apply {
|
||||||
parent?.let { dependsOn(parent) }
|
parent?.let { dependsOn(parent) }
|
||||||
@@ -47,16 +54,17 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
|||||||
private fun createIntermediateSourceSets(
|
private fun createIntermediateSourceSets(
|
||||||
namePrefix: String,
|
namePrefix: String,
|
||||||
children: List<DefaultSourceSets>,
|
children: List<DefaultSourceSets>,
|
||||||
parent: DefaultSourceSets? = null
|
parent: DefaultSourceSets? = null,
|
||||||
): DefaultSourceSets {
|
): DefaultSourceSets {
|
||||||
val main = createIntermediateSourceSet("${namePrefix}Main", children.map { it.main }, parent?.main)
|
val main = createIntermediateSourceSet("${namePrefix}Main", children.map { it.main }, parent?.main)
|
||||||
val test = createIntermediateSourceSet("${namePrefix}Test", children.map { it.test }, parent?.test)
|
val test = createIntermediateSourceSet("${namePrefix}Test", children.map { it.test }, parent?.test)
|
||||||
return DefaultSourceSets(main, test)
|
return DefaultSourceSets(main, test)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
|
||||||
fun ios(
|
fun ios(
|
||||||
namePrefix: String = "ios",
|
namePrefix: String = "ios",
|
||||||
configure: KotlinNativeTarget.() -> Unit = {}
|
configure: KotlinNativeTarget.() -> Unit = {},
|
||||||
) {
|
) {
|
||||||
val targets = listOf(
|
val targets = listOf(
|
||||||
iosArm64("${namePrefix}Arm64"),
|
iosArm64("${namePrefix}Arm64"),
|
||||||
@@ -66,14 +74,35 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
|||||||
targets.forEach { it.configure() }
|
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") { }
|
fun ios() = ios("ios") { }
|
||||||
|
|
||||||
|
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
|
||||||
fun ios(namePrefix: String) = ios(namePrefix) { }
|
fun ios(namePrefix: String) = ios(namePrefix) { }
|
||||||
|
|
||||||
|
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
|
||||||
fun ios(namePrefix: String, configure: Action<KotlinNativeTarget>) = ios(namePrefix) { configure.execute(this) }
|
fun ios(namePrefix: String, configure: Action<KotlinNativeTarget>) = ios(namePrefix) { configure.execute(this) }
|
||||||
fun ios(configure: Action<KotlinNativeTarget>) = ios { configure.execute(this) }
|
fun ios(configure: Action<KotlinNativeTarget>) = ios { configure.execute(this) }
|
||||||
|
|
||||||
|
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
|
||||||
fun tvos(
|
fun tvos(
|
||||||
namePrefix: String = "tvos",
|
namePrefix: String = "tvos",
|
||||||
configure: KotlinNativeTarget.() -> Unit
|
configure: KotlinNativeTarget.() -> Unit,
|
||||||
) {
|
) {
|
||||||
val targets = listOf(
|
val targets = listOf(
|
||||||
tvosArm64("${namePrefix}Arm64"),
|
tvosArm64("${namePrefix}Arm64"),
|
||||||
@@ -83,14 +112,37 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
|||||||
targets.forEach { it.configure() }
|
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") { }
|
fun tvos() = tvos("tvos") { }
|
||||||
|
|
||||||
|
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
|
||||||
fun tvos(namePrefix: String) = tvos(namePrefix) { }
|
fun tvos(namePrefix: String) = tvos(namePrefix) { }
|
||||||
|
|
||||||
|
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
|
||||||
fun tvos(namePrefix: String, configure: Action<KotlinNativeTarget>) = tvos(namePrefix) { configure.execute(this) }
|
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) }
|
fun tvos(configure: Action<KotlinNativeTarget>) = tvos { configure.execute(this) }
|
||||||
|
|
||||||
|
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
|
||||||
fun watchos(
|
fun watchos(
|
||||||
namePrefix: String = "watchos",
|
namePrefix: String = "watchos",
|
||||||
configure: KotlinNativeTarget.() -> Unit = {}
|
configure: KotlinNativeTarget.() -> Unit = {},
|
||||||
) {
|
) {
|
||||||
val device32 = watchosArm32("${namePrefix}Arm32")
|
val device32 = watchosArm32("${namePrefix}Arm32")
|
||||||
val device64 = watchosArm64("${namePrefix}Arm64")
|
val device64 = watchosArm64("${namePrefix}Arm64")
|
||||||
@@ -111,8 +163,32 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
|||||||
listOf(device32, device64, simulatorX64).forEach { it.configure() }
|
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") { }
|
fun watchos() = watchos("watchos") { }
|
||||||
|
|
||||||
|
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
|
||||||
fun watchos(namePrefix: String) = watchos(namePrefix) { }
|
fun watchos(namePrefix: String) = watchos(namePrefix) { }
|
||||||
|
|
||||||
|
@Deprecated(SHORTCUTS_DEPRECATION_MESSAGE)
|
||||||
fun watchos(namePrefix: String, configure: Action<KotlinNativeTarget>) = watchos(namePrefix) { configure.execute(this) }
|
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) }
|
fun watchos(configure: Action<KotlinNativeTarget>) = watchos { configure.execute(this) }
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -509,7 +509,8 @@ class ConfigurationsTest : MultiplatformExtensionTest() {
|
|||||||
kotlin {
|
kotlin {
|
||||||
jvm()
|
jvm()
|
||||||
js().nodejs()
|
js().nodejs()
|
||||||
ios()
|
iosX64()
|
||||||
|
iosArm64()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
project.evaluate()
|
project.evaluate()
|
||||||
|
|||||||
+4
-19
@@ -127,10 +127,12 @@ class InternalKotlinSourceSetTest {
|
|||||||
fun `test getHostSpecificMainSharedSourceSets`() {
|
fun `test getHostSpecificMainSharedSourceSets`() {
|
||||||
val project = buildProjectWithMPP {
|
val project = buildProjectWithMPP {
|
||||||
kotlin {
|
kotlin {
|
||||||
|
applyDefaultHierarchyTemplate()
|
||||||
jvm()
|
jvm()
|
||||||
linuxX64()
|
linuxX64()
|
||||||
linuxArm64()
|
linuxArm64()
|
||||||
ios() // host specific from preset
|
iosX64()
|
||||||
|
iosArm64()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,11 +149,6 @@ class InternalKotlinSourceSetTest {
|
|||||||
val iosX64Test = getByName("iosX64Test")
|
val iosX64Test = getByName("iosX64Test")
|
||||||
val iosArm64Test = getByName("iosArm64Test")
|
val iosArm64Test = getByName("iosArm64Test")
|
||||||
|
|
||||||
val linuxX64Main = getByName("linuxX64Main")
|
|
||||||
val linuxArm64Main = getByName("linuxArm64Main")
|
|
||||||
val linuxX64Test = getByName("linuxX64Test")
|
|
||||||
val linuxArm64Test = getByName("linuxArm64Test")
|
|
||||||
|
|
||||||
// common -> ios2 -> ios
|
// common -> ios2 -> ios
|
||||||
create("ios2Main") { it.dependsOn(commonMain); iosMain.dependsOn(it) }
|
create("ios2Main") { it.dependsOn(commonMain); iosMain.dependsOn(it) }
|
||||||
create("ios2Test") { it.dependsOn(commonTest); iosTest.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("ios2X64Test") { it.dependsOn(iosTest); iosX64Test.dependsOn(it) }
|
||||||
create("ios2Arm64Main") { it.dependsOn(iosMain); iosArm64Main.dependsOn(it) }
|
create("ios2Arm64Main") { it.dependsOn(iosMain); iosArm64Main.dependsOn(it) }
|
||||||
create("ios2Arm64Test") { it.dependsOn(iosTest); iosArm64Test.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()
|
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()
|
val actual = project.future { getHostSpecificMainSharedSourceSets(project).map { it.name }.sorted() }.getOrThrow()
|
||||||
|
|
||||||
assertEquals(expected, actual)
|
assertEquals(expected, actual)
|
||||||
|
|||||||
Reference in New Issue
Block a user