[Gradle][MPP] Deprecate several K/N targets
This commit is contained in:
committed by
Space Team
parent
3d4af8e1ab
commit
37ab139139
+21
-9
@@ -25,6 +25,7 @@ private fun generateAbstractKotlinArtifactsExtensionImplementation() {
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinArtifactsExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.BitcodeEmbeddingMode
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
||||
import org.jetbrains.kotlin.konan.target.DEPRECATED_TARGET_MESSAGE
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import javax.inject.Inject
|
||||
""".trimIndent()
|
||||
@@ -54,15 +55,15 @@ private fun generateAbstractKotlinArtifactsExtensionImplementation() {
|
||||
"val EmbedBitcodeMode = BitcodeEmbeddingModeDsl()"
|
||||
).joinToString("\n").indented(4)
|
||||
|
||||
val konanTargetConstants = KonanTarget.predefinedTargets.values.joinToString("\n") {
|
||||
val nameParts = it.name.split("_")
|
||||
val name = nameParts.drop(1).joinToString(
|
||||
separator = "",
|
||||
prefix = nameParts.first(),
|
||||
transform = String::capitalizeUS
|
||||
)
|
||||
"val $name = KonanTarget.${it.name.uppercase(Locale.US)}"
|
||||
}.indented(4)
|
||||
val konanTargetConstants = KonanTarget.predefinedTargets.values.filter { !KonanTarget.deprecatedTargets.contains(it) }
|
||||
.joinToString("\n") {
|
||||
it.generateKonanTargetVal()
|
||||
}.indented(4)
|
||||
|
||||
val deprecatedKonanTargetConstants = KonanTarget.predefinedTargets.values.filter { KonanTarget.deprecatedTargets.contains(it) }
|
||||
.joinToString("\n") {
|
||||
"\n@Deprecated(DEPRECATED_TARGET_MESSAGE)\n" + it.generateKonanTargetVal()
|
||||
}.indented(4)
|
||||
|
||||
val code = listOf(
|
||||
"package ${className.packageName()}",
|
||||
@@ -74,9 +75,20 @@ private fun generateAbstractKotlinArtifactsExtensionImplementation() {
|
||||
bitcodeModeConstants,
|
||||
bitcodeMode,
|
||||
konanTargetConstants,
|
||||
deprecatedKonanTargetConstants,
|
||||
"}"
|
||||
).joinToString(separator = "\n\n")
|
||||
|
||||
val targetFile = File("$outputSourceRoot/${className.fqName.replace(".", "/")}.kt")
|
||||
targetFile.writeText(code)
|
||||
}
|
||||
|
||||
private fun KonanTarget.generateKonanTargetVal(): String {
|
||||
val nameParts = this.name.split("_")
|
||||
val name = nameParts.drop(1).joinToString(
|
||||
separator = "",
|
||||
prefix = nameParts.first(),
|
||||
transform = String::capitalizeUS
|
||||
)
|
||||
return "val $name = KonanTarget.${this.name.uppercase(Locale.US)}"
|
||||
}
|
||||
+14
-8
@@ -19,8 +19,10 @@ private val presetsProperty = KotlinTargetsContainerWithPresets::presets.name
|
||||
|
||||
private fun generateKotlinTargetContainerWithPresetFunctionsInterface() {
|
||||
// Generate KotlinMultiplatformExtension subclass with member functions for the presets:
|
||||
val functions = allPresetEntries.map {
|
||||
generatePresetFunctions(it, presetsProperty, "configureOrCreate")
|
||||
val functions = allPresetEntries.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)
|
||||
}
|
||||
|
||||
val parentInterfaceName =
|
||||
@@ -29,9 +31,12 @@ private fun generateKotlinTargetContainerWithPresetFunctionsInterface() {
|
||||
val className =
|
||||
typeName("org.jetbrains.kotlin.gradle.dsl.KotlinTargetContainerWithPresetFunctions")
|
||||
|
||||
val deprecatedMessageVal = typeName("org.jetbrains.kotlin.konan.target.DEPRECATED_TARGET_MESSAGE")
|
||||
|
||||
val imports = allPresetEntries
|
||||
.flatMap { it.typeNames() }
|
||||
.plus(parentInterfaceName)
|
||||
.plus(deprecatedMessageVal)
|
||||
.plus(typeName(Action::class.java.canonicalName))
|
||||
.filter { it.packageName() != className.packageName() }
|
||||
.flatMap { it.collectFqNames() }
|
||||
@@ -56,11 +61,12 @@ private fun generateKotlinTargetContainerWithPresetFunctionsInterface() {
|
||||
private fun generatePresetFunctions(
|
||||
presetEntry: KotlinPresetEntry,
|
||||
getPresetsExpression: String,
|
||||
configureOrCreateFunctionName: String
|
||||
configureOrCreateFunctionName: String,
|
||||
funPrefix: String = ""
|
||||
): String {
|
||||
val presetName = presetEntry.presetName
|
||||
return """
|
||||
fun $presetName(
|
||||
${funPrefix}fun $presetName(
|
||||
name: String = "$presetName",
|
||||
configure: ${presetEntry.targetType.renderShort()}.() -> Unit = { }
|
||||
): ${presetEntry.targetType.renderShort()} =
|
||||
@@ -70,9 +76,9 @@ private fun generatePresetFunctions(
|
||||
configure
|
||||
)
|
||||
|
||||
fun $presetName() = $presetName("$presetName") { }
|
||||
fun $presetName(name: String) = $presetName(name) { }
|
||||
fun $presetName(name: String, configure: Action<${presetEntry.targetType.renderShort()}>) = $presetName(name) { configure.execute(this) }
|
||||
fun $presetName(configure: Action<${presetEntry.targetType.renderShort()}>) = $presetName { configure.execute(this) }
|
||||
${funPrefix}fun $presetName() = $presetName("$presetName") { }
|
||||
${funPrefix}fun $presetName(name: String) = $presetName(name) { }
|
||||
${funPrefix}fun $presetName(name: String, configure: Action<${presetEntry.targetType.renderShort()}>) = $presetName(name) { configure.execute(this) }
|
||||
${funPrefix}fun $presetName(configure: Action<${presetEntry.targetType.renderShort()}>) = $presetName { configure.execute(this) }
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
+4
-2
@@ -14,7 +14,8 @@ import org.jetbrains.kotlin.konan.target.presetName
|
||||
internal class KotlinPresetEntry(
|
||||
val presetName: String,
|
||||
val presetType: TypeName,
|
||||
val targetType: TypeName
|
||||
val targetType: TypeName,
|
||||
val deprecation: String? = null
|
||||
)
|
||||
|
||||
internal fun KotlinPresetEntry.typeNames(): Set<TypeName> = setOf(presetType, targetType)
|
||||
@@ -74,8 +75,9 @@ internal val nativePresetEntries = HostManager().targets
|
||||
else ->
|
||||
Presets.simple to Targets.base
|
||||
}
|
||||
val deprecation = "@Deprecated(DEPRECATED_TARGET_MESSAGE)".takeIf { target in KonanTarget.deprecatedTargets }
|
||||
|
||||
KotlinPresetEntry(target.presetName, typeName(presetType), typeName(targetType))
|
||||
KotlinPresetEntry(target.presetName, typeName(presetType), typeName(targetType), deprecation)
|
||||
}
|
||||
|
||||
internal val allPresetEntries = listOf(
|
||||
|
||||
Reference in New Issue
Block a user