[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
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user