[KLIB] Add flag to select between per-file and monolithic layout
This commit is contained in:
@@ -91,6 +91,7 @@ internal class K2MetadataKlibSerializer(private val metadataVersion: BuiltInsBin
|
||||
destDir.absolutePath,
|
||||
configuration[CommonConfigurationKeys.MODULE_NAME]!!,
|
||||
nopack = true,
|
||||
perFile = false,
|
||||
manifestProperties = null,
|
||||
dataFlowGraph = null,
|
||||
builtInsPlatform = BuiltInsPlatform.COMMON
|
||||
|
||||
@@ -179,7 +179,8 @@ fun generateKLib(
|
||||
moduleFragment,
|
||||
expectDescriptorToSymbol,
|
||||
icData,
|
||||
nopack
|
||||
nopack,
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
@@ -447,7 +448,8 @@ fun serializeModuleIntoKlib(
|
||||
moduleFragment: IrModuleFragment,
|
||||
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
||||
cleanFiles: List<KotlinFileSerializedData>,
|
||||
nopack: Boolean
|
||||
nopack: Boolean,
|
||||
perFile: Boolean
|
||||
) {
|
||||
assert(files.size == moduleFragment.files.size)
|
||||
|
||||
@@ -525,6 +527,7 @@ fun serializeModuleIntoKlib(
|
||||
manifestProperties = null,
|
||||
moduleName = moduleName,
|
||||
nopack = nopack,
|
||||
perFile = perFile,
|
||||
output = klibPath,
|
||||
versions = versions,
|
||||
builtInsPlatform = BuiltInsPlatform.JS
|
||||
|
||||
@@ -234,7 +234,8 @@ open class KotlinLibraryImpl(
|
||||
fun createKotlinLibrary(
|
||||
libraryFile: File,
|
||||
component: String,
|
||||
isDefault: Boolean = false
|
||||
isDefault: Boolean = false,
|
||||
perFile: Boolean = false
|
||||
): KotlinLibrary {
|
||||
val baseAccess = BaseLibraryAccess<KotlinLibraryLayout>(libraryFile, component)
|
||||
val metadataAccess = MetadataLibraryAccess<MetadataKotlinLibraryLayout>(libraryFile, component)
|
||||
@@ -242,8 +243,7 @@ fun createKotlinLibrary(
|
||||
|
||||
val base = BaseKotlinLibraryImpl(baseAccess, isDefault)
|
||||
val metadata = MetadataLibraryImpl(metadataAccess)
|
||||
val ir = IrMonoliticLibraryImpl(irAccess)
|
||||
// val ir = IrPerFileLibraryImpl(irAccess)
|
||||
val ir = if (perFile) IrPerFileLibraryImpl(irAccess) else IrMonoliticLibraryImpl(irAccess)
|
||||
|
||||
return KotlinLibraryImpl(base, metadata, ir)
|
||||
}
|
||||
|
||||
+42
-2
@@ -111,13 +111,26 @@ fun buildKotlinLibrary(
|
||||
output: String,
|
||||
moduleName: String,
|
||||
nopack: Boolean,
|
||||
perFile: Boolean,
|
||||
manifestProperties: Properties?,
|
||||
dataFlowGraph: ByteArray?,
|
||||
builtInsPlatform: BuiltInsPlatform,
|
||||
nativeTargets: List<String> = emptyList()
|
||||
): KotlinLibraryLayout {
|
||||
|
||||
val library = KotlinLibraryWriterImpl(File(output), moduleName, versions, builtInsPlatform, nativeTargets, nopack)
|
||||
val klibDirectory = File(output)
|
||||
val layout = KotlinLibraryLayoutForWriter(klibDirectory)
|
||||
val irWriter = if (perFile) IrPerFileWriterImpl(layout) else IrMonoliticWriterImpl(layout)
|
||||
val library = KotlinLibraryWriterImpl(
|
||||
klibDirectory,
|
||||
moduleName,
|
||||
versions,
|
||||
builtInsPlatform,
|
||||
nativeTargets,
|
||||
nopack,
|
||||
layout = layout,
|
||||
ir = irWriter
|
||||
)
|
||||
|
||||
library.addMetadata(metadata)
|
||||
|
||||
@@ -133,10 +146,37 @@ fun buildKotlinLibrary(
|
||||
return library.layout
|
||||
}
|
||||
|
||||
class KotlinLibraryOnlyIrWriter(output: String, moduleName: String, versions: KotlinLibraryVersioning, platform: BuiltInsPlatform, nativeTargets: List<String>, perFile: Boolean) {
|
||||
val outputDir = File(output)
|
||||
val library = createLibrary(perFile, moduleName, versions, platform, nativeTargets, outputDir)
|
||||
|
||||
private fun createLibrary(
|
||||
perFile: Boolean,
|
||||
moduleName: String,
|
||||
versions: KotlinLibraryVersioning,
|
||||
platform: BuiltInsPlatform,
|
||||
nativeTargets: List<String>,
|
||||
directory: File
|
||||
): KotlinLibraryWriterImpl {
|
||||
val layout = KotlinLibraryLayoutForWriter(directory)
|
||||
val irWriter = if (perFile) IrPerFileWriterImpl(layout) else IrMonoliticWriterImpl(layout)
|
||||
return KotlinLibraryWriterImpl(directory, moduleName, versions, platform, nativeTargets, nopack = true, layout = layout, ir = irWriter)
|
||||
}
|
||||
|
||||
fun invalidate() {
|
||||
outputDir.deleteRecursively()
|
||||
library.layout.irDir.mkdirs()
|
||||
}
|
||||
|
||||
fun writeIr(serializedIrModule: SerializedIrModule) {
|
||||
library.addIr(serializedIrModule)
|
||||
}
|
||||
}
|
||||
|
||||
enum class BuiltInsPlatform {
|
||||
JVM, JS, NATIVE, COMMON;
|
||||
|
||||
companion object {
|
||||
fun parseFromString(name: String): BuiltInsPlatform? = values().firstOrNull { it.name == name }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user