[K/N] Normalize klib paths for KonanLibraryImpl

^KT-58979 Fixed

Merge-request: KT-MR-10372
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
Vladimir Sukharev
2023-05-31 04:53:58 +00:00
committed by Space Team
parent e11ebcadb4
commit ebc4cf7f96
2 changed files with 8 additions and 4 deletions
@@ -14,7 +14,7 @@ object KonanHomeProvider {
/** /**
* Determines a path to the current Kotlin/Native distribution. * Determines a path to the current Kotlin/Native distribution.
* *
* - If the system property "konan.home" is set, the method returns its value. * - If the system property "konan.home" is set, the method returns its normalized value.
* - Otherwise, it determines a path to a jar containing this class. If this path corresponds to the jar path * - Otherwise, it determines a path to a jar containing this class. If this path corresponds to the jar path
* inside a distribution, the method calculates the path to the distribution on the basis of this jar path. * inside a distribution, the method calculates the path to the distribution on the basis of this jar path.
* Otherwise an IllegalStateException is thrown. * Otherwise an IllegalStateException is thrown.
@@ -22,7 +22,9 @@ object KonanHomeProvider {
fun determineKonanHome(): String { fun determineKonanHome(): String {
val propertyValue = kotlinNativeHome val propertyValue = kotlinNativeHome
return if (propertyValue != null) { return if (propertyValue != null) {
File(propertyValue).absolutePath // KT-58979: KonanLibraryImpl needs normalized klib paths to correctly provide symbols from resolved klibs
// For extra safety, path to "konan.home" is also normalized here
Paths.get(File(propertyValue).absolutePath).normalize().toString()
} else { } else {
val jarPath = PathUtil.getResourcePathForClass(this::class.java) val jarPath = PathUtil.getResourcePathForClass(this::class.java)
@@ -19,13 +19,13 @@ package org.jetbrains.kotlin.konan.library.impl
import org.jetbrains.kotlin.konan.file.File import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.konan.library.* import org.jetbrains.kotlin.konan.library.*
import org.jetbrains.kotlin.konan.properties.Properties import org.jetbrains.kotlin.konan.properties.Properties
import org.jetbrains.kotlin.konan.properties.loadProperties
import org.jetbrains.kotlin.konan.properties.propertyList import org.jetbrains.kotlin.konan.properties.propertyList
import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.konan.util.defaultTargetSubstitutions import org.jetbrains.kotlin.konan.util.defaultTargetSubstitutions
import org.jetbrains.kotlin.konan.util.substitute import org.jetbrains.kotlin.konan.util.substitute
import org.jetbrains.kotlin.library.* import org.jetbrains.kotlin.library.*
import org.jetbrains.kotlin.library.impl.* import org.jetbrains.kotlin.library.impl.*
import java.nio.file.Paths
open class TargetedLibraryImpl( open class TargetedLibraryImpl(
private val access: TargetedLibraryAccess<TargetedKotlinLibraryLayout>, private val access: TargetedLibraryAccess<TargetedKotlinLibraryLayout>,
@@ -81,11 +81,13 @@ class KonanLibraryImpl(
fun createKonanLibrary( fun createKonanLibrary(
libraryFile: File, libraryFilePossiblyDenormalized: File,
component: String, component: String,
target: KonanTarget? = null, target: KonanTarget? = null,
isDefault: Boolean = false isDefault: Boolean = false
): KonanLibrary { ): KonanLibrary {
// KT-58979: The following access classes need normalized klib path to correctly provide symbols from resolved klibs
val libraryFile = Paths.get(libraryFilePossiblyDenormalized.absolutePath).normalize().File()
val baseAccess = BaseLibraryAccess<KotlinLibraryLayout>(libraryFile, component) val baseAccess = BaseLibraryAccess<KotlinLibraryLayout>(libraryFile, component)
val targetedAccess = TargetedLibraryAccess<TargetedKotlinLibraryLayout>(libraryFile, component, target) val targetedAccess = TargetedLibraryAccess<TargetedKotlinLibraryLayout>(libraryFile, component, target)
val metadataAccess = MetadataLibraryAccess<MetadataKotlinLibraryLayout>(libraryFile, component) val metadataAccess = MetadataLibraryAccess<MetadataKotlinLibraryLayout>(libraryFile, component)