Detect platform only for stdlib and use only roots for detection (KT-30442)
#KT-30442 Fixed
This commit is contained in:
+21
-23
@@ -50,13 +50,11 @@ class KotlinNonJvmSourceRootConverterProvider : ConverterProvider("kotlin-non-jv
|
||||
JavaResourceRootType.TEST_RESOURCE
|
||||
)
|
||||
|
||||
private val TargetPlatform.stdlibDetector: ((Array<VirtualFile>) -> Boolean)?
|
||||
get() = when (this) {
|
||||
is JvmPlatform -> { roots -> JavaRuntimeDetectionUtil.getRuntimeJar(roots.toList()) != null }
|
||||
is JsPlatform -> { roots -> JsLibraryStdDetectionUtil.getJsStdLibJar(roots.toList()) != null }
|
||||
is CommonPlatform -> { roots -> getLibraryJar(roots, PathUtil.KOTLIN_STDLIB_COMMON_JAR_PATTERN) != null }
|
||||
else -> null
|
||||
}
|
||||
private val PLATFORM_TO_STDLIB_DETECTORS: Map<TargetPlatform, (Array<VirtualFile>) -> Boolean> = mapOf(
|
||||
JvmPlatform to { roots: Array<VirtualFile> -> JavaRuntimeDetectionUtil.getRuntimeJar(roots.toList()) != null },
|
||||
JsPlatform to { roots: Array<VirtualFile> -> JsLibraryStdDetectionUtil.getJsStdLibJar(roots.toList()) != null },
|
||||
CommonPlatform to { roots: Array<VirtualFile> -> getLibraryJar(roots, PathUtil.KOTLIN_STDLIB_COMMON_JAR_PATTERN) != null }
|
||||
)
|
||||
}
|
||||
|
||||
sealed class LibInfo {
|
||||
@@ -88,14 +86,16 @@ class KotlinNonJvmSourceRootConverterProvider : ConverterProvider("kotlin-non-jv
|
||||
abstract val explicitKind: PersistentLibraryKind<*>?
|
||||
abstract fun getRoots(): Array<VirtualFile>
|
||||
|
||||
val platform by lazy {
|
||||
val explicitKind = explicitKind
|
||||
val kind = if (explicitKind is KotlinLibraryKind) explicitKind else detectLibraryKind(getRoots())
|
||||
kind?.platform ?: JvmPlatform
|
||||
}
|
||||
val stdlibPlatform: TargetPlatform? by lazy {
|
||||
val roots = getRoots()
|
||||
for ((platform, detector) in PLATFORM_TO_STDLIB_DETECTORS) {
|
||||
if (detector.invoke(roots)) {
|
||||
return@lazy platform
|
||||
}
|
||||
}
|
||||
|
||||
val isStdlib: Boolean
|
||||
get() = platform.stdlibDetector?.invoke(getRoots()) ?: false
|
||||
return@lazy null
|
||||
}
|
||||
}
|
||||
|
||||
class ConverterImpl(private val context: ConversionContext) : ProjectConverter() {
|
||||
@@ -144,15 +144,12 @@ class KotlinNonJvmSourceRootConverterProvider : ConverterProvider("kotlin-non-jv
|
||||
.asSequence()
|
||||
.mapNotNull { createLibInfo(it, this) }
|
||||
.forEach {
|
||||
when (val platform = it.platform) {
|
||||
is CommonPlatform -> {
|
||||
if (!hasCommonStdlib && it.isStdlib) {
|
||||
hasCommonStdlib = true
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
if (it.isStdlib) return platform
|
||||
val stdlibPlatform = it.stdlibPlatform
|
||||
if (stdlibPlatform != null) {
|
||||
if (stdlibPlatform == CommonPlatform) {
|
||||
hasCommonStdlib = true
|
||||
} else {
|
||||
return stdlibPlatform
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,6 +170,7 @@ class KotlinNonJvmSourceRootConverterProvider : ConverterProvider("kotlin-non-jv
|
||||
.flatMap { it.getChildren(SourceFolderImpl.ELEMENT_NAME) }
|
||||
}
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
private fun ModuleSettings.isExternalModule(): Boolean {
|
||||
return when {
|
||||
rootElement.getAttributeValue(ExternalProjectSystemRegistry.EXTERNAL_SYSTEM_ID_KEY) != null -> true
|
||||
|
||||
Reference in New Issue
Block a user