[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() {
|
||||
// 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
|
||||
val funPrefix = kotlinPreset.deprecation?.let { "\n $it\n @Suppress(\"DEPRECATION\")\n " } ?: ""
|
||||
generatePresetFunctions(kotlinPreset, presetsProperty, "configureOrCreate", funPrefix)
|
||||
@@ -29,11 +29,11 @@ private fun generateKotlinTargetContainerWithPresetFunctionsInterface() {
|
||||
typeName(parentInterface.java.canonicalName)
|
||||
|
||||
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 imports = allPresetEntries
|
||||
val imports = nativePresetEntries
|
||||
.flatMap { it.typeNames() }
|
||||
.plus(parentInterfaceName)
|
||||
.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'
|
||||
private val nativeTargetsWithHostTests =
|
||||
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)
|
||||
}
|
||||
|
||||
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 javax.inject.Inject
|
||||
|
||||
interface KotlinTargetContainerWithPresetFunctions :
|
||||
KotlinTargetContainerWithJvmPresetFunctions,
|
||||
KotlinTargetContainerWithAndroidPresetFunctions,
|
||||
KotlinTargetContainerWithNativePresetFunctions,
|
||||
KotlinTargetContainerWithJsPresetFunctions,
|
||||
KotlinTargetContainerWithWasmPresetFunctions
|
||||
|
||||
abstract class KotlinMultiplatformExtension(project: Project) :
|
||||
KotlinProjectExtension(project),
|
||||
KotlinTargetContainerWithPresetFunctions,
|
||||
KotlinTargetContainerWithJsPresetFunctions,
|
||||
KotlinTargetContainerWithWasmPresetFunctions,
|
||||
KotlinTargetContainerWithNativeShortcuts {
|
||||
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
|
||||
|
||||
interface KotlinTargetContainerWithJsPresetFunctions :
|
||||
KotlinTargetContainerWithPresetFunctions,
|
||||
KotlinTargetsContainerWithPresets,
|
||||
KotlinJsCompilerTypeHolder {
|
||||
fun 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.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.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.targets.jvm.KotlinJvmTarget
|
||||
import org.jetbrains.kotlin.konan.target.DEPRECATED_TARGET_MESSAGE
|
||||
|
||||
// DO NOT EDIT MANUALLY! Generated by org.jetbrains.kotlin.generators.gradle.dsl.MppPresetFunctionsCodegenKt
|
||||
|
||||
interface KotlinTargetContainerWithPresetFunctions : 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) }
|
||||
interface KotlinTargetContainerWithNativePresetFunctions : KotlinTargetsContainerWithPresets {
|
||||
|
||||
fun androidNativeX64(
|
||||
name: String = "androidNativeX64",
|
||||
+2
-1
@@ -6,12 +6,13 @@
|
||||
package org.jetbrains.kotlin.gradle.dsl
|
||||
|
||||
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.KotlinJsTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinWasmTargetPreset
|
||||
|
||||
interface KotlinTargetContainerWithWasmPresetFunctions : KotlinTargetContainerWithPresetFunctions {
|
||||
interface KotlinTargetContainerWithWasmPresetFunctions : KotlinTargetsContainerWithPresets {
|
||||
@ExperimentalWasmDsl
|
||||
fun wasm(
|
||||
name: String = "wasm",
|
||||
|
||||
Reference in New Issue
Block a user