[KLIB] Introduce isJsStdlib() and isWasmStdlib() checks for KLIBs

This commit is contained in:
Dmitriy Dolovov
2023-11-10 10:13:57 +01:00
committed by Space Team
parent 4892a81178
commit d65fc00578
5 changed files with 29 additions and 11 deletions
@@ -74,7 +74,7 @@ internal class LibraryAbiReaderImpl(libraryFile: File, filters: List<AbiReadingF
private fun readManifest(): LibraryManifest {
val versions = library.versions
return LibraryManifest(
platform = library.builtInsPlatform,
platform = library.builtInsPlatform?.name,
nativeTargets = library.nativeTargets.sorted(),
compilerVersion = versions.compilerVersion,
abiVersion = versions.abiVersion?.toString(),
@@ -94,7 +94,7 @@ private class LibraryDeserializer(
supportedSignatureVersions: Set<AbiSignatureVersion>,
private val compositeFilter: AbiReadingFilter.Composite?
) {
private val platform: BuiltInsPlatform? = library.builtInsPlatform?.let(BuiltInsPlatform::parseFromString)
private val platform: BuiltInsPlatform? = library.builtInsPlatform
private val interner = IrInterningService()
@@ -15,8 +15,10 @@ import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.library.KotlinLibrary
import org.jetbrains.kotlin.library.isJsStdlib
import org.jetbrains.kotlin.library.metadata.*
import org.jetbrains.kotlin.library.isNativeStdlib
import org.jetbrains.kotlin.library.isWasmStdlib
import org.jetbrains.kotlin.name.*
import org.jetbrains.kotlin.platform.jvm.isJvm
import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration
@@ -57,7 +59,7 @@ class KlibMetadataModuleDescriptorFactoryImpl(
storageManager,
moduleDescriptor,
configuration = CompilerDeserializationConfiguration(languageVersionSettings),
compositePackageFragmentAddend = runIf(library.isNativeStdlib) {
compositePackageFragmentAddend = runIf(library.isNativeStdlib || library.isJsStdlib || library.isWasmStdlib) {
functionInterfacePackageFragmentProvider(storageManager, moduleDescriptor)
},
lookupTracker = lookupTracker
@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.library
import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.konan.properties.Properties
import org.jetbrains.kotlin.konan.properties.propertyList
import org.jetbrains.kotlin.library.impl.BuiltInsPlatform
/**
* [org.jetbrains.kotlin.library.KotlinAbiVersion]
@@ -93,15 +94,21 @@ interface IrLibrary {
fun bodies(fileIndex: Int): ByteArray
}
val BaseKotlinLibrary.isNativeStdlib: Boolean
get() = uniqueName == KOTLIN_NATIVE_STDLIB_NAME && builtInsPlatform == BuiltInsPlatform.NATIVE
val BaseKotlinLibrary.isJsStdlib: Boolean
get() = uniqueName == KOTLIN_JS_STDLIB_NAME && builtInsPlatform == BuiltInsPlatform.JS
val BaseKotlinLibrary.isWasmStdlib: Boolean
get() = uniqueName == KOTLIN_WASM_STDLIB_NAME && builtInsPlatform == BuiltInsPlatform.WASM
val BaseKotlinLibrary.uniqueName: String
get() = manifestProperties.getProperty(KLIB_PROPERTY_UNIQUE_NAME)!!
val BaseKotlinLibrary.shortName: String?
get() = manifestProperties.getProperty(KLIB_PROPERTY_SHORT_NAME)
val BaseKotlinLibrary.isNativeStdlib: Boolean
get() = uniqueName == KOTLIN_STDLIB_NAME
val BaseKotlinLibrary.unresolvedDependencies: List<RequiredUnresolvedLibrary>
get() = unresolvedDependencies(lenient = false).map { it as RequiredUnresolvedLibrary }
@@ -139,8 +146,12 @@ val KotlinLibrary.containsErrorCode: Boolean
val KotlinLibrary.commonizerTarget: String?
get() = manifestProperties.getProperty(KLIB_PROPERTY_COMMONIZER_TARGET)
@Deprecated("Use BaseKotlinLibrary.builtInsPlatform instead", level = DeprecationLevel.HIDDEN)
val KotlinLibrary.builtInsPlatform: String?
get() = manifestProperties.getProperty(KLIB_PROPERTY_BUILTINS_PLATFORM)
get() = builtInsPlatform?.name
val BaseKotlinLibrary.builtInsPlatform: BuiltInsPlatform?
get() = manifestProperties.getProperty(KLIB_PROPERTY_BUILTINS_PLATFORM)?.let(BuiltInsPlatform::parseFromString)
val BaseKotlinLibrary.commonizerNativeTargets: List<String>?
get() = if (manifestProperties.containsKey(KLIB_PROPERTY_COMMONIZER_NATIVE_TARGETS))
@@ -10,7 +10,12 @@ import org.jetbrains.kotlin.util.suffixIfNot
import java.nio.file.InvalidPathException
import java.nio.file.Paths
const val KOTLIN_STDLIB_NAME = "stdlib"
@Deprecated("Use KOTLIN_NATIVE_STDLIB_NAME, KOTLIN_JS_STDLIB_NAME or KOTLIN_WASM_STDLIB_NAME instead", level = DeprecationLevel.HIDDEN)
const val KOTLIN_STDLIB_NAME: String = "stdlib"
const val KOTLIN_NATIVE_STDLIB_NAME: String = "stdlib"
const val KOTLIN_JS_STDLIB_NAME: String = "kotlin"
const val KOTLIN_WASM_STDLIB_NAME: String = "kotlin"
interface SearchPathResolver<L : KotlinLibrary> : WithLogger {
val searchRoots: List<File>
@@ -187,7 +192,7 @@ abstract class KotlinLibrarySearchPathResolver<L : KotlinLibrary>(
.asSequence()
.filter { it.name.startsWith(prefix) }
.filterNot { it.name.startsWith('.') }
.filterNot { it.name.removeSuffixIfPresent(KLIB_FILE_EXTENSION_WITH_DOT) == KOTLIN_STDLIB_NAME }
.filterNot { it.name.removeSuffixIfPresent(KLIB_FILE_EXTENSION_WITH_DOT) == KOTLIN_NATIVE_STDLIB_NAME }
.map { UnresolvedLibrary(it.absolutePath, null) }
.map { resolve(it, isDefaultLink = true) }
} else emptySequence()
@@ -197,7 +202,7 @@ abstract class KotlinLibrarySearchPathResolver<L : KotlinLibrary>(
val result = mutableListOf<L>()
if (!noStdLib) {
result.add(resolve(UnresolvedLibrary(KOTLIN_STDLIB_NAME, null), true))
result.add(resolve(UnresolvedLibrary(KOTLIN_NATIVE_STDLIB_NAME, null), true))
}
// Endorsed libraries in distHead.
@@ -77,7 +77,7 @@ internal fun IdeaKotlinBinaryAttributes(attributes: AttributeContainer): IdeaKot
internal fun KlibExtra(library: KotlinLibrary): KlibExtra {
return KlibExtra(
builtInsPlatform = library.builtInsPlatform,
builtInsPlatform = library.builtInsPlatform?.name,
uniqueName = library.uniqueName,
shortName = library.shortName,
packageFqName = library.packageFqName,