Consider platform compatibility in library usage index
Logic of module dependencies is enhanced to filter out incompatible common -> platform dependencies. However the reversed index for getting all modules that use libraries doesn't take this filtering into account and returns all modules based exclusively on order entries. This leads to incorrect library dependency calculation. ^KT-44638 Verification pending
This commit is contained in:
@@ -173,7 +173,7 @@ private fun ideaModelDependencies(
|
||||
return correctedResult
|
||||
}
|
||||
|
||||
private fun TargetPlatform.canDependOn(other: IdeaModuleInfo, isHmppEnabled: Boolean): Boolean {
|
||||
internal fun TargetPlatform.canDependOn(other: IdeaModuleInfo, isHmppEnabled: Boolean): Boolean {
|
||||
if (isHmppEnabled) {
|
||||
// HACK: allow depending on stdlib even if platforms do not match
|
||||
if (isNative() && other is AbstractKlibLibraryInfo && other.libraryRoot.endsWith(KONAN_STDLIB_NAME)) return true
|
||||
|
||||
+13
-2
@@ -19,6 +19,7 @@ import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.util.containers.MultiMap
|
||||
import org.jetbrains.kotlin.idea.core.util.CachedValue
|
||||
import org.jetbrains.kotlin.idea.core.util.getValue
|
||||
import org.jetbrains.kotlin.idea.project.isHMPPEnabled
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.isCommon
|
||||
import java.util.*
|
||||
@@ -62,7 +63,7 @@ class LibraryDependenciesCacheImpl(private val project: Project) : LibraryDepend
|
||||
|
||||
val platform = libraryInfo.platform
|
||||
|
||||
for (module in getLibraryUsageIndex().modulesLibraryIsUsedIn[libraryInfo.library]) {
|
||||
for (module in getLibraryUsageIndex().getModulesLibraryIsUsedIn(libraryInfo)) {
|
||||
if (!processedModules.add(module)) continue
|
||||
|
||||
ModuleRootManager.getInstance(module).orderEntries().recursively().satisfying(condition).process(object : RootPolicy<Unit>() {
|
||||
@@ -109,7 +110,7 @@ class LibraryDependenciesCacheImpl(private val project: Project) : LibraryDepend
|
||||
}
|
||||
|
||||
private inner class LibraryUsageIndex {
|
||||
val modulesLibraryIsUsedIn: MultiMap<Library, Module> = MultiMap.createSet()
|
||||
private val modulesLibraryIsUsedIn: MultiMap<Library, Module> = MultiMap.createSet()
|
||||
|
||||
init {
|
||||
for (module in ModuleManager.getInstance(project).modules) {
|
||||
@@ -123,5 +124,15 @@ class LibraryDependenciesCacheImpl(private val project: Project) : LibraryDepend
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getModulesLibraryIsUsedIn(libraryInfo: LibraryInfo) = sequence<Module> {
|
||||
val ideaModelInfosCache = getIdeaModelInfosCache(project)
|
||||
for (module in modulesLibraryIsUsedIn[libraryInfo.library]) {
|
||||
val mappedModuleInfos = ideaModelInfosCache.getModuleInfosForModule(module)
|
||||
if (mappedModuleInfos.any { it.platform.canDependOn(libraryInfo, module.isHMPPEnabled) }) {
|
||||
yield(module)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user