Use "tooling" KLIB resolve strategy in IDE and commonizer
Issue #KT-36213
This commit is contained in:
@@ -86,18 +86,24 @@ internal val VirtualFile.isKonanLibraryRoot: Boolean
|
||||
val extension = extension
|
||||
if (!extension.isNullOrEmpty() && extension != KLIB_FILE_EXTENSION) return false
|
||||
|
||||
val manifestFile = findChild(KLIB_MANIFEST_FILE_NAME)?.takeIf { !it.isDirectory } ?: return false
|
||||
fun checkComponent(componentFile: VirtualFile): Boolean {
|
||||
val manifestFile = componentFile.findChild(KLIB_MANIFEST_FILE_NAME)?.takeIf { !it.isDirectory } ?: return false
|
||||
|
||||
// this is a hacky way to determine whether this is a Kotlin/Native .klib or common .klib (common .klibs don't have ir)
|
||||
// TODO(dsavvinov): introduce more robust way to detect library platform
|
||||
val irFolder = findChild(KLIB_IR_FOLDER_NAME)
|
||||
if (irFolder == null || irFolder.children.isEmpty()) return false
|
||||
// this is a hacky way to determine whether this is a Kotlin/Native .klib or common .klib (common .klibs don't have ir)
|
||||
// TODO(dsavvinov): introduce more robust way to detect library platform
|
||||
val irFolder = componentFile.findChild(KLIB_IR_FOLDER_NAME)
|
||||
if (irFolder == null || irFolder.children.isEmpty()) return false
|
||||
|
||||
val manifestProperties = try {
|
||||
manifestFile.inputStream.use { Properties().apply { load(it) } }
|
||||
} catch (_: IOException) {
|
||||
return false
|
||||
val manifestProperties = try {
|
||||
manifestFile.inputStream.use { Properties().apply { load(it) } }
|
||||
} catch (_: IOException) {
|
||||
return false
|
||||
}
|
||||
|
||||
return manifestProperties.containsKey(KLIB_PROPERTY_UNIQUE_NAME)
|
||||
}
|
||||
|
||||
return manifestProperties.containsKey(KLIB_PROPERTY_UNIQUE_NAME)
|
||||
// run check for library root too
|
||||
// this is necessary to recognize old style KLIBs that do not have components, and report tem to user appropriately
|
||||
return checkComponent(this) || children?.any(::checkComponent) == true
|
||||
}
|
||||
|
||||
+11
-3
@@ -38,11 +38,12 @@ import org.jetbrains.kotlin.idea.caches.project.SdkInfo
|
||||
import org.jetbrains.kotlin.idea.caches.project.lazyClosure
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.BuiltInsCacheKey
|
||||
import org.jetbrains.kotlin.idea.compiler.IDELanguageSettingsProvider
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.idea.util.IJLoggerAdapter
|
||||
import org.jetbrains.kotlin.konan.file.File as KFile
|
||||
import org.jetbrains.kotlin.konan.library.KONAN_STDLIB_NAME
|
||||
import org.jetbrains.kotlin.konan.util.KlibMetadataFactories
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.impl.createKotlinLibrary
|
||||
import org.jetbrains.kotlin.library.ToolingSingleFileKlibResolveStrategy
|
||||
import org.jetbrains.kotlin.library.isInterop
|
||||
import org.jetbrains.kotlin.library.resolveSingleFileKlib
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
@@ -192,9 +193,14 @@ class NativeLibraryInfo(project: Project, library: Library, val libraryRoot: Str
|
||||
}
|
||||
}
|
||||
|
||||
private val nativeLibrary = resolveSingleFileKlib(File(libraryRoot))
|
||||
private val nativeLibrary = resolveSingleFileKlib(
|
||||
libraryFile = KFile(libraryRoot),
|
||||
logger = LOG,
|
||||
strategy = ToolingSingleFileKlibResolveStrategy
|
||||
)
|
||||
|
||||
val isStdlib get() = libraryRoot.endsWith(KONAN_STDLIB_NAME)
|
||||
|
||||
val metadataInfo by lazy {
|
||||
val metadataVersion = nativeLibrary.safeMetadataVersion
|
||||
when {
|
||||
@@ -221,6 +227,8 @@ class NativeLibraryInfo(project: Project, library: Library, val libraryRoot: Str
|
||||
override fun toString() = "Native" + super.toString()
|
||||
|
||||
companion object {
|
||||
private val LOG = IJLoggerAdapter.getInstance(NativeLibraryInfo::class.java)
|
||||
|
||||
val NATIVE_LIBRARY_CAPABILITY = ModuleDescriptor.Capability<KotlinLibrary>("KotlinNativeLibrary")
|
||||
|
||||
internal val KotlinLibrary.safeMetadataVersion get() = this.readSafe(null) { metadataVersion }
|
||||
|
||||
Reference in New Issue
Block a user