[Gradle/MPP] Refactored KotlinTargetContainerWithPresetFunctions
Android preset functions were moved to a separate interface because we need to write custom deprecation with ReplaceWith due KT-57903. After that we had generated: - all the K/N preset functions - jvm functions. I decided to move jvm function to separate file too, so the whole division to several files would be somewhat sane. I kept the KotlinTargetContainerWithPresetFunctions interface to keep source/binary compatibility for the `android`/ `jvm` preset functions users #KT-57903 In Progress
This commit is contained in:
committed by
Space Team
parent
725cfb4ea5
commit
becf50ee0f
+3
-3
@@ -19,7 +19,7 @@ private val presetsProperty = KotlinTargetsContainerWithPresets::presets.name
|
|||||||
|
|
||||||
private fun generateKotlinTargetContainerWithPresetFunctionsInterface() {
|
private fun generateKotlinTargetContainerWithPresetFunctionsInterface() {
|
||||||
// Generate KotlinMultiplatformExtension subclass with member functions for the presets:
|
// Generate KotlinMultiplatformExtension subclass with member functions for the presets:
|
||||||
val functions = allPresetEntries.map { kotlinPreset ->
|
val functions = nativePresetEntries.map { kotlinPreset ->
|
||||||
// magic indent is needed to make the result look pretty
|
// magic indent is needed to make the result look pretty
|
||||||
val funPrefix = kotlinPreset.deprecation?.let { "\n $it\n @Suppress(\"DEPRECATION\")\n " } ?: ""
|
val funPrefix = kotlinPreset.deprecation?.let { "\n $it\n @Suppress(\"DEPRECATION\")\n " } ?: ""
|
||||||
generatePresetFunctions(kotlinPreset, presetsProperty, "configureOrCreate", funPrefix)
|
generatePresetFunctions(kotlinPreset, presetsProperty, "configureOrCreate", funPrefix)
|
||||||
@@ -29,11 +29,11 @@ private fun generateKotlinTargetContainerWithPresetFunctionsInterface() {
|
|||||||
typeName(parentInterface.java.canonicalName)
|
typeName(parentInterface.java.canonicalName)
|
||||||
|
|
||||||
val className =
|
val className =
|
||||||
typeName("org.jetbrains.kotlin.gradle.dsl.KotlinTargetContainerWithPresetFunctions")
|
typeName("org.jetbrains.kotlin.gradle.dsl.KotlinTargetContainerWithNativePresetFunctions")
|
||||||
|
|
||||||
val deprecatedMessageVal = typeName("org.jetbrains.kotlin.konan.target.DEPRECATED_TARGET_MESSAGE")
|
val deprecatedMessageVal = typeName("org.jetbrains.kotlin.konan.target.DEPRECATED_TARGET_MESSAGE")
|
||||||
|
|
||||||
val imports = allPresetEntries
|
val imports = nativePresetEntries
|
||||||
.flatMap { it.typeNames() }
|
.flatMap { it.typeNames() }
|
||||||
.plus(parentInterfaceName)
|
.plus(parentInterfaceName)
|
||||||
.plus(deprecatedMessageVal)
|
.plus(deprecatedMessageVal)
|
||||||
|
|||||||
-17
@@ -36,18 +36,6 @@ internal object NativeFQNames {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val jvmPresetEntry = KotlinPresetEntry(
|
|
||||||
"jvm",
|
|
||||||
typeName("$MPP_PACKAGE.KotlinJvmTargetPreset"),
|
|
||||||
typeName("org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget")
|
|
||||||
)
|
|
||||||
|
|
||||||
internal val androidPresetEntry = KotlinPresetEntry(
|
|
||||||
"android",
|
|
||||||
typeName("$MPP_PACKAGE.KotlinAndroidTargetPreset"),
|
|
||||||
typeName("$MPP_PACKAGE.KotlinAndroidTarget")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Note: modifying these sets should also be reflected in the MPP plugin code, see 'setupDefaultPresets'
|
// Note: modifying these sets should also be reflected in the MPP plugin code, see 'setupDefaultPresets'
|
||||||
private val nativeTargetsWithHostTests =
|
private val nativeTargetsWithHostTests =
|
||||||
setOf(KonanTarget.LINUX_X64, KonanTarget.MACOS_X64, KonanTarget.MACOS_ARM64, KonanTarget.MINGW_X64)
|
setOf(KonanTarget.LINUX_X64, KonanTarget.MACOS_X64, KonanTarget.MACOS_ARM64, KonanTarget.MINGW_X64)
|
||||||
@@ -79,8 +67,3 @@ internal val nativePresetEntries = HostManager().targets
|
|||||||
|
|
||||||
KotlinPresetEntry(target.presetName, typeName(presetType), typeName(targetType), deprecation)
|
KotlinPresetEntry(target.presetName, typeName(presetType), typeName(targetType), deprecation)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val allPresetEntries = listOf(
|
|
||||||
jvmPresetEntry,
|
|
||||||
androidPresetEntry
|
|
||||||
) + nativePresetEntries
|
|
||||||
|
|||||||
+7
-2
@@ -16,11 +16,16 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.targetHierarchy.KotlinTargetHierarchyDslImpl
|
import org.jetbrains.kotlin.gradle.plugin.mpp.targetHierarchy.KotlinTargetHierarchyDslImpl
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
interface KotlinTargetContainerWithPresetFunctions :
|
||||||
|
KotlinTargetContainerWithJvmPresetFunctions,
|
||||||
|
KotlinTargetContainerWithAndroidPresetFunctions,
|
||||||
|
KotlinTargetContainerWithNativePresetFunctions,
|
||||||
|
KotlinTargetContainerWithJsPresetFunctions,
|
||||||
|
KotlinTargetContainerWithWasmPresetFunctions
|
||||||
|
|
||||||
abstract class KotlinMultiplatformExtension(project: Project) :
|
abstract class KotlinMultiplatformExtension(project: Project) :
|
||||||
KotlinProjectExtension(project),
|
KotlinProjectExtension(project),
|
||||||
KotlinTargetContainerWithPresetFunctions,
|
KotlinTargetContainerWithPresetFunctions,
|
||||||
KotlinTargetContainerWithJsPresetFunctions,
|
|
||||||
KotlinTargetContainerWithWasmPresetFunctions,
|
|
||||||
KotlinTargetContainerWithNativeShortcuts {
|
KotlinTargetContainerWithNativeShortcuts {
|
||||||
override val presets: NamedDomainObjectCollection<KotlinTargetPreset<*>> = project.container(KotlinTargetPreset::class.java)
|
override val presets: NamedDomainObjectCollection<KotlinTargetPreset<*>> = project.container(KotlinTargetPreset::class.java)
|
||||||
|
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.dsl
|
||||||
|
|
||||||
|
import org.gradle.api.Action
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainerWithPresets
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTargetPreset
|
||||||
|
|
||||||
|
interface KotlinTargetContainerWithAndroidPresetFunctions : KotlinTargetsContainerWithPresets {
|
||||||
|
|
||||||
|
fun android(
|
||||||
|
name: String = "android",
|
||||||
|
configure: KotlinAndroidTarget.() -> Unit = { }
|
||||||
|
): KotlinAndroidTarget =
|
||||||
|
configureOrCreate(
|
||||||
|
name,
|
||||||
|
presets.getByName("android") as KotlinAndroidTargetPreset,
|
||||||
|
configure
|
||||||
|
)
|
||||||
|
|
||||||
|
fun android() = android("android") { }
|
||||||
|
fun android(name: String) = android(name) { }
|
||||||
|
fun android(name: String, configure: Action<KotlinAndroidTarget>) = android(name) { configure.execute(this) }
|
||||||
|
fun android(configure: Action<KotlinAndroidTarget>) = android { configure.execute(this) }
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
|
|||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
|
|
||||||
interface KotlinTargetContainerWithJsPresetFunctions :
|
interface KotlinTargetContainerWithJsPresetFunctions :
|
||||||
KotlinTargetContainerWithPresetFunctions,
|
KotlinTargetsContainerWithPresets,
|
||||||
KotlinJsCompilerTypeHolder {
|
KotlinJsCompilerTypeHolder {
|
||||||
fun js(
|
fun js(
|
||||||
name: String = "js",
|
name: String = "js",
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.dsl
|
||||||
|
|
||||||
|
import org.gradle.api.Action
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainerWithPresets
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmTargetPreset
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||||
|
|
||||||
|
interface KotlinTargetContainerWithJvmPresetFunctions : KotlinTargetsContainerWithPresets {
|
||||||
|
|
||||||
|
fun jvm(
|
||||||
|
name: String = "jvm",
|
||||||
|
configure: KotlinJvmTarget.() -> Unit = { }
|
||||||
|
): KotlinJvmTarget =
|
||||||
|
configureOrCreate(
|
||||||
|
name,
|
||||||
|
presets.getByName("jvm") as KotlinJvmTargetPreset,
|
||||||
|
configure
|
||||||
|
)
|
||||||
|
|
||||||
|
fun jvm() = jvm("jvm") { }
|
||||||
|
fun jvm(name: String) = jvm(name) { }
|
||||||
|
fun jvm(name: String, configure: Action<KotlinJvmTarget>) = jvm(name) { configure.execute(this) }
|
||||||
|
fun jvm(configure: Action<KotlinJvmTarget>) = jvm { configure.execute(this) }
|
||||||
|
|
||||||
|
}
|
||||||
+1
-35
@@ -2,51 +2,17 @@ package org.jetbrains.kotlin.gradle.dsl
|
|||||||
|
|
||||||
import org.gradle.api.Action
|
import org.gradle.api.Action
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainerWithPresets
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainerWithPresets
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTargetPreset
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmTargetPreset
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTestsPreset
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTestsPreset
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTests
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTests
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTestsPreset
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTestsPreset
|
||||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
|
||||||
import org.jetbrains.kotlin.konan.target.DEPRECATED_TARGET_MESSAGE
|
import org.jetbrains.kotlin.konan.target.DEPRECATED_TARGET_MESSAGE
|
||||||
|
|
||||||
// DO NOT EDIT MANUALLY! Generated by org.jetbrains.kotlin.generators.gradle.dsl.MppPresetFunctionsCodegenKt
|
// DO NOT EDIT MANUALLY! Generated by org.jetbrains.kotlin.generators.gradle.dsl.MppPresetFunctionsCodegenKt
|
||||||
|
|
||||||
interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithPresets {
|
interface KotlinTargetContainerWithNativePresetFunctions : KotlinTargetsContainerWithPresets {
|
||||||
|
|
||||||
fun jvm(
|
|
||||||
name: String = "jvm",
|
|
||||||
configure: KotlinJvmTarget.() -> Unit = { }
|
|
||||||
): KotlinJvmTarget =
|
|
||||||
configureOrCreate(
|
|
||||||
name,
|
|
||||||
presets.getByName("jvm") as KotlinJvmTargetPreset,
|
|
||||||
configure
|
|
||||||
)
|
|
||||||
|
|
||||||
fun jvm() = jvm("jvm") { }
|
|
||||||
fun jvm(name: String) = jvm(name) { }
|
|
||||||
fun jvm(name: String, configure: Action<KotlinJvmTarget>) = jvm(name) { configure.execute(this) }
|
|
||||||
fun jvm(configure: Action<KotlinJvmTarget>) = jvm { configure.execute(this) }
|
|
||||||
|
|
||||||
fun android(
|
|
||||||
name: String = "android",
|
|
||||||
configure: KotlinAndroidTarget.() -> Unit = { }
|
|
||||||
): KotlinAndroidTarget =
|
|
||||||
configureOrCreate(
|
|
||||||
name,
|
|
||||||
presets.getByName("android") as KotlinAndroidTargetPreset,
|
|
||||||
configure
|
|
||||||
)
|
|
||||||
|
|
||||||
fun android() = android("android") { }
|
|
||||||
fun android(name: String) = android(name) { }
|
|
||||||
fun android(name: String, configure: Action<KotlinAndroidTarget>) = android(name) { configure.execute(this) }
|
|
||||||
fun android(configure: Action<KotlinAndroidTarget>) = android { configure.execute(this) }
|
|
||||||
|
|
||||||
fun androidNativeX64(
|
fun androidNativeX64(
|
||||||
name: String = "androidNativeX64",
|
name: String = "androidNativeX64",
|
||||||
+2
-1
@@ -6,12 +6,13 @@
|
|||||||
package org.jetbrains.kotlin.gradle.dsl
|
package org.jetbrains.kotlin.gradle.dsl
|
||||||
|
|
||||||
import org.gradle.api.Action
|
import org.gradle.api.Action
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainerWithPresets
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmTargetDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmTargetDsl
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinWasmTargetPreset
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinWasmTargetPreset
|
||||||
|
|
||||||
interface KotlinTargetContainerWithWasmPresetFunctions : KotlinTargetContainerWithPresetFunctions {
|
interface KotlinTargetContainerWithWasmPresetFunctions : KotlinTargetsContainerWithPresets {
|
||||||
@ExperimentalWasmDsl
|
@ExperimentalWasmDsl
|
||||||
fun wasm(
|
fun wasm(
|
||||||
name: String = "wasm",
|
name: String = "wasm",
|
||||||
|
|||||||
Reference in New Issue
Block a user