From 00df562a2b1c80b46c64dbb68b1942215e963d43 Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Fri, 22 May 2020 16:54:52 +0300 Subject: [PATCH] Allow specific native targets to depend on unspecified native target ^KT-38769 Fixed --- .../idea/caches/project/IdeaModuleInfos.kt | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 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 d9517981214..45b081285e7 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 @@ -56,6 +56,8 @@ import org.jetbrains.kotlin.platform.isCommon import org.jetbrains.kotlin.platform.js.isJs import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.platform.jvm.isJvm +import org.jetbrains.kotlin.platform.konan.NativePlatform +import org.jetbrains.kotlin.platform.konan.NativePlatforms import org.jetbrains.kotlin.platform.konan.isNative import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices @@ -138,17 +140,6 @@ private fun ideaModelDependencies( forProduction: Boolean, platform: TargetPlatform ): List { - fun TargetPlatform.canDependOn(other: TargetPlatform): Boolean { - return if (module.isHMPPEnabled) { - other.componentPlatforms.containsAll(this.componentPlatforms) - } else { - this.isJvm() && other.isJvm() || - this.isJs() && other.isJs() || - this.isNative() && other.isNative() || - this.isCommon() && other.isCommon() - } - } - //NOTE: lib dependencies can be processed several times during recursive traversal val result = LinkedHashSet() val dependencyEnumerator = ModuleRootManager.getInstance(module).orderEntries().compileOnly().recursively().exportedOnly() @@ -161,7 +152,23 @@ private fun ideaModelDependencies( } true } - return result.filterNot { it is LibraryInfo && !platform.canDependOn(it.platform) } + return result.filterNot { it is LibraryInfo && !platform.canDependOn(it.platform, module.isHMPPEnabled) } +} + +private fun TargetPlatform.canDependOn(other: TargetPlatform, isHmppEnabled: Boolean): Boolean { + if (isHmppEnabled) { + val platformsWhichAreNotContainedInOther = this.componentPlatforms - other.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 + } else { + return this.isJvm() && other.isJvm() || + this.isJs() && other.isJs() || + this.isNative() && other.isNative() || + this.isCommon() && other.isCommon() + } } interface ModuleSourceInfo : IdeaModuleInfo, TrackableModuleInfo {