[KLIB] Compute relative path instead of absolute if relative base is provided
- normalize path if required - path it in JS/Native - path null for JVM (temporary) - fix build
This commit is contained in:
+30
-2
@@ -29,6 +29,8 @@ import org.jetbrains.kotlin.library.impl.IrMemoryDeclarationWriter
|
|||||||
import org.jetbrains.kotlin.library.impl.IrMemoryStringWriter
|
import org.jetbrains.kotlin.library.impl.IrMemoryStringWriter
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.file.Path
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.proto.AccessorIdSignature as ProtoAccessorIdSignature
|
import org.jetbrains.kotlin.backend.common.serialization.proto.AccessorIdSignature as ProtoAccessorIdSignature
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.proto.Actual as ProtoActual
|
import org.jetbrains.kotlin.backend.common.serialization.proto.Actual as ProtoActual
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.proto.CommonIdSignature as ProtoCommonIdSignature
|
import org.jetbrains.kotlin.backend.common.serialization.proto.CommonIdSignature as ProtoCommonIdSignature
|
||||||
@@ -127,7 +129,9 @@ open class IrFileSerializer(
|
|||||||
// required for JS IC caches
|
// required for JS IC caches
|
||||||
private val skipMutableState: Boolean = false,
|
private val skipMutableState: Boolean = false,
|
||||||
private val allowErrorStatementOrigins: Boolean = false, // TODO: support InlinerExpressionLocationHint
|
private val allowErrorStatementOrigins: Boolean = false, // TODO: support InlinerExpressionLocationHint
|
||||||
private val addDebugInfo: Boolean = true
|
private val addDebugInfo: Boolean = true,
|
||||||
|
private val normalizeAbsolutePaths: Boolean = false,
|
||||||
|
private val sourceBaseDirs: Collection<String>
|
||||||
) {
|
) {
|
||||||
private val loopIndex = mutableMapOf<IrLoop, Int>()
|
private val loopIndex = mutableMapOf<IrLoop, Int>()
|
||||||
private var currentLoopIndex = 0
|
private var currentLoopIndex = 0
|
||||||
@@ -1435,7 +1439,7 @@ open class IrFileSerializer(
|
|||||||
// ---------- Top level ------------------------------------------------------
|
// ---------- Top level ------------------------------------------------------
|
||||||
|
|
||||||
private fun serializeFileEntry(entry: IrFileEntry): ProtoFileEntry = ProtoFileEntry.newBuilder()
|
private fun serializeFileEntry(entry: IrFileEntry): ProtoFileEntry = ProtoFileEntry.newBuilder()
|
||||||
.setName(entry.name)
|
.setName(entry.matchAndNormalizeFilePath())
|
||||||
.addAllLineStartOffset(entry.lineStartOffsets.asIterable())
|
.addAllLineStartOffset(entry.lineStartOffsets.asIterable())
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
@@ -1590,6 +1594,30 @@ open class IrFileSerializer(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun tryMatchPath(fileName: String): String? {
|
||||||
|
val file = File(fileName)
|
||||||
|
val path = file.toPath()
|
||||||
|
|
||||||
|
for (base in sourceBaseDirs) {
|
||||||
|
if (path.startsWith(base)) {
|
||||||
|
return file.toRelativeString(File(base))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun IrFileEntry.matchAndNormalizeFilePath(): String {
|
||||||
|
tryMatchPath(name)?.let {
|
||||||
|
return it.replace(File.separatorChar, '/')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!normalizeAbsolutePaths) return name
|
||||||
|
|
||||||
|
return name.replace(File.separatorChar, '/')
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private fun serializeExpectActualSubstitutionTable(proto: ProtoFile.Builder) {
|
private fun serializeExpectActualSubstitutionTable(proto: ProtoFile.Builder) {
|
||||||
if (skipExpects) return
|
if (skipExpects) return
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
|||||||
import org.jetbrains.kotlin.library.SerializedIrFile
|
import org.jetbrains.kotlin.library.SerializedIrFile
|
||||||
import org.jetbrains.kotlin.library.SerializedIrModule
|
import org.jetbrains.kotlin.library.SerializedIrModule
|
||||||
|
|
||||||
abstract class IrModuleSerializer<F : IrFileSerializer>(protected val messageLogger: IrMessageLogger, protected val compatibilityMode: CompatibilityMode) {
|
abstract class IrModuleSerializer<F : IrFileSerializer>(protected val messageLogger: IrMessageLogger, protected val compatibilityMode: CompatibilityMode, protected val normalizeAbsolutePaths: Boolean, protected val sourceBaseDirs: Collection<String>) {
|
||||||
abstract fun createSerializerForFile(file: IrFile): F
|
abstract fun createSerializerForFile(file: IrFile): F
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-1
@@ -86,7 +86,9 @@ class IcSerializer(
|
|||||||
skipExpects = true,
|
skipExpects = true,
|
||||||
icMode = true,
|
icMode = true,
|
||||||
allowErrorStatementOrigins = true,
|
allowErrorStatementOrigins = true,
|
||||||
compatibilityMode = CompatibilityMode.CURRENT
|
compatibilityMode = CompatibilityMode.CURRENT,
|
||||||
|
normalizeAbsolutePaths = false,
|
||||||
|
sourceBaseDirs = emptyList()
|
||||||
)
|
)
|
||||||
|
|
||||||
icDeclarationTable.inFile(file) {
|
icDeclarationTable.inFile(file) {
|
||||||
|
|||||||
@@ -782,6 +782,8 @@ fun serializeModuleIntoKlib(
|
|||||||
assert(files.size == moduleFragment.files.size)
|
assert(files.size == moduleFragment.files.size)
|
||||||
|
|
||||||
val compatibilityMode = CompatibilityMode(abiVersion)
|
val compatibilityMode = CompatibilityMode(abiVersion)
|
||||||
|
val sourceBaseDirs = configuration[CommonConfigurationKeys.KLIB_RELATIVE_PATH_BASES] ?: emptyList()
|
||||||
|
val absolutePathNormalization = configuration[CommonConfigurationKeys.KLIB_NORMALIZE_ABSOLUTE_PATH] ?: false
|
||||||
|
|
||||||
val serializedIr =
|
val serializedIr =
|
||||||
JsIrModuleSerializer(
|
JsIrModuleSerializer(
|
||||||
@@ -789,7 +791,9 @@ fun serializeModuleIntoKlib(
|
|||||||
moduleFragment.irBuiltins,
|
moduleFragment.irBuiltins,
|
||||||
expectDescriptorToSymbol,
|
expectDescriptorToSymbol,
|
||||||
compatibilityMode,
|
compatibilityMode,
|
||||||
skipExpects = !configuration.expectActualLinker
|
skipExpects = !configuration.expectActualLinker,
|
||||||
|
normalizeAbsolutePaths = absolutePathNormalization,
|
||||||
|
sourceBaseDirs = sourceBaseDirs
|
||||||
).serializedIrModule(moduleFragment)
|
).serializedIrModule(moduleFragment)
|
||||||
|
|
||||||
val moduleDescriptor = moduleFragment.descriptor
|
val moduleDescriptor = moduleFragment.descriptor
|
||||||
|
|||||||
+4
@@ -24,6 +24,8 @@ class JsIrFileSerializer(
|
|||||||
bodiesOnlyForInlines: Boolean = false,
|
bodiesOnlyForInlines: Boolean = false,
|
||||||
icMode: Boolean = false,
|
icMode: Boolean = false,
|
||||||
allowErrorStatementOrigins: Boolean = false,
|
allowErrorStatementOrigins: Boolean = false,
|
||||||
|
normalizeAbsolutePaths: Boolean,
|
||||||
|
sourceBaseDirs: Collection<String>
|
||||||
) : IrFileSerializer(
|
) : IrFileSerializer(
|
||||||
messageLogger,
|
messageLogger,
|
||||||
declarationTable,
|
declarationTable,
|
||||||
@@ -33,6 +35,8 @@ class JsIrFileSerializer(
|
|||||||
skipExpects = skipExpects,
|
skipExpects = skipExpects,
|
||||||
skipMutableState = icMode,
|
skipMutableState = icMode,
|
||||||
allowErrorStatementOrigins = allowErrorStatementOrigins,
|
allowErrorStatementOrigins = allowErrorStatementOrigins,
|
||||||
|
normalizeAbsolutePaths = normalizeAbsolutePaths,
|
||||||
|
sourceBaseDirs = sourceBaseDirs
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
private val JS_EXPORT_FQN = FqName("kotlin.js.JsExport")
|
private val JS_EXPORT_FQN = FqName("kotlin.js.JsExport")
|
||||||
|
|||||||
+13
-3
@@ -19,11 +19,21 @@ class JsIrModuleSerializer(
|
|||||||
irBuiltIns: IrBuiltIns,
|
irBuiltIns: IrBuiltIns,
|
||||||
private val expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
private val expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
||||||
compatibilityMode: CompatibilityMode,
|
compatibilityMode: CompatibilityMode,
|
||||||
val skipExpects: Boolean
|
val skipExpects: Boolean,
|
||||||
) : IrModuleSerializer<JsIrFileSerializer>(messageLogger, compatibilityMode) {
|
normalizeAbsolutePaths: Boolean,
|
||||||
|
sourceBaseDirs: Collection<String>
|
||||||
|
) : IrModuleSerializer<JsIrFileSerializer>(messageLogger, compatibilityMode, normalizeAbsolutePaths, sourceBaseDirs) {
|
||||||
|
|
||||||
private val globalDeclarationTable = JsGlobalDeclarationTable(irBuiltIns)
|
private val globalDeclarationTable = JsGlobalDeclarationTable(irBuiltIns)
|
||||||
|
|
||||||
override fun createSerializerForFile(file: IrFile): JsIrFileSerializer =
|
override fun createSerializerForFile(file: IrFile): JsIrFileSerializer =
|
||||||
JsIrFileSerializer(messageLogger, DeclarationTable(globalDeclarationTable), expectDescriptorToSymbol, skipExpects = skipExpects, compatibilityMode = compatibilityMode)
|
JsIrFileSerializer(
|
||||||
|
messageLogger,
|
||||||
|
DeclarationTable(globalDeclarationTable),
|
||||||
|
expectDescriptorToSymbol,
|
||||||
|
skipExpects = skipExpects,
|
||||||
|
compatibilityMode = compatibilityMode,
|
||||||
|
normalizeAbsolutePaths = normalizeAbsolutePaths,
|
||||||
|
sourceBaseDirs = sourceBaseDirs
|
||||||
|
)
|
||||||
}
|
}
|
||||||
+1
-1
@@ -27,7 +27,7 @@ class JvmIrSerializerSession(
|
|||||||
) : IrFileSerializer(
|
) : IrFileSerializer(
|
||||||
messageLogger, declarationTable, expectDescriptorToSymbol, CompatibilityMode.CURRENT,
|
messageLogger, declarationTable, expectDescriptorToSymbol, CompatibilityMode.CURRENT,
|
||||||
bodiesOnlyForInlines = mode == JvmSerializeIrMode.INLINE,
|
bodiesOnlyForInlines = mode == JvmSerializeIrMode.INLINE,
|
||||||
skipExpects
|
skipExpects, normalizeAbsolutePaths = false, sourceBaseDirs = emptyList()
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
assert(mode != JvmSerializeIrMode.NONE)
|
assert(mode != JvmSerializeIrMode.NONE)
|
||||||
|
|||||||
@@ -136,10 +136,15 @@ abstract class AbstractKlibTextTestCase : CodegenTestCase() {
|
|||||||
|
|
||||||
protected fun serializeModule(irModuleFragment: IrModuleFragment, bindingContext: BindingContext, stdlib: KotlinLibrary, containsErrorCode: Boolean, expectActualSymbols: MutableMap<DeclarationDescriptor, IrSymbol>, skipExpect: Boolean): String {
|
protected fun serializeModule(irModuleFragment: IrModuleFragment, bindingContext: BindingContext, stdlib: KotlinLibrary, containsErrorCode: Boolean, expectActualSymbols: MutableMap<DeclarationDescriptor, IrSymbol>, skipExpect: Boolean): String {
|
||||||
val ktFiles = myFiles.psiFiles
|
val ktFiles = myFiles.psiFiles
|
||||||
val serializedIr =
|
val serializedIr = JsIrModuleSerializer(
|
||||||
JsIrModuleSerializer(IrMessageLogger.None, irModuleFragment.irBuiltins, expectActualSymbols, CompatibilityMode.CURRENT, skipExpect).serializedIrModule(
|
IrMessageLogger.None,
|
||||||
irModuleFragment
|
irModuleFragment.irBuiltins,
|
||||||
)
|
expectActualSymbols,
|
||||||
|
CompatibilityMode.CURRENT,
|
||||||
|
skipExpect,
|
||||||
|
false,
|
||||||
|
emptyList()
|
||||||
|
).serializedIrModule(irModuleFragment)
|
||||||
|
|
||||||
val moduleDescriptor = irModuleFragment.descriptor
|
val moduleDescriptor = irModuleFragment.descriptor
|
||||||
val metadataSerializer = klibMetadataIncrementalSerializer(myEnvironment.configuration, myEnvironment.project, containsErrorCode)
|
val metadataSerializer = klibMetadataIncrementalSerializer(myEnvironment.configuration, myEnvironment.project, containsErrorCode)
|
||||||
|
|||||||
@@ -529,7 +529,9 @@ class GenerateIrRuntime {
|
|||||||
module.irBuiltins,
|
module.irBuiltins,
|
||||||
mutableMapOf(),
|
mutableMapOf(),
|
||||||
CompatibilityMode.CURRENT,
|
CompatibilityMode.CURRENT,
|
||||||
true
|
skipExpects = true,
|
||||||
|
normalizeAbsolutePaths = false,
|
||||||
|
emptyList()
|
||||||
).serializedIrModule(module)
|
).serializedIrModule(module)
|
||||||
return serializedIr
|
return serializedIr
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -219,10 +219,12 @@ internal val serializerPhase = konanUnitPhase(
|
|||||||
op = {
|
op = {
|
||||||
val expectActualLinker = config.configuration.get(CommonConfigurationKeys.EXPECT_ACTUAL_LINKER) ?: false
|
val expectActualLinker = config.configuration.get(CommonConfigurationKeys.EXPECT_ACTUAL_LINKER) ?: false
|
||||||
val messageLogger = config.configuration.get(IrMessageLogger.IR_MESSAGE_LOGGER) ?: IrMessageLogger.None
|
val messageLogger = config.configuration.get(IrMessageLogger.IR_MESSAGE_LOGGER) ?: IrMessageLogger.None
|
||||||
|
val relativePathBase = config.configuration.get(CommonConfigurationKeys.KLIB_RELATIVE_PATH_BASES) ?: emptyList()
|
||||||
|
val normalizeAbsolutePaths = config.configuration.get(CommonConfigurationKeys.KLIB_NORMALIZE_ABSOLUTE_PATH) ?: false
|
||||||
|
|
||||||
serializedIr = irModule?.let { ir ->
|
serializedIr = irModule?.let { ir ->
|
||||||
KonanIrModuleSerializer(
|
KonanIrModuleSerializer(
|
||||||
messageLogger, ir.irBuiltins, expectDescriptorToSymbol, skipExpects = !expectActualLinker, compatibilityMode = CompatibilityMode.CURRENT
|
messageLogger, ir.irBuiltins, expectDescriptorToSymbol, skipExpects = !expectActualLinker, compatibilityMode = CompatibilityMode.CURRENT, normalizeAbsolutePaths = normalizeAbsolutePaths, sourceBaseDirs = relativePathBase
|
||||||
).serializedIrModule(ir)
|
).serializedIrModule(ir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -18,8 +18,10 @@ class KonanIrFileSerializer(
|
|||||||
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
||||||
skipExpects: Boolean,
|
skipExpects: Boolean,
|
||||||
bodiesOnlyForInlines: Boolean = false,
|
bodiesOnlyForInlines: Boolean = false,
|
||||||
compatibilityMode: CompatibilityMode
|
compatibilityMode: CompatibilityMode,
|
||||||
): IrFileSerializer(messageLogger, declarationTable, expectDescriptorToSymbol, compatibilityMode, bodiesOnlyForInlines, skipExpects) {
|
normalizeAbsolutePaths: Boolean,
|
||||||
|
sourceBaseDirs: Collection<String>
|
||||||
|
): IrFileSerializer(messageLogger, declarationTable, expectDescriptorToSymbol, compatibilityMode, bodiesOnlyForInlines, skipExpects, normalizeAbsolutePaths = normalizeAbsolutePaths, sourceBaseDirs = sourceBaseDirs) {
|
||||||
|
|
||||||
override fun backendSpecificExplicitRoot(node: IrAnnotationContainer): Boolean {
|
override fun backendSpecificExplicitRoot(node: IrAnnotationContainer): Boolean {
|
||||||
val fqn = when (node) {
|
val fqn = when (node) {
|
||||||
|
|||||||
+5
-4
@@ -2,7 +2,6 @@ package org.jetbrains.kotlin.backend.konan.serialization
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.CompatibilityMode
|
import org.jetbrains.kotlin.backend.common.serialization.CompatibilityMode
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.IrModuleSerializer
|
import org.jetbrains.kotlin.backend.common.serialization.IrModuleSerializer
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer
|
|
||||||
import org.jetbrains.kotlin.backend.konan.ir.interop.IrProviderForCEnumAndCStructStubs
|
import org.jetbrains.kotlin.backend.konan.ir.interop.IrProviderForCEnumAndCStructStubs
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||||
@@ -15,8 +14,10 @@ class KonanIrModuleSerializer(
|
|||||||
irBuiltIns: IrBuiltIns,
|
irBuiltIns: IrBuiltIns,
|
||||||
private val expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
private val expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
||||||
val skipExpects: Boolean,
|
val skipExpects: Boolean,
|
||||||
compatibilityMode: CompatibilityMode
|
compatibilityMode: CompatibilityMode,
|
||||||
) : IrModuleSerializer<KonanIrFileSerializer>(messageLogger, compatibilityMode) {
|
normalizeAbsolutePaths: Boolean,
|
||||||
|
sourceBaseDirs: Collection<String>
|
||||||
|
) : IrModuleSerializer<KonanIrFileSerializer>(messageLogger, compatibilityMode, normalizeAbsolutePaths, sourceBaseDirs) {
|
||||||
|
|
||||||
private val globalDeclarationTable = KonanGlobalDeclarationTable(irBuiltIns)
|
private val globalDeclarationTable = KonanGlobalDeclarationTable(irBuiltIns)
|
||||||
|
|
||||||
@@ -30,5 +31,5 @@ class KonanIrModuleSerializer(
|
|||||||
file.fileEntry.name != IrProviderForCEnumAndCStructStubs.cTypeDefinitionsFileName
|
file.fileEntry.name != IrProviderForCEnumAndCStructStubs.cTypeDefinitionsFileName
|
||||||
|
|
||||||
override fun createSerializerForFile(file: IrFile): KonanIrFileSerializer =
|
override fun createSerializerForFile(file: IrFile): KonanIrFileSerializer =
|
||||||
KonanIrFileSerializer(messageLogger, KonanDeclarationTable(globalDeclarationTable), expectDescriptorToSymbol, skipExpects = skipExpects, compatibilityMode = compatibilityMode)
|
KonanIrFileSerializer(messageLogger, KonanDeclarationTable(globalDeclarationTable), expectDescriptorToSymbol, skipExpects = skipExpects, compatibilityMode = compatibilityMode, normalizeAbsolutePaths = normalizeAbsolutePaths, sourceBaseDirs = sourceBaseDirs)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user