From 0b57dac7386f632fe15d4638d66bbab3477577e9 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Wed, 21 Jun 2023 12:14:52 +0200 Subject: [PATCH] [Gradle] Deprecate native target shortcuts ... ... in favor of default hierarchy template ^KT-58676 Verification Pending --- .../dsl/KotlinMultiplatformExtension.kt | 1 + ...otlinTargetContainerWithNativeShortcuts.kt | 86 +++++++++++++++++-- .../regressionTests/ConfigurationsTest.kt | 3 +- .../sources/InternalKotlinSourceSetTest.kt | 23 +---- 4 files changed, 88 insertions(+), 25 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinMultiplatformExtension.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinMultiplatformExtension.kt index c795ce2f0e9..5484614ce7e 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinMultiplatformExtension.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinMultiplatformExtension.kt @@ -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) : diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinTargetContainerWithNativeShortcuts.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinTargetContainerWithNativeShortcuts.kt index 3f8fd77059f..baedaa7a1fe 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinTargetContainerWithNativeShortcuts.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinTargetContainerWithNativeShortcuts.kt @@ -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, - 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, - 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) = ios(namePrefix) { configure.execute(this) } fun ios(configure: Action) = 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) = tvos(namePrefix) { configure.execute(this) } + + @Deprecated(SHORTCUTS_DEPRECATION_MESSAGE) fun tvos(configure: Action) = 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) = watchos(namePrefix) { configure.execute(this) } + + @Deprecated(SHORTCUTS_DEPRECATION_MESSAGE) fun watchos(configure: Action) = watchos { configure.execute(this) } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/regressionTests/ConfigurationsTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/regressionTests/ConfigurationsTest.kt index a22b99ddab9..7ece1a5335c 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/regressionTests/ConfigurationsTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/regressionTests/ConfigurationsTest.kt @@ -509,7 +509,8 @@ class ConfigurationsTest : MultiplatformExtensionTest() { kotlin { jvm() js().nodejs() - ios() + iosX64() + iosArm64() } } project.evaluate() diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/sources/InternalKotlinSourceSetTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/sources/InternalKotlinSourceSetTest.kt index f6dcb8c03cc..34adcb4f23d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/sources/InternalKotlinSourceSetTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/sources/InternalKotlinSourceSetTest.kt @@ -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)