[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,
|
destDir.absolutePath,
|
||||||
configuration[CommonConfigurationKeys.MODULE_NAME]!!,
|
configuration[CommonConfigurationKeys.MODULE_NAME]!!,
|
||||||
nopack = true,
|
nopack = true,
|
||||||
|
perFile = false,
|
||||||
manifestProperties = null,
|
manifestProperties = null,
|
||||||
dataFlowGraph = null,
|
dataFlowGraph = null,
|
||||||
builtInsPlatform = BuiltInsPlatform.COMMON
|
builtInsPlatform = BuiltInsPlatform.COMMON
|
||||||
|
|||||||
@@ -179,7 +179,8 @@ fun generateKLib(
|
|||||||
moduleFragment,
|
moduleFragment,
|
||||||
expectDescriptorToSymbol,
|
expectDescriptorToSymbol,
|
||||||
icData,
|
icData,
|
||||||
nopack
|
nopack,
|
||||||
|
false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,7 +448,8 @@ fun serializeModuleIntoKlib(
|
|||||||
moduleFragment: IrModuleFragment,
|
moduleFragment: IrModuleFragment,
|
||||||
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
||||||
cleanFiles: List<KotlinFileSerializedData>,
|
cleanFiles: List<KotlinFileSerializedData>,
|
||||||
nopack: Boolean
|
nopack: Boolean,
|
||||||
|
perFile: Boolean
|
||||||
) {
|
) {
|
||||||
assert(files.size == moduleFragment.files.size)
|
assert(files.size == moduleFragment.files.size)
|
||||||
|
|
||||||
@@ -525,6 +527,7 @@ fun serializeModuleIntoKlib(
|
|||||||
manifestProperties = null,
|
manifestProperties = null,
|
||||||
moduleName = moduleName,
|
moduleName = moduleName,
|
||||||
nopack = nopack,
|
nopack = nopack,
|
||||||
|
perFile = perFile,
|
||||||
output = klibPath,
|
output = klibPath,
|
||||||
versions = versions,
|
versions = versions,
|
||||||
builtInsPlatform = BuiltInsPlatform.JS
|
builtInsPlatform = BuiltInsPlatform.JS
|
||||||
|
|||||||
@@ -234,7 +234,8 @@ open class KotlinLibraryImpl(
|
|||||||
fun createKotlinLibrary(
|
fun createKotlinLibrary(
|
||||||
libraryFile: File,
|
libraryFile: File,
|
||||||
component: String,
|
component: String,
|
||||||
isDefault: Boolean = false
|
isDefault: Boolean = false,
|
||||||
|
perFile: Boolean = false
|
||||||
): KotlinLibrary {
|
): KotlinLibrary {
|
||||||
val baseAccess = BaseLibraryAccess<KotlinLibraryLayout>(libraryFile, component)
|
val baseAccess = BaseLibraryAccess<KotlinLibraryLayout>(libraryFile, component)
|
||||||
val metadataAccess = MetadataLibraryAccess<MetadataKotlinLibraryLayout>(libraryFile, component)
|
val metadataAccess = MetadataLibraryAccess<MetadataKotlinLibraryLayout>(libraryFile, component)
|
||||||
@@ -242,8 +243,7 @@ fun createKotlinLibrary(
|
|||||||
|
|
||||||
val base = BaseKotlinLibraryImpl(baseAccess, isDefault)
|
val base = BaseKotlinLibraryImpl(baseAccess, isDefault)
|
||||||
val metadata = MetadataLibraryImpl(metadataAccess)
|
val metadata = MetadataLibraryImpl(metadataAccess)
|
||||||
val ir = IrMonoliticLibraryImpl(irAccess)
|
val ir = if (perFile) IrPerFileLibraryImpl(irAccess) else IrMonoliticLibraryImpl(irAccess)
|
||||||
// val ir = IrPerFileLibraryImpl(irAccess)
|
|
||||||
|
|
||||||
return KotlinLibraryImpl(base, metadata, ir)
|
return KotlinLibraryImpl(base, metadata, ir)
|
||||||
}
|
}
|
||||||
|
|||||||
+42
-2
@@ -111,13 +111,26 @@ fun buildKotlinLibrary(
|
|||||||
output: String,
|
output: String,
|
||||||
moduleName: String,
|
moduleName: String,
|
||||||
nopack: Boolean,
|
nopack: Boolean,
|
||||||
|
perFile: Boolean,
|
||||||
manifestProperties: Properties?,
|
manifestProperties: Properties?,
|
||||||
dataFlowGraph: ByteArray?,
|
dataFlowGraph: ByteArray?,
|
||||||
builtInsPlatform: BuiltInsPlatform,
|
builtInsPlatform: BuiltInsPlatform,
|
||||||
nativeTargets: List<String> = emptyList()
|
nativeTargets: List<String> = emptyList()
|
||||||
): KotlinLibraryLayout {
|
): 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)
|
library.addMetadata(metadata)
|
||||||
|
|
||||||
@@ -133,10 +146,37 @@ fun buildKotlinLibrary(
|
|||||||
return library.layout
|
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 {
|
enum class BuiltInsPlatform {
|
||||||
JVM, JS, NATIVE, COMMON;
|
JVM, JS, NATIVE, COMMON;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun parseFromString(name: String): BuiltInsPlatform? = values().firstOrNull { it.name == name }
|
fun parseFromString(name: String): BuiltInsPlatform? = values().firstOrNull { it.name == name }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user