Allow depending on Native stdlib even if platforms do not match under HMPP

^KT-40102
This commit is contained in:
Dmitry Savvinov
2020-07-09 12:18:32 +07:00
parent 21026001db
commit 5c88b1e80a
2 changed files with 14 additions and 8 deletions
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.idea.configuration.getBuildSystemType
import org.jetbrains.kotlin.idea.core.isInTestSourceContentKotlinAware
import org.jetbrains.kotlin.idea.framework.effectiveKind
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.findAnalyzerServices
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.util.isInSourceContentWithoutInjected
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.platform.DefaultIdeTargetPlatformKindProvider
import org.jetbrains.kotlin.platform.TargetPlatform
@@ -167,7 +169,7 @@ private fun ideaModelDependencies(
debugString?.appendLine("]")
// 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 }}")
LOG.debug(debugString?.toString())
@@ -175,19 +177,22 @@ private fun ideaModelDependencies(
return correctedResult
}
private fun TargetPlatform.canDependOn(other: TargetPlatform, isHmppEnabled: Boolean): Boolean {
private fun TargetPlatform.canDependOn(other: IdeaModuleInfo, isHmppEnabled: Boolean): Boolean {
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
// unspecifiedNativePlatform is effectively a wildcard for NativePlatform
return platformsWhichAreNotContainedInOther.all { it is NativePlatform } &&
NativePlatforms.unspecifiedNativePlatform.componentPlatforms.single() in other.componentPlatforms
NativePlatforms.unspecifiedNativePlatform.componentPlatforms.single() in other.platform.componentPlatforms
} else {
return this.isJvm() && other.isJvm() ||
this.isJs() && other.isJs() ||
this.isNative() && other.isNative() ||
this.isCommon() && other.isCommon()
return this.isJvm() && other.platform.isJvm() ||
this.isJs() && other.platform.isJs() ||
this.isNative() && other.platform.isNative() ||
this.isCommon() && other.platform.isCommon()
}
}
@@ -153,6 +153,7 @@ class NativePlatformKindResolution : IdePlatformKindResolution {
class NativeKlibLibraryInfo(project: Project, library: Library, libraryRoot: String) :
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)
override val capabilities: Map<ModuleDescriptor.Capability<*>, Any?>