[CLI] Allow using -Xshort-module-name for klib compilation only

This commit is contained in:
Ilya Matveev
2020-03-31 13:33:01 +07:00
committed by Ilya Matveev
parent 92228d44af
commit 721a84ea44
3 changed files with 29 additions and 4 deletions
@@ -124,7 +124,6 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
put(LINKER_ARGS, arguments.linkerArguments.toNonNullList() +
arguments.singleLinkerArguments.toNonNullList())
arguments.moduleName?.let{ put(MODULE_NAME, it) }
arguments.shortModuleName?.let { put(SHORT_MODULE_NAME, it) }
arguments.target?.let{ put(TARGET, it) }
put(INCLUDED_BINARY_FILES,
@@ -229,6 +228,10 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
libraryToAddToCache?.let { put(LIBRARY_TO_ADD_TO_CACHE, it) }
put(CACHE_DIRECTORIES, cacheDirectories)
put(CACHED_LIBRARIES, parseCachedLibraries(arguments, configuration))
parseShortModuleName(arguments, configuration, outputKind)?.let {
put(SHORT_MODULE_NAME, it)
}
}
}
}
@@ -374,5 +377,25 @@ private fun parseLibraryToAddToCache(
}
}
// TODO: Support short names for current module in ObjC export and lift this limitation.
private fun parseShortModuleName(
arguments: K2NativeCompilerArguments,
configuration: CompilerConfiguration,
outputKind: CompilerOutputKind
): String? {
val input = arguments.shortModuleName
return if (input != null && outputKind != CompilerOutputKind.LIBRARY) {
configuration.report(
STRONG_WARNING,
"$SHORT_MODULE_NAME_ARG is only supported when producing a Kotlin library, " +
"but the compiler is producing ${outputKind.name.toLowerCase()}"
)
null
} else {
input
}
}
fun main(args: Array<String>) = K2Native.main(args)
fun mainNoExit(args: Array<String>) = K2Native.mainNoExit(args)
@@ -200,7 +200,7 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
var includes: Array<String>? = null
@Argument(
value = "-Xshort-module-name",
value = SHORT_MODULE_NAME_ARG,
valueDescription = "<name>",
description = "A short name used to denote this library in the IDE and in a generated Objective-C header"
)
@@ -281,4 +281,5 @@ const val STATIC_FRAMEWORK_FLAG = "-Xstatic-framework"
const val INCLUDE_ARG = "-Xinclude"
const val CACHED_LIBRARY = "-Xcached-library"
const val MAKE_CACHE = "-Xmake-cache"
const val ADD_CACHE = "-Xadd-cache"
const val ADD_CACHE = "-Xadd-cache"
const val SHORT_MODULE_NAME_ARG = "-Xshort-module-name"
@@ -4,6 +4,7 @@
*/
package org.jetbrains.kotlin.cli.utilities
import org.jetbrains.kotlin.cli.bc.SHORT_MODULE_NAME_ARG
import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.konan.target.PlatformManager
import org.jetbrains.kotlin.native.interop.gen.jvm.InternalInteropOptions
@@ -69,7 +70,7 @@ fun invokeInterop(flavor: String, args: Array<String>): Array<String>? {
(if (purgeUserLibs) arrayOf("-$PURGE_USER_LIBS") else emptyArray()) +
(if (nopack) arrayOf("-$NOPACK") else emptyArray()) +
moduleName?.let { arrayOf("-module-name", it) }.orEmpty() +
shortModuleName?.let { arrayOf("-Xshort-module-name=$it") }.orEmpty() +
shortModuleName?.let { arrayOf("$SHORT_MODULE_NAME_ARG=$it") }.orEmpty() +
arguments.kotlincOption
}