HMPP: Parameterize NativePlatform with KonanTarget
This commit is contained in:
@@ -8,6 +8,7 @@ dependencies {
|
||||
compile(project(":compiler:config"))
|
||||
compile(project(":compiler:config.jvm"))
|
||||
compile(project(":js:js.config"))
|
||||
compile(project(":native:kotlin-native-utils"))
|
||||
compileOnly(project(":kotlin-reflect-api"))
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
compileOnly(intellijDep()) { includeIntellijCoreJarDependencies(project) }
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.platform.js.JsPlatforms.defaultJsPlatform
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms.allJvmPlatforms
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms.unspecifiedJvmPlatform
|
||||
import org.jetbrains.kotlin.platform.konan.NativePlatforms.allNativePlatforms
|
||||
import org.jetbrains.kotlin.platform.konan.NativePlatforms.defaultNativePlatform
|
||||
import org.jetbrains.kotlin.platform.konan.NativePlatforms.unspecifiedNativePlatform
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
object CommonPlatforms {
|
||||
@@ -23,7 +23,7 @@ object CommonPlatforms {
|
||||
setOf(
|
||||
unspecifiedJvmPlatform.single(),
|
||||
defaultJsPlatform.single(),
|
||||
defaultNativePlatform.single()
|
||||
unspecifiedNativePlatform.single()
|
||||
)
|
||||
), org.jetbrains.kotlin.analyzer.common.CommonPlatform {
|
||||
override val platformName: String
|
||||
|
||||
@@ -5,33 +5,62 @@
|
||||
|
||||
package org.jetbrains.kotlin.platform.konan
|
||||
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.platform.SimplePlatform
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.toTargetPlatform
|
||||
|
||||
sealed class NativePlatform : SimplePlatform("Native")
|
||||
|
||||
object NativePlatformUnspecifiedTarget : NativePlatform() {
|
||||
override fun toString() = "$platformName (general)"
|
||||
|
||||
abstract class NativePlatform : SimplePlatform("Native") {
|
||||
override val oldFashionedDescription: String
|
||||
get() = "Native "
|
||||
get() = "Native (general) "
|
||||
}
|
||||
|
||||
data class NativePlatformWithTarget(val target: KonanTarget) : NativePlatform() {
|
||||
override fun toString() = "$platformName ($target)"
|
||||
|
||||
override val oldFashionedDescription: String
|
||||
get() = "Native ($target) "
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
object NativePlatforms {
|
||||
private object DefaultSimpleNativePlatform : NativePlatform()
|
||||
private val predefinedNativeTargetToSimpleNativePlatform: Map<KonanTarget, NativePlatformWithTarget> =
|
||||
KonanTarget.predefinedTargets.values.associateWith { NativePlatformWithTarget(it) }
|
||||
|
||||
private val predefinedNativeTargetToNativePlatform: Map<KonanTarget, TargetPlatform> =
|
||||
predefinedNativeTargetToSimpleNativePlatform.mapValues { (_, simplePlatform) -> simplePlatform.toTargetPlatform() }
|
||||
|
||||
val unspecifiedNativePlatform: TargetPlatform
|
||||
get() = CompatNativePlatform
|
||||
|
||||
val allNativePlatforms: List<TargetPlatform> = listOf(unspecifiedNativePlatform) + predefinedNativeTargetToNativePlatform.values
|
||||
|
||||
fun nativePlatformBySingleTarget(target: KonanTarget): TargetPlatform =
|
||||
predefinedNativeTargetToNativePlatform[target] ?: unspecifiedNativePlatform
|
||||
|
||||
fun nativePlatformByTargets(targets: Collection<KonanTarget>): TargetPlatform {
|
||||
val simplePlatforms = targets.mapNotNullTo(HashSet()) { predefinedNativeTargetToSimpleNativePlatform[it] }
|
||||
return when (simplePlatforms.size) {
|
||||
0 -> unspecifiedNativePlatform
|
||||
1 -> nativePlatformBySingleTarget(simplePlatforms.first().target)
|
||||
else -> TargetPlatform(simplePlatforms)
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
message = "Should be accessed only by compatibility layer, other clients should use 'defaultNativePlatform'",
|
||||
message = "Should be accessed only by compatibility layer, other clients should use 'unspecifiedNativePlatform'",
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
object CompatNativePlatform : TargetPlatform(setOf(DefaultSimpleNativePlatform)),
|
||||
object CompatNativePlatform : TargetPlatform(setOf(NativePlatformUnspecifiedTarget)),
|
||||
// Needed for backward compatibility, because old code uses INSTANCEOF checks instead of calling extensions
|
||||
org.jetbrains.kotlin.resolve.konan.platform.KonanPlatform {
|
||||
override val platformName: String
|
||||
get() = "Native"
|
||||
}
|
||||
|
||||
val defaultNativePlatform: TargetPlatform
|
||||
get() = CompatNativePlatform
|
||||
|
||||
val allNativePlatforms: List<TargetPlatform> = listOf(defaultNativePlatform)
|
||||
}
|
||||
|
||||
fun TargetPlatform?.isNative(): Boolean = this?.singleOrNull() is NativePlatform
|
||||
fun TargetPlatform?.isNative(): Boolean = this?.isNotEmpty() == true && all { it is NativePlatform }
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
|
||||
@Deprecated(
|
||||
message = "This class is deprecated and will be removed soon, use API from 'org.jetbrains.kotlin.platform.*' packages instead",
|
||||
replaceWith = ReplaceWith("NativePlatforms.defaultNativePlatform", "org.jetbrains.kotlin.platform.konan.NativePlatforms"),
|
||||
replaceWith = ReplaceWith("NativePlatforms.unspecifiedNativePlatform", "org.jetbrains.kotlin.platform.konan.NativePlatforms"),
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
interface KonanPlatform : TargetPlatform {
|
||||
|
||||
Reference in New Issue
Block a user