[KLIB] Fix issues between directory and .klib modes
- use .klib extension explicitly - fix issue with `module.klib.klib` names
This commit is contained in:
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumer
|
||||
import org.jetbrains.kotlin.ir.backend.js.*
|
||||
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
|
||||
import org.jetbrains.kotlin.js.config.*
|
||||
import org.jetbrains.kotlin.library.KLIB_FILE_EXTENSION
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
@@ -187,11 +188,9 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
}
|
||||
|
||||
if (arguments.irProduceKlibDir || arguments.irProduceKlibFile) {
|
||||
val outputKlibPath =
|
||||
if (arguments.irProduceKlibDir)
|
||||
File(outputFilePath).parent
|
||||
else
|
||||
outputFilePath
|
||||
if (arguments.irProduceKlibFile) {
|
||||
require(outputFile.extension == KLIB_FILE_EXTENSION) { "Please set up .klib file as output" }
|
||||
}
|
||||
|
||||
try {
|
||||
generateKLib(
|
||||
@@ -202,7 +201,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
allDependencies = resolvedLibraries,
|
||||
friendDependencies = friendDependencies,
|
||||
irFactory = PersistentIrFactory,
|
||||
outputKlibPath = outputKlibPath,
|
||||
outputKlibPath = outputFile.path,
|
||||
nopack = arguments.irProduceKlibDir
|
||||
)
|
||||
} catch (e: JsIrCompilationError) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.konan.util.KlibMetadataFactories
|
||||
import org.jetbrains.kotlin.library.*
|
||||
import org.jetbrains.kotlin.library.impl.BuiltInsPlatform
|
||||
import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutForWriter
|
||||
import org.jetbrains.kotlin.library.impl.KotlinLibraryWriterImpl
|
||||
import org.jetbrains.kotlin.library.metadata.NativeTypeTransformer
|
||||
import org.jetbrains.kotlin.library.metadata.NullFlexibleTypeDeserializer
|
||||
@@ -78,8 +79,10 @@ object KlibTestUtil {
|
||||
|
||||
val serializedMetadata = serializer.serializeModule(module)
|
||||
|
||||
val unzippedDir = org.jetbrains.kotlin.konan.file.createTempDir(libraryName)
|
||||
val layout = KotlinLibraryLayoutForWriter(KFile(klibFile.path), unzippedDir)
|
||||
|
||||
val library = KotlinLibraryWriterImpl(
|
||||
libDir = KFile(klibFile.path.removeSuffix(KLIB_FILE_EXTENSION_WITH_DOT)),
|
||||
moduleName = libraryName,
|
||||
versions = KotlinLibraryVersioning(
|
||||
libraryVersion = null,
|
||||
@@ -91,7 +94,8 @@ object KlibTestUtil {
|
||||
builtInsPlatform = BuiltInsPlatform.COMMON,
|
||||
nativeTargets = emptyList(),
|
||||
nopack = false,
|
||||
shortName = libraryName
|
||||
shortName = libraryName,
|
||||
layout = layout
|
||||
)
|
||||
|
||||
library.addMetadata(serializedMetadata)
|
||||
|
||||
@@ -26,18 +26,18 @@ const val KLIB_IR_FOLDER_NAME = "ir"
|
||||
* This scheme describes the Kotlin/Native Library (KLIB) layout.
|
||||
*/
|
||||
interface KotlinLibraryLayout {
|
||||
val libDir: File
|
||||
val libFile: File
|
||||
val libraryName: String
|
||||
get() = libDir.path
|
||||
get() = libFile.path
|
||||
val component: String?
|
||||
val componentDir: File
|
||||
get() = File(libDir, component!!)
|
||||
get() = File(libFile, component!!)
|
||||
val manifestFile
|
||||
get() = File(componentDir, KLIB_MANIFEST_FILE_NAME)
|
||||
val resourcesDir
|
||||
get() = File(componentDir, "resources")
|
||||
val pre_1_4_manifest: File
|
||||
get() = File(libDir, KLIB_MANIFEST_FILE_NAME)
|
||||
get() = File(libFile, KLIB_MANIFEST_FILE_NAME)
|
||||
}
|
||||
|
||||
interface MetadataKotlinLibraryLayout : KotlinLibraryLayout {
|
||||
|
||||
@@ -30,7 +30,7 @@ open class BaseKotlinLibraryImpl(
|
||||
|
||||
private val componentListAndHasPre14Manifest by lazy {
|
||||
access.inPlace { layout ->
|
||||
val listFiles = layout.libDir.listFiles
|
||||
val listFiles = layout.libFile.listFiles
|
||||
listFiles
|
||||
.filter { it.isDirectory }
|
||||
.filter { it.listFiles.map { it.name }.contains(KLIB_MANIFEST_FILE_NAME) }
|
||||
|
||||
@@ -14,14 +14,14 @@ open class KotlinLibraryLayoutImpl(val klib: File, override val component: Strin
|
||||
if (isZipped) zippedKotlinLibraryChecks(klib)
|
||||
}
|
||||
|
||||
override val libDir = if (isZipped) File("/") else klib
|
||||
override val libFile = if (isZipped) File("/") else klib
|
||||
|
||||
override val libraryName
|
||||
get() =
|
||||
if (isZipped)
|
||||
klib.path.removeSuffixIfPresent(KLIB_FILE_EXTENSION_WITH_DOT)
|
||||
else
|
||||
libDir.path
|
||||
libFile.path
|
||||
|
||||
open val extractingToTemp: KotlinLibraryLayout by lazy {
|
||||
ExtractingBaseLibraryImpl(this)
|
||||
@@ -84,7 +84,7 @@ open class FromZipBaseLibraryImpl(zipped: KotlinLibraryLayoutImpl, zipFileSystem
|
||||
KotlinLibraryLayout {
|
||||
|
||||
override val libraryName = zipped.libraryName
|
||||
override val libDir = zipFileSystem.file(zipped.libDir)
|
||||
override val libFile = zipFileSystem.file(zipped.libFile)
|
||||
override val component = zipped.component
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ fun KotlinLibraryLayoutImpl.extractDir(directory: File): File = this.klib.withZi
|
||||
}
|
||||
|
||||
open class ExtractingKotlinLibraryLayout(zipped: KotlinLibraryLayoutImpl) : KotlinLibraryLayout {
|
||||
override val libDir: File get() = error("Extracting layout doesn't extract its own root")
|
||||
override val libFile: File get() = error("Extracting layout doesn't extract its own root")
|
||||
override val libraryName = zipped.libraryName
|
||||
override val component = zipped.component
|
||||
}
|
||||
|
||||
+15
-16
@@ -14,9 +14,13 @@ import org.jetbrains.kotlin.library.*
|
||||
const val KLIB_DEFAULT_COMPONENT_NAME = "default"
|
||||
|
||||
open class KotlinLibraryLayoutForWriter(
|
||||
override val libDir: File,
|
||||
override val libFile: File,
|
||||
val unzippedDir: File,
|
||||
override val component: String = KLIB_DEFAULT_COMPONENT_NAME
|
||||
) : KotlinLibraryLayout, MetadataKotlinLibraryLayout, IrKotlinLibraryLayout
|
||||
) : KotlinLibraryLayout, MetadataKotlinLibraryLayout, IrKotlinLibraryLayout {
|
||||
override val componentDir: File
|
||||
get() = File(unzippedDir, component)
|
||||
}
|
||||
|
||||
open class BaseWriterImpl(
|
||||
val libraryLayout: KotlinLibraryLayoutForWriter,
|
||||
@@ -28,14 +32,12 @@ open class BaseWriterImpl(
|
||||
val shortName: String? = null
|
||||
) : BaseWriter {
|
||||
|
||||
val klibFile = File("${libraryLayout.libDir.path}.$KLIB_FILE_EXTENSION")
|
||||
val klibFile = libraryLayout.libFile
|
||||
val manifestProperties = Properties()
|
||||
|
||||
init {
|
||||
// TODO: figure out the proper policy here.
|
||||
libraryLayout.libDir.deleteRecursively()
|
||||
klibFile.delete()
|
||||
libraryLayout.libDir.mkdirs()
|
||||
libraryLayout.resourcesDir.mkdirs()
|
||||
// TODO: <name>:<hash> will go somewhere around here.
|
||||
manifestProperties.setProperty(KLIB_PROPERTY_UNIQUE_NAME, moduleName)
|
||||
@@ -76,8 +78,8 @@ open class BaseWriterImpl(
|
||||
override fun commit() {
|
||||
manifestProperties.saveToFile(libraryLayout.manifestFile)
|
||||
if (!nopack) {
|
||||
libraryLayout.libDir.zipDirAs(klibFile)
|
||||
libraryLayout.libDir.deleteRecursively()
|
||||
libraryLayout.unzippedDir.zipDirAs(klibFile)
|
||||
libraryLayout.unzippedDir.deleteRecursively()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,16 +88,13 @@ open class BaseWriterImpl(
|
||||
* Requires non-null [target].
|
||||
*/
|
||||
class KotlinLibraryWriterImpl(
|
||||
libDir: File,
|
||||
moduleName: String,
|
||||
versions: KotlinLibraryVersioning,
|
||||
builtInsPlatform: BuiltInsPlatform,
|
||||
nativeTargets: List<String>,
|
||||
nopack: Boolean = false,
|
||||
shortName: String? = null,
|
||||
|
||||
val layout: KotlinLibraryLayoutForWriter = KotlinLibraryLayoutForWriter(libDir),
|
||||
|
||||
val layout: KotlinLibraryLayoutForWriter,
|
||||
val base: BaseWriter = BaseWriterImpl(layout, moduleName, versions, builtInsPlatform, nativeTargets, nopack, shortName),
|
||||
metadata: MetadataWriter = MetadataWriterImpl(layout),
|
||||
ir: IrWriter = IrMonoliticWriterImpl(layout)
|
||||
@@ -118,11 +117,11 @@ fun buildKotlinLibrary(
|
||||
nativeTargets: List<String> = emptyList()
|
||||
): KotlinLibraryLayout {
|
||||
|
||||
val klibDirectory = File(output)
|
||||
val layout = KotlinLibraryLayoutForWriter(klibDirectory)
|
||||
val klibFile = File(output)
|
||||
val unzippedKlibDir = if (nopack) klibFile.also { it.isDirectory } else org.jetbrains.kotlin.konan.file.createTempDir(moduleName)
|
||||
val layout = KotlinLibraryLayoutForWriter(klibFile, unzippedKlibDir)
|
||||
val irWriter = if (perFile) IrPerFileWriterImpl(layout) else IrMonoliticWriterImpl(layout)
|
||||
val library = KotlinLibraryWriterImpl(
|
||||
klibDirectory,
|
||||
moduleName,
|
||||
versions,
|
||||
builtInsPlatform,
|
||||
@@ -158,9 +157,9 @@ class KotlinLibraryOnlyIrWriter(output: String, moduleName: String, versions: Ko
|
||||
nativeTargets: List<String>,
|
||||
directory: File
|
||||
): KotlinLibraryWriterImpl {
|
||||
val layout = KotlinLibraryLayoutForWriter(directory)
|
||||
val layout = KotlinLibraryLayoutForWriter(directory, directory)
|
||||
val irWriter = if (perFile) IrPerFileWriterImpl(layout) else IrMonoliticWriterImpl(layout)
|
||||
return KotlinLibraryWriterImpl(directory, moduleName, versions, platform, nativeTargets, nopack = true, layout = layout, ir = irWriter)
|
||||
return KotlinLibraryWriterImpl(moduleName, versions, platform, nativeTargets, nopack = true, layout = layout, ir = irWriter)
|
||||
}
|
||||
|
||||
fun invalidate() {
|
||||
|
||||
Reference in New Issue
Block a user