[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.name.Name
|
||||
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.Actual as ProtoActual
|
||||
import org.jetbrains.kotlin.backend.common.serialization.proto.CommonIdSignature as ProtoCommonIdSignature
|
||||
@@ -127,7 +129,9 @@ open class IrFileSerializer(
|
||||
// required for JS IC caches
|
||||
private val skipMutableState: Boolean = false,
|
||||
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 var currentLoopIndex = 0
|
||||
@@ -1435,7 +1439,7 @@ open class IrFileSerializer(
|
||||
// ---------- Top level ------------------------------------------------------
|
||||
|
||||
private fun serializeFileEntry(entry: IrFileEntry): ProtoFileEntry = ProtoFileEntry.newBuilder()
|
||||
.setName(entry.name)
|
||||
.setName(entry.matchAndNormalizeFilePath())
|
||||
.addAllLineStartOffset(entry.lineStartOffsets.asIterable())
|
||||
.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) {
|
||||
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.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
|
||||
|
||||
/**
|
||||
|
||||
+3
-1
@@ -86,7 +86,9 @@ class IcSerializer(
|
||||
skipExpects = true,
|
||||
icMode = true,
|
||||
allowErrorStatementOrigins = true,
|
||||
compatibilityMode = CompatibilityMode.CURRENT
|
||||
compatibilityMode = CompatibilityMode.CURRENT,
|
||||
normalizeAbsolutePaths = false,
|
||||
sourceBaseDirs = emptyList()
|
||||
)
|
||||
|
||||
icDeclarationTable.inFile(file) {
|
||||
|
||||
@@ -782,6 +782,8 @@ fun serializeModuleIntoKlib(
|
||||
assert(files.size == moduleFragment.files.size)
|
||||
|
||||
val compatibilityMode = CompatibilityMode(abiVersion)
|
||||
val sourceBaseDirs = configuration[CommonConfigurationKeys.KLIB_RELATIVE_PATH_BASES] ?: emptyList()
|
||||
val absolutePathNormalization = configuration[CommonConfigurationKeys.KLIB_NORMALIZE_ABSOLUTE_PATH] ?: false
|
||||
|
||||
val serializedIr =
|
||||
JsIrModuleSerializer(
|
||||
@@ -789,7 +791,9 @@ fun serializeModuleIntoKlib(
|
||||
moduleFragment.irBuiltins,
|
||||
expectDescriptorToSymbol,
|
||||
compatibilityMode,
|
||||
skipExpects = !configuration.expectActualLinker
|
||||
skipExpects = !configuration.expectActualLinker,
|
||||
normalizeAbsolutePaths = absolutePathNormalization,
|
||||
sourceBaseDirs = sourceBaseDirs
|
||||
).serializedIrModule(moduleFragment)
|
||||
|
||||
val moduleDescriptor = moduleFragment.descriptor
|
||||
|
||||
+4
@@ -24,6 +24,8 @@ class JsIrFileSerializer(
|
||||
bodiesOnlyForInlines: Boolean = false,
|
||||
icMode: Boolean = false,
|
||||
allowErrorStatementOrigins: Boolean = false,
|
||||
normalizeAbsolutePaths: Boolean,
|
||||
sourceBaseDirs: Collection<String>
|
||||
) : IrFileSerializer(
|
||||
messageLogger,
|
||||
declarationTable,
|
||||
@@ -33,6 +35,8 @@ class JsIrFileSerializer(
|
||||
skipExpects = skipExpects,
|
||||
skipMutableState = icMode,
|
||||
allowErrorStatementOrigins = allowErrorStatementOrigins,
|
||||
normalizeAbsolutePaths = normalizeAbsolutePaths,
|
||||
sourceBaseDirs = sourceBaseDirs
|
||||
) {
|
||||
companion object {
|
||||
private val JS_EXPORT_FQN = FqName("kotlin.js.JsExport")
|
||||
|
||||
+13
-3
@@ -19,11 +19,21 @@ class JsIrModuleSerializer(
|
||||
irBuiltIns: IrBuiltIns,
|
||||
private val expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
||||
compatibilityMode: CompatibilityMode,
|
||||
val skipExpects: Boolean
|
||||
) : IrModuleSerializer<JsIrFileSerializer>(messageLogger, compatibilityMode) {
|
||||
val skipExpects: Boolean,
|
||||
normalizeAbsolutePaths: Boolean,
|
||||
sourceBaseDirs: Collection<String>
|
||||
) : IrModuleSerializer<JsIrFileSerializer>(messageLogger, compatibilityMode, normalizeAbsolutePaths, sourceBaseDirs) {
|
||||
|
||||
private val globalDeclarationTable = JsGlobalDeclarationTable(irBuiltIns)
|
||||
|
||||
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(
|
||||
messageLogger, declarationTable, expectDescriptorToSymbol, CompatibilityMode.CURRENT,
|
||||
bodiesOnlyForInlines = mode == JvmSerializeIrMode.INLINE,
|
||||
skipExpects
|
||||
skipExpects, normalizeAbsolutePaths = false, sourceBaseDirs = emptyList()
|
||||
) {
|
||||
init {
|
||||
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 {
|
||||
val ktFiles = myFiles.psiFiles
|
||||
val serializedIr =
|
||||
JsIrModuleSerializer(IrMessageLogger.None, irModuleFragment.irBuiltins, expectActualSymbols, CompatibilityMode.CURRENT, skipExpect).serializedIrModule(
|
||||
irModuleFragment
|
||||
)
|
||||
val serializedIr = JsIrModuleSerializer(
|
||||
IrMessageLogger.None,
|
||||
irModuleFragment.irBuiltins,
|
||||
expectActualSymbols,
|
||||
CompatibilityMode.CURRENT,
|
||||
skipExpect,
|
||||
false,
|
||||
emptyList()
|
||||
).serializedIrModule(irModuleFragment)
|
||||
|
||||
val moduleDescriptor = irModuleFragment.descriptor
|
||||
val metadataSerializer = klibMetadataIncrementalSerializer(myEnvironment.configuration, myEnvironment.project, containsErrorCode)
|
||||
|
||||
@@ -529,7 +529,9 @@ class GenerateIrRuntime {
|
||||
module.irBuiltins,
|
||||
mutableMapOf(),
|
||||
CompatibilityMode.CURRENT,
|
||||
true
|
||||
skipExpects = true,
|
||||
normalizeAbsolutePaths = false,
|
||||
emptyList()
|
||||
).serializedIrModule(module)
|
||||
return serializedIr
|
||||
}
|
||||
|
||||
+3
-1
@@ -219,10 +219,12 @@ internal val serializerPhase = konanUnitPhase(
|
||||
op = {
|
||||
val expectActualLinker = config.configuration.get(CommonConfigurationKeys.EXPECT_ACTUAL_LINKER) ?: false
|
||||
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 ->
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -18,8 +18,10 @@ class KonanIrFileSerializer(
|
||||
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
||||
skipExpects: Boolean,
|
||||
bodiesOnlyForInlines: Boolean = false,
|
||||
compatibilityMode: CompatibilityMode
|
||||
): IrFileSerializer(messageLogger, declarationTable, expectDescriptorToSymbol, compatibilityMode, bodiesOnlyForInlines, skipExpects) {
|
||||
compatibilityMode: CompatibilityMode,
|
||||
normalizeAbsolutePaths: Boolean,
|
||||
sourceBaseDirs: Collection<String>
|
||||
): IrFileSerializer(messageLogger, declarationTable, expectDescriptorToSymbol, compatibilityMode, bodiesOnlyForInlines, skipExpects, normalizeAbsolutePaths = normalizeAbsolutePaths, sourceBaseDirs = sourceBaseDirs) {
|
||||
|
||||
override fun backendSpecificExplicitRoot(node: IrAnnotationContainer): Boolean {
|
||||
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.IrModuleSerializer
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer
|
||||
import org.jetbrains.kotlin.backend.konan.ir.interop.IrProviderForCEnumAndCStructStubs
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
@@ -15,8 +14,10 @@ class KonanIrModuleSerializer(
|
||||
irBuiltIns: IrBuiltIns,
|
||||
private val expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>,
|
||||
val skipExpects: Boolean,
|
||||
compatibilityMode: CompatibilityMode
|
||||
) : IrModuleSerializer<KonanIrFileSerializer>(messageLogger, compatibilityMode) {
|
||||
compatibilityMode: CompatibilityMode,
|
||||
normalizeAbsolutePaths: Boolean,
|
||||
sourceBaseDirs: Collection<String>
|
||||
) : IrModuleSerializer<KonanIrFileSerializer>(messageLogger, compatibilityMode, normalizeAbsolutePaths, sourceBaseDirs) {
|
||||
|
||||
private val globalDeclarationTable = KonanGlobalDeclarationTable(irBuiltIns)
|
||||
|
||||
@@ -30,5 +31,5 @@ class KonanIrModuleSerializer(
|
||||
file.fileEntry.name != IrProviderForCEnumAndCStructStubs.cTypeDefinitionsFileName
|
||||
|
||||
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