Support short library names in compiler, interop and platform libs

Fixes for KT-36720 and KT-36721 change a scheme that is used to generate
unique names for klibs: now we use "fully qualified" names that
include a group and a name of a library (e.g. org.jetbrains.kotlin.
native.posix).

But in some cases we still need short library names. For example
to display platform libs in the IDE or to export some symbols of
a library to an ObjC framework.

This patch adds support for such short names to:
 - klib generation in the compiler
 - cinterop tool (both sourcecode and metadata mode)
 - platform libraries (both prebuilt and built on the user side)

Support for C/ObjC export remains.
This commit is contained in:
Ilya Matveev
2020-03-24 16:46:39 +07:00
committed by Ilya Matveev
parent 624328c3cc
commit ce1cb39c41
12 changed files with 50 additions and 9 deletions
@@ -21,6 +21,7 @@ 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
import org.jetbrains.kotlin.native.interop.tool.CommonInteropArguments.Companion.MODE_SOURCECODE
import org.jetbrains.kotlin.native.interop.tool.SHORT_MODULE_NAME
import java.io.PrintWriter
import java.io.StringWriter
import java.util.concurrent.atomic.AtomicInteger
@@ -167,6 +168,9 @@ private class DefFile(val name: String, val depends: MutableList<DefFile>) {
val libraryName: String
get() = "${PlatformLibsInfo.namePrefix}$name"
val shortLibraryName: String
get() = name
}
private fun createTempDir(prefix: String, parent: File): File =
@@ -236,6 +240,7 @@ private fun generateLibrary(
"-repo", outputDirectory.absolutePath,
"-no-default-libs", "-no-endorsed-libs", "-Xpurge-user-libs", "-nopack",
"-mode", mode,
"-$SHORT_MODULE_NAME", def.shortLibraryName,
*def.depends.flatMap { listOf("-l", "$outputDirectory/${it.libraryName}") }.toTypedArray()
)
logger.verbose("Run cinterop with args: ${cinteropArgs.joinToString(separator = " ")}")
@@ -26,6 +26,7 @@ fun invokeInterop(flavor: String, args: Array<String>): Array<String>? {
val purgeUserLibs = arguments.purgeUserLibs
val nopack = arguments.nopack
val temporaryFilesDir = arguments.tempDir
val shortModuleName = (arguments as? CInteropArguments)?.shortModuleName
val buildDir = File("$outputFileName-build")
val generatedDir = File(buildDir, "kotlin")
@@ -66,6 +67,7 @@ fun invokeInterop(flavor: String, args: Array<String>): Array<String>? {
(if (noEndorsedLibs) arrayOf("-$NOENDORSEDLIBS") else emptyArray()) +
(if (purgeUserLibs) arrayOf("-$PURGE_USER_LIBS") else emptyArray()) +
(if (nopack) arrayOf("-$NOPACK") else emptyArray()) +
shortModuleName?.let { arrayOf("-Xshort-module-name=$it") }.orEmpty() +
arguments.kotlincOption
}