Allow depending on Native stdlib even if platforms do not match under HMPP
^KT-40102
This commit is contained in:
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.idea.configuration.getBuildSystemType
|
|||||||
import org.jetbrains.kotlin.idea.core.isInTestSourceContentKotlinAware
|
import org.jetbrains.kotlin.idea.core.isInTestSourceContentKotlinAware
|
||||||
import org.jetbrains.kotlin.idea.framework.effectiveKind
|
import org.jetbrains.kotlin.idea.framework.effectiveKind
|
||||||
import org.jetbrains.kotlin.idea.framework.platform
|
import org.jetbrains.kotlin.idea.framework.platform
|
||||||
|
import org.jetbrains.kotlin.idea.klib.AbstractKlibLibraryInfo
|
||||||
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
||||||
import org.jetbrains.kotlin.idea.project.findAnalyzerServices
|
import org.jetbrains.kotlin.idea.project.findAnalyzerServices
|
||||||
import org.jetbrains.kotlin.idea.project.getStableName
|
import org.jetbrains.kotlin.idea.project.getStableName
|
||||||
@@ -46,6 +47,7 @@ import org.jetbrains.kotlin.idea.project.isHMPPEnabled
|
|||||||
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
|
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
|
||||||
import org.jetbrains.kotlin.idea.util.isInSourceContentWithoutInjected
|
import org.jetbrains.kotlin.idea.util.isInSourceContentWithoutInjected
|
||||||
import org.jetbrains.kotlin.idea.util.rootManager
|
import org.jetbrains.kotlin.idea.util.rootManager
|
||||||
|
import org.jetbrains.kotlin.konan.library.KONAN_STDLIB_NAME
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider
|
import org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider
|
||||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||||
@@ -167,7 +169,7 @@ private fun ideaModelDependencies(
|
|||||||
debugString?.appendLine("]")
|
debugString?.appendLine("]")
|
||||||
|
|
||||||
// Some dependencies prohibited (e.g. common can not depend on a platform)
|
// Some dependencies prohibited (e.g. common can not depend on a platform)
|
||||||
val correctedResult = result.filterNot { it is LibraryInfo && !platform.canDependOn(it.platform, module.isHMPPEnabled) }
|
val correctedResult = result.filterNot { it is LibraryInfo && !platform.canDependOn(it, module.isHMPPEnabled) }
|
||||||
debugString?.appendLine(" Corrected result: ${correctedResult.joinToString(prefix = "[", postfix = "]", separator = ";") { it.displayedName }}")
|
debugString?.appendLine(" Corrected result: ${correctedResult.joinToString(prefix = "[", postfix = "]", separator = ";") { it.displayedName }}")
|
||||||
|
|
||||||
LOG.debug(debugString?.toString())
|
LOG.debug(debugString?.toString())
|
||||||
@@ -175,19 +177,22 @@ private fun ideaModelDependencies(
|
|||||||
return correctedResult
|
return correctedResult
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TargetPlatform.canDependOn(other: TargetPlatform, isHmppEnabled: Boolean): Boolean {
|
private fun TargetPlatform.canDependOn(other: IdeaModuleInfo, isHmppEnabled: Boolean): Boolean {
|
||||||
if (isHmppEnabled) {
|
if (isHmppEnabled) {
|
||||||
val platformsWhichAreNotContainedInOther = this.componentPlatforms - other.componentPlatforms
|
// HACK: allow depending on stdlib even if platforms do not match
|
||||||
|
if (isNative() && other is AbstractKlibLibraryInfo && other.libraryRoot.endsWith(KONAN_STDLIB_NAME)) return true
|
||||||
|
|
||||||
|
val platformsWhichAreNotContainedInOther = this.componentPlatforms - other.platform.componentPlatforms
|
||||||
if (platformsWhichAreNotContainedInOther.isEmpty()) return true
|
if (platformsWhichAreNotContainedInOther.isEmpty()) return true
|
||||||
|
|
||||||
// unspecifiedNativePlatform is effectively a wildcard for NativePlatform
|
// unspecifiedNativePlatform is effectively a wildcard for NativePlatform
|
||||||
return platformsWhichAreNotContainedInOther.all { it is NativePlatform } &&
|
return platformsWhichAreNotContainedInOther.all { it is NativePlatform } &&
|
||||||
NativePlatforms.unspecifiedNativePlatform.componentPlatforms.single() in other.componentPlatforms
|
NativePlatforms.unspecifiedNativePlatform.componentPlatforms.single() in other.platform.componentPlatforms
|
||||||
} else {
|
} else {
|
||||||
return this.isJvm() && other.isJvm() ||
|
return this.isJvm() && other.platform.isJvm() ||
|
||||||
this.isJs() && other.isJs() ||
|
this.isJs() && other.platform.isJs() ||
|
||||||
this.isNative() && other.isNative() ||
|
this.isNative() && other.platform.isNative() ||
|
||||||
this.isCommon() && other.isCommon()
|
this.isCommon() && other.platform.isCommon()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ class NativePlatformKindResolution : IdePlatformKindResolution {
|
|||||||
class NativeKlibLibraryInfo(project: Project, library: Library, libraryRoot: String) :
|
class NativeKlibLibraryInfo(project: Project, library: Library, libraryRoot: String) :
|
||||||
AbstractKlibLibraryInfo(project, library, libraryRoot) {
|
AbstractKlibLibraryInfo(project, library, libraryRoot) {
|
||||||
|
|
||||||
|
// If you're changing this, please take a look at ideaModelDependencies as well
|
||||||
val isStdlib: Boolean get() = libraryRoot.endsWith(KONAN_STDLIB_NAME)
|
val isStdlib: Boolean get() = libraryRoot.endsWith(KONAN_STDLIB_NAME)
|
||||||
|
|
||||||
override val capabilities: Map<ModuleDescriptor.Capability<*>, Any?>
|
override val capabilities: Map<ModuleDescriptor.Capability<*>, Any?>
|
||||||
|
|||||||
Reference in New Issue
Block a user