Import of middle HMPP target platforms is supported
Original commit: c0bf5a6566
This commit is contained in:
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.TargetPlatformVersion
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.compat.toIdePlatform
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
import org.jetbrains.kotlin.utils.DescriptionAware
|
||||
|
||||
@Deprecated("Use IdePlatformKind instead.", level = DeprecationLevel.ERROR)
|
||||
@@ -189,12 +190,20 @@ class KotlinFacetSettings {
|
||||
compilerArguments!!.apiVersion = value?.versionString
|
||||
}
|
||||
|
||||
val targetPlatform: TargetPlatform?
|
||||
var targetPlatform: TargetPlatform? = null
|
||||
get() {
|
||||
val compilerArguments = this.compilerArguments ?: return null
|
||||
return IdePlatformKind.platformByCompilerArguments(compilerArguments)
|
||||
// This work-around is required in order to fix importing of the proper JVM target version.
|
||||
//TODO(auskov): this hack should be removed after fixing equals in SimplePlatform
|
||||
val args = compilerArguments
|
||||
val mappedPlatforms = field?.componentPlatforms?.flatMap {
|
||||
if (JvmPlatforms.defaultJvmPlatform.first() == it && args != null) (IdePlatformKind.platformByCompilerArguments(args)
|
||||
?: return null) else listOf(it)
|
||||
}?.toSet() ?: return null
|
||||
|
||||
return TargetPlatform(mappedPlatforms)
|
||||
}
|
||||
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
@Deprecated(
|
||||
message = "This accessor is deprecated and will be removed soon, use API from 'org.jetbrains.kotlin.platform.*' packages instead",
|
||||
|
||||
@@ -25,16 +25,13 @@ import org.jdom.Element
|
||||
import org.jdom.Text
|
||||
import org.jetbrains.kotlin.cli.common.arguments.*
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.*
|
||||
import org.jetbrains.kotlin.platform.impl.FakeK2NativeCompilerArguments
|
||||
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatform
|
||||
import org.jetbrains.kotlin.platform.jvm.JdkPlatform
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatform
|
||||
import org.jetbrains.kotlin.platform.konan.KonanPlatform
|
||||
import org.jetbrains.kotlin.platform.oldFashionedDescription
|
||||
import org.jetbrains.kotlin.platform.orDefault
|
||||
import java.lang.reflect.Modifier
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.full.superclasses
|
||||
@@ -67,7 +64,7 @@ private fun readV1Config(element: Element): KotlinFacetSettings {
|
||||
val targetPlatformName = versionInfoElement?.getOptionValue("targetPlatformName")
|
||||
val languageLevel = versionInfoElement?.getOptionValue("languageLevel")
|
||||
val apiLevel = versionInfoElement?.getOptionValue("apiLevel")
|
||||
val targetPlatform = IdePlatformKind.All_PLATFORMS
|
||||
val targetPlatform = CommonPlatforms.allSimplePlatforms.union(setOf(CommonPlatforms.defaultCommonPlatform))
|
||||
.firstOrNull { it.oldFashionedDescription == targetPlatformName }
|
||||
?: JvmIdePlatformKind.defaultPlatform // FIXME(dsavvinov): choose proper default
|
||||
|
||||
@@ -115,20 +112,30 @@ private fun readV1Config(element: Element): KotlinFacetSettings {
|
||||
|
||||
this.compilerSettings = compilerSettings
|
||||
this.compilerArguments = compilerArguments
|
||||
this.targetPlatform = IdePlatformKind.platformByCompilerArguments(compilerArguments)
|
||||
}
|
||||
}
|
||||
|
||||
fun Element.getFacetPlatformByConfigurationElement(): TargetPlatform {
|
||||
val platformNames = getAttributeValue("allPlatforms")?.split('/')?.toSet()
|
||||
if (platformNames != null) {
|
||||
return TargetPlatform(CommonPlatforms.allSimplePlatforms
|
||||
.flatMap { it.componentPlatforms }
|
||||
.filter { platformNames.contains(it.serializeToString()) }
|
||||
.toSet())
|
||||
}
|
||||
// failed to read list of all platforms. Fallback to legacy algorythm
|
||||
val platformName = getAttributeValue("platform")
|
||||
return IdePlatformKind.All_PLATFORMS
|
||||
.firstOrNull { it.oldFashionedDescription == platformName }
|
||||
.orDefault()
|
||||
// this code could be simplified using union after fixing the equals method in SimplePlatform
|
||||
val allPlatforms = ArrayList(CommonPlatforms.allSimplePlatforms).also { it.add(CommonPlatforms.defaultCommonPlatform) }
|
||||
return allPlatforms.firstOrNull { it.oldFashionedDescription == platformName }.orDefault()
|
||||
}
|
||||
|
||||
private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings {
|
||||
return KotlinFacetSettings().apply {
|
||||
element.getAttributeValue("useProjectSettings")?.let { useProjectSettings = it.toBoolean() }
|
||||
val targetPlatform = element.getFacetPlatformByConfigurationElement()
|
||||
this.targetPlatform = targetPlatform
|
||||
element.getChild("implements")?.let {
|
||||
val items = it.getChildren("implement")
|
||||
implementedModuleNames = if (items.isNotEmpty()) {
|
||||
@@ -288,7 +295,7 @@ private fun KotlinFacetSettings.writeLatestConfig(element: Element) {
|
||||
val filter = SkipDefaultsSerializationFilter()
|
||||
|
||||
targetPlatform?.let {
|
||||
element.setAttribute("platform", it.oldFashionedDescription)
|
||||
element.setAttribute("allPlatforms", it.componentPlatforms.map { it.serializeToString() }.joinToString(separator = "/"))
|
||||
}
|
||||
if (!useProjectSettings) {
|
||||
element.setAttribute("useProjectSettings", useProjectSettings.toString())
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.platform
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import org.jetbrains.kotlin.extensions.ApplicationExtensionDescriptor
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.config.isJps
|
||||
@@ -14,14 +15,10 @@ import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatform
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatform
|
||||
import org.jetbrains.kotlin.platform.konan.KonanPlatform
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
|
||||
abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
|
||||
abstract val platforms: List<TargetPlatform>
|
||||
abstract fun supportsTargetPlatform(platform: TargetPlatform): Boolean
|
||||
|
||||
abstract val defaultPlatform: TargetPlatform
|
||||
|
||||
@@ -67,7 +64,6 @@ abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
|
||||
kinds
|
||||
}
|
||||
|
||||
val All_PLATFORMS by lazy { ALL_KINDS.flatMap { it.platforms } }
|
||||
|
||||
fun <Args : CommonCompilerArguments> platformByCompilerArguments(arguments: Args): TargetPlatform? =
|
||||
ALL_KINDS.firstNotNullResult { it.platformByCompilerArguments(arguments) }
|
||||
@@ -76,10 +72,10 @@ abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
|
||||
}
|
||||
|
||||
val TargetPlatform.idePlatformKind: IdePlatformKind<*>
|
||||
get() = when (val single = singleOrNull()) {
|
||||
null -> CommonIdePlatformKind
|
||||
is JvmPlatform -> JvmIdePlatformKind
|
||||
is JsPlatform -> JsIdePlatformKind
|
||||
is KonanPlatform -> NativeIdePlatformKind
|
||||
else -> error("Unknown platform $single")
|
||||
}
|
||||
get() = IdePlatformKind.ALL_KINDS.filter { it.supportsTargetPlatform(this) }.let { list ->
|
||||
when {
|
||||
list.size == 1 -> list.first()
|
||||
list.size > 1 -> list.first().also { Logger.getInstance(IdePlatformKind.javaClass).warn("Found more than one IdePlatformKind [$list] for target [$this].") }
|
||||
else -> error("Unknown platform $this")
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
|
||||
import org.jetbrains.kotlin.platform.*
|
||||
|
||||
object CommonIdePlatformKind : IdePlatformKind<CommonIdePlatformKind>() {
|
||||
override fun supportsTargetPlatform(platform: TargetPlatform) = platform.isCommon()
|
||||
|
||||
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
|
||||
return if (arguments is K2MetadataCompilerArguments)
|
||||
@@ -31,7 +32,6 @@ object CommonIdePlatformKind : IdePlatformKind<CommonIdePlatformKind>() {
|
||||
return K2MetadataCompilerArguments() // TODO(dsavvinov): review that, as now MPP !== K2Metadata
|
||||
}
|
||||
|
||||
override val platforms get() = listOf(CommonPlatforms.defaultCommonPlatform)
|
||||
override val defaultPlatform get() = CommonPlatforms.defaultCommonPlatform
|
||||
|
||||
override val argumentsClass get() = K2MetadataCompilerArguments::class.java
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.platform.TargetPlatformVersion
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
||||
|
||||
object JsIdePlatformKind : IdePlatformKind<JsIdePlatformKind>() {
|
||||
override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platforms.contains(platform)
|
||||
|
||||
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
|
||||
return if (arguments is K2JSCompilerArguments)
|
||||
@@ -25,7 +26,7 @@ object JsIdePlatformKind : IdePlatformKind<JsIdePlatformKind>() {
|
||||
null
|
||||
}
|
||||
|
||||
override val platforms get() = listOf(JsPlatforms.defaultJsPlatform)
|
||||
val platforms get() = listOf(JsPlatforms.defaultJsPlatform)
|
||||
override val defaultPlatform get() = JsPlatforms.defaultJsPlatform
|
||||
|
||||
@Deprecated(
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
|
||||
object JvmIdePlatformKind : IdePlatformKind<JvmIdePlatformKind>() {
|
||||
override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platforms.contains(platform)
|
||||
|
||||
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
|
||||
if (arguments !is K2JVMCompilerArguments) return null
|
||||
@@ -42,7 +43,7 @@ object JvmIdePlatformKind : IdePlatformKind<JvmIdePlatformKind>() {
|
||||
return K2JVMCompilerArguments()
|
||||
}
|
||||
|
||||
override val platforms: List<TargetPlatform> = JvmTarget.values().map { ver -> JvmPlatforms.jvmPlatformByTargetVersion(ver) } + listOf(JvmPlatforms.unspecifiedJvmPlatform)
|
||||
val platforms: List<TargetPlatform> = JvmTarget.values().map { ver -> JvmPlatforms.jvmPlatformByTargetVersion(ver) } + listOf(JvmPlatforms.unspecifiedJvmPlatform)
|
||||
override val defaultPlatform get() = JvmPlatforms.defaultJvmPlatform
|
||||
|
||||
override val argumentsClass get() = K2JVMCompilerArguments::class.java
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.platform.TargetPlatformVersion
|
||||
import org.jetbrains.kotlin.platform.konan.KonanPlatforms
|
||||
|
||||
object NativeIdePlatformKind : IdePlatformKind<NativeIdePlatformKind>() {
|
||||
override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platform == KonanPlatforms.defaultKonanPlatform
|
||||
|
||||
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
|
||||
return if (arguments is FakeK2NativeCompilerArguments)
|
||||
@@ -37,9 +38,6 @@ object NativeIdePlatformKind : IdePlatformKind<NativeIdePlatformKind>() {
|
||||
)
|
||||
override fun getDefaultPlatform(): IdePlatform<*, *> = Platform
|
||||
|
||||
override val platforms
|
||||
get() = listOf(KonanPlatforms.defaultKonanPlatform)
|
||||
|
||||
override val argumentsClass
|
||||
get() = FakeK2NativeCompilerArguments::class.java
|
||||
|
||||
|
||||
+2
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.config.KotlinFacetSettings
|
||||
import org.jetbrains.kotlin.incremental.testingUtils.BuildLogFinder
|
||||
import org.jetbrains.kotlin.incremental.testingUtils.BuildLogFinder.Companion.JS_JPS_LOG
|
||||
import org.jetbrains.kotlin.jps.model.JpsKotlinFacetModuleExtension
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractIncrementalJsJpsTest : AbstractIncrementalJpsTest() {
|
||||
@@ -28,6 +29,7 @@ abstract class AbstractIncrementalJsJpsTest : AbstractIncrementalJpsTest() {
|
||||
myProject.modules.forEach {
|
||||
val facet = KotlinFacetSettings()
|
||||
facet.compilerArguments = K2JSCompilerArguments()
|
||||
facet.targetPlatform = JsPlatforms.defaultJsPlatform
|
||||
|
||||
it.container.setChild(
|
||||
JpsKotlinFacetModuleExtension.KIND,
|
||||
|
||||
+12
-4
@@ -15,9 +15,13 @@ import org.jetbrains.kotlin.config.KotlinFacetSettings
|
||||
import org.jetbrains.kotlin.config.KotlinModuleKind.COMPILATION_AND_SOURCE_SET_HOLDER
|
||||
import org.jetbrains.kotlin.config.KotlinModuleKind.SOURCE_SET_HOLDER
|
||||
import org.jetbrains.kotlin.jps.build.dependeciestxt.ModulesTxt.Dependency.Kind.*
|
||||
import org.jetbrains.kotlin.platform.CommonPlatforms
|
||||
import org.jetbrains.kotlin.platform.impl.FakeK2NativeCompilerArguments
|
||||
import org.jetbrains.kotlin.platform.isCommon
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
import org.jetbrains.kotlin.platform.jvm.isJvm
|
||||
import org.jetbrains.kotlin.platform.konan.KonanPlatforms
|
||||
import java.io.File
|
||||
import kotlin.reflect.KMutableProperty1
|
||||
import kotlin.reflect.full.findAnnotation
|
||||
@@ -253,10 +257,14 @@ class ModulesTxtBuilder {
|
||||
when (flag) {
|
||||
"sourceSetHolder" -> settings.kind = SOURCE_SET_HOLDER
|
||||
"compilationAndSourceSetHolder" -> settings.kind = COMPILATION_AND_SOURCE_SET_HOLDER
|
||||
"common" -> settings.compilerArguments = K2MetadataCompilerArguments()
|
||||
"jvm" -> settings.compilerArguments = K2JVMCompilerArguments()
|
||||
"js" -> settings.compilerArguments = K2JSCompilerArguments()
|
||||
"native" -> settings.compilerArguments = FakeK2NativeCompilerArguments()
|
||||
"common" -> settings.compilerArguments =
|
||||
K2MetadataCompilerArguments().also { settings.targetPlatform = CommonPlatforms.defaultCommonPlatform }
|
||||
"jvm" -> settings.compilerArguments =
|
||||
K2JVMCompilerArguments().also { settings.targetPlatform = JvmPlatforms.defaultJvmPlatform }
|
||||
"js" -> settings.compilerArguments =
|
||||
K2JSCompilerArguments().also { settings.targetPlatform = JsPlatforms.defaultJsPlatform }
|
||||
"native" -> settings.compilerArguments =
|
||||
FakeK2NativeCompilerArguments().also { settings.targetPlatform = KonanPlatforms.defaultKonanPlatform }
|
||||
else -> {
|
||||
val flagProperty = ModulesTxt.Module.flags[flag]
|
||||
if (flagProperty != null) flagProperty.set(module, true)
|
||||
|
||||
Reference in New Issue
Block a user