From 5c88b1e80a3314b254a94f92ca0ed7dd6e1ece45 Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Thu, 9 Jul 2020 12:18:32 +0700 Subject: [PATCH] Allow depending on Native stdlib even if platforms do not match under HMPP ^KT-40102 --- .../idea/caches/project/IdeaModuleInfos.kt | 21 ++++++++++++------- .../ide/konan/NativePlatformKindResolution.kt | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt index c2253181965..1d1572a6451 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt @@ -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() } } diff --git a/idea/idea-native/src/org/jetbrains/kotlin/ide/konan/NativePlatformKindResolution.kt b/idea/idea-native/src/org/jetbrains/kotlin/ide/konan/NativePlatformKindResolution.kt index 4a701566fb6..1f640cd260c 100644 --- a/idea/idea-native/src/org/jetbrains/kotlin/ide/konan/NativePlatformKindResolution.kt +++ b/idea/idea-native/src/org/jetbrains/kotlin/ide/konan/NativePlatformKindResolution.kt @@ -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, Any?>