From 25625223922e19dea410781c7a846680d7b829a1 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Wed, 4 Mar 2020 15:51:09 +0700 Subject: [PATCH] Platform libs: Use FQ-names for platform libraries This patch changes the platform libraries naming scheme. Earlier the platform libraries used to have simple names, like posix or Foundation. But these names are not unique enough. This causes issues with library resolution and cache building if a user library has the same simple name. With this patch all platform libraries have FQ names like org.jetbrains.konan.platform.posix. Corresponding change for user libraries will be added separately at the Gradle plugin side. Fix for #KT-36720. --- platformLibs/build.gradle | 7 +++++-- .../jetbrains/kotlin/konan/util/PlatformLibsInfo.kt | 5 +++++ .../cli/utilities/GeneratePlatformLibraries.kt | 12 ++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 shared/src/main/kotlin/org/jetbrains/kotlin/konan/util/PlatformLibsInfo.kt diff --git a/platformLibs/build.gradle b/platformLibs/build.gradle index e81c7b26b7a..716026ed3d3 100644 --- a/platformLibs/build.gradle +++ b/platformLibs/build.gradle @@ -73,15 +73,18 @@ project.rootProject.ext.platformManager.enabled.each { target -> targetDefFiles(target).each { df -> def libName = defFileToLibName(targetName, df.name) + def fileNamePrefix = PlatformLibsInfo.namePrefix konanArtifacts { interop (libName, targets: [targetName]) { defFile df.file - artifactName df.name + artifactName "${fileNamePrefix}${df.name}" noDefaultLibs true noEndorsedLibs true libraries { - klibs df.config.depends + klibs df.config.depends.collect { + "${fileNamePrefix}${it}".toString() + } } extraOpts '-Xpurge-user-libs' compilerOpts "-fmodules-cache-path=${project.buildDir}/clangModulesCache" diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/util/PlatformLibsInfo.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/util/PlatformLibsInfo.kt new file mode 100644 index 00000000000..0b5dcded1ca --- /dev/null +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/util/PlatformLibsInfo.kt @@ -0,0 +1,5 @@ +package org.jetbrains.kotlin.konan.util + +object PlatformLibsInfo { + const val namePrefix = "org.jetbrains.kotlin.native.platform." +} diff --git a/utilities/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/GeneratePlatformLibraries.kt b/utilities/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/GeneratePlatformLibraries.kt index 0b9e6011404..53351499340 100644 --- a/utilities/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/GeneratePlatformLibraries.kt +++ b/utilities/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/GeneratePlatformLibraries.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.konan.target.CompilerOutputKind import org.jetbrains.kotlin.konan.target.HostManager import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.konan.target.customerDistribution +import org.jetbrains.kotlin.konan.util.PlatformLibsInfo import org.jetbrains.kotlin.konan.util.visibleName import org.jetbrains.kotlin.native.interop.tool.CommonInteropArguments.Companion.DEFAULT_MODE import org.jetbrains.kotlin.native.interop.tool.CommonInteropArguments.Companion.MODE_METADATA @@ -163,6 +164,9 @@ private data class CacheInfo(val cacheDirectory: File, val cacheKind: String, private class DefFile(val name: String, val depends: MutableList) { override fun toString(): String = "$name: [${depends.joinToString(separator = ", ") { it.name }}]" + + val libraryName: String + get() = "${PlatformLibsInfo.namePrefix}$name" } private fun createTempDir(prefix: String, parent: File): File = @@ -214,14 +218,14 @@ private fun generateLibrary( logger: Logger ) = with(directories) { val defFile = inputDirectory.child("${def.name}.def") - val outKlib = outputDirectory.child(def.name) + val outKlib = outputDirectory.child(def.libraryName) if (outKlib.exists && !rebuild) { logger.verbose("Skip generating ${def.name} as it's already generated") return } - val tmpKlib = tmpDirectory.child(def.name) + val tmpKlib = tmpDirectory.child(def.libraryName) try { val cinteropArgs = arrayOf( @@ -232,7 +236,7 @@ private fun generateLibrary( "-repo", outputDirectory.absolutePath, "-no-default-libs", "-no-endorsed-libs", "-Xpurge-user-libs", "-nopack", "-mode", mode, - *def.depends.flatMap { listOf("-l", "$outputDirectory/${it.name}") }.toTypedArray() + *def.depends.flatMap { listOf("-l", "$outputDirectory/${it.libraryName}") }.toTypedArray() ) logger.verbose("Run cinterop with args: ${cinteropArgs.joinToString(separator = " ")}") invokeInterop("native", cinteropArgs)?.let { K2Native.mainNoExit(it) } @@ -283,7 +287,7 @@ private fun buildCache( "-p", cacheKind, "-target", target.visibleName, "-repo", outputDirectory.absolutePath, - "-Xadd-cache=${outputDirectory.absolutePath}/${def.name}", + "-Xadd-cache=${outputDirectory.absolutePath}/${def.libraryName}", "-Xcache-directory=${cacheDirectory.absolutePath}", *cacheArgs.toTypedArray() )