Stop using ModuleDescriptor.name for top-level ObjCExport name prefix
^KT-47809 Fixed Do similar for C export.
This commit is contained in:
committed by
Space
parent
48a2b23b3a
commit
a63f218dd3
@@ -140,6 +140,10 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
put(LINKER_ARGS, arguments.linkerArguments.toNonNullList() +
|
||||
arguments.singleLinkerArguments.toNonNullList())
|
||||
arguments.moduleName?.let{ put(MODULE_NAME, it) }
|
||||
|
||||
// TODO: allow overriding the prefix directly.
|
||||
arguments.moduleName?.let { put(FULL_EXPORTED_NAME_PREFIX, it) }
|
||||
|
||||
arguments.target?.let{ put(TARGET, it) }
|
||||
|
||||
put(INCLUDED_BINARY_FILES,
|
||||
|
||||
+1
-1
@@ -516,7 +516,7 @@ private fun ModuleDescriptor.getPackageFragments(): List<PackageFragmentDescript
|
||||
internal class CAdapterGenerator(val context: Context) : DeclarationDescriptorVisitor<Boolean, Void?> {
|
||||
|
||||
private val scopes = mutableListOf<ExportedElementScope>()
|
||||
internal val prefix = context.config.moduleId
|
||||
internal val prefix = context.config.fullExportedNamePrefix
|
||||
private lateinit var outputStreamWriter: PrintWriter
|
||||
private val paramNamesRecorded = mutableMapOf<String, Int>()
|
||||
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ internal fun StorageComponentContainer.initContainer(config: KonanConfig) {
|
||||
|
||||
useInstance(object : ObjCExportLazy.Configuration {
|
||||
override val frameworkName: String
|
||||
get() = config.moduleId
|
||||
get() = config.fullExportedNamePrefix
|
||||
|
||||
override fun isIncluded(moduleInfo: ModuleInfo): Boolean = true
|
||||
|
||||
|
||||
+7
-1
@@ -106,8 +106,14 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
||||
|
||||
val outputFile get() = outputFiles.mainFile
|
||||
|
||||
private val implicitModuleName: String
|
||||
get() = File(outputFiles.outputName).name
|
||||
|
||||
val fullExportedNamePrefix: String
|
||||
get() = configuration.get(KonanConfigKeys.FULL_EXPORTED_NAME_PREFIX) ?: implicitModuleName
|
||||
|
||||
val moduleId: String
|
||||
get() = configuration.get(KonanConfigKeys.MODULE_NAME) ?: File(outputFiles.outputName).name
|
||||
get() = configuration.get(KonanConfigKeys.MODULE_NAME) ?: implicitModuleName
|
||||
|
||||
val shortModuleName: String?
|
||||
get() = configuration.get(KonanConfigKeys.SHORT_MODULE_NAME)
|
||||
|
||||
+2
@@ -32,6 +32,8 @@ class KonanConfigKeys {
|
||||
= CompilerConfigurationKey.create("fully qualified main() name")
|
||||
val EXPORTED_LIBRARIES: CompilerConfigurationKey<List<String>>
|
||||
= CompilerConfigurationKey.create<List<String>>("libraries included into produced framework API")
|
||||
val FULL_EXPORTED_NAME_PREFIX: CompilerConfigurationKey<String?>
|
||||
= CompilerConfigurationKey.create("prefix used when exporting Kotlin names to other languages")
|
||||
val LIBRARIES_TO_CACHE: CompilerConfigurationKey<List<String>>
|
||||
= CompilerConfigurationKey.create<List<String>>("paths to libraries that to be compiled to cache")
|
||||
val LIBRARY_TO_ADD_TO_CACHE: CompilerConfigurationKey<String?>
|
||||
|
||||
+3
-2
@@ -36,6 +36,7 @@ internal class ObjCExportedInterface(
|
||||
|
||||
internal class ObjCExport(val context: Context, symbolTable: SymbolTable) {
|
||||
private val target get() = context.config.target
|
||||
private val topLevelNamePrefix get() = context.objCExportTopLevelNamePrefix
|
||||
|
||||
private val exportedInterface = produceInterface()
|
||||
private val codeSpec = exportedInterface?.createCodeSpec(symbolTable)
|
||||
@@ -59,7 +60,7 @@ internal class ObjCExport(val context: Context, symbolTable: SymbolTable) {
|
||||
moduleDescriptors.toSet(),
|
||||
context.moduleDescriptor.builtIns,
|
||||
mapper,
|
||||
context.moduleDescriptor.namePrefix,
|
||||
topLevelNamePrefix,
|
||||
local = false,
|
||||
objcGenerics = objcGenerics
|
||||
)
|
||||
@@ -87,7 +88,7 @@ internal class ObjCExport(val context: Context, symbolTable: SymbolTable) {
|
||||
setOf(codegen.context.moduleDescriptor),
|
||||
context.moduleDescriptor.builtIns,
|
||||
mapper,
|
||||
context.moduleDescriptor.namePrefix,
|
||||
topLevelNamePrefix,
|
||||
local = false
|
||||
)
|
||||
|
||||
|
||||
+11
-5
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.backend.konan.objcexport
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.findSourceFile
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.cKeywords
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isArray
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isInterface
|
||||
@@ -78,13 +79,13 @@ interface ObjCExportNamer {
|
||||
}
|
||||
|
||||
fun createNamer(moduleDescriptor: ModuleDescriptor,
|
||||
topLevelNamePrefix: String = moduleDescriptor.namePrefix): ObjCExportNamer =
|
||||
topLevelNamePrefix: String): ObjCExportNamer =
|
||||
createNamer(moduleDescriptor, emptyList(), topLevelNamePrefix)
|
||||
|
||||
fun createNamer(
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
exportedDependencies: List<ModuleDescriptor>,
|
||||
topLevelNamePrefix: String = moduleDescriptor.namePrefix
|
||||
topLevelNamePrefix: String
|
||||
): ObjCExportNamer = ObjCExportNamerImpl(
|
||||
(exportedDependencies + moduleDescriptor).toSet(),
|
||||
moduleDescriptor.builtIns,
|
||||
@@ -270,7 +271,7 @@ internal class ObjCExportNamerImpl(
|
||||
get() = topLevelNamePrefix
|
||||
|
||||
override fun getAdditionalPrefix(module: ModuleDescriptor): String? =
|
||||
if (module in moduleDescriptors) null else module.namePrefix
|
||||
if (module in moduleDescriptors) null else module.objCExportAdditionalNamePrefix
|
||||
|
||||
override val objcGenerics: Boolean
|
||||
get() = objcGenerics
|
||||
@@ -900,11 +901,13 @@ private fun ObjCExportMapper.canHaveSameName(first: PropertyDescriptor, second:
|
||||
return bridgePropertyType(first) == bridgePropertyType(second)
|
||||
}
|
||||
|
||||
internal val ModuleDescriptor.namePrefix: String get() {
|
||||
internal val ModuleDescriptor.objCExportAdditionalNamePrefix: String get() {
|
||||
if (this.isNativeStdlib()) return "Kotlin"
|
||||
|
||||
val fullPrefix = when(val module = this.klibModuleOrigin) {
|
||||
CurrentKlibModuleOrigin, SyntheticModulesOrigin ->
|
||||
CurrentKlibModuleOrigin ->
|
||||
error("expected deserialized module, got $this (origin = $module)")
|
||||
SyntheticModulesOrigin ->
|
||||
this.name.asString().let { it.substring(1, it.lastIndex) }
|
||||
is DeserializedKlibModuleOrigin ->
|
||||
module.library.let { it.shortName ?: it.uniqueName }
|
||||
@@ -913,6 +916,9 @@ internal val ModuleDescriptor.namePrefix: String get() {
|
||||
return abbreviate(fullPrefix)
|
||||
}
|
||||
|
||||
internal val Context.objCExportTopLevelNamePrefix: String
|
||||
get() = abbreviate(config.fullExportedNamePrefix)
|
||||
|
||||
fun abbreviate(name: String): String {
|
||||
val normalizedName = name
|
||||
.replaceFirstChar(Char::uppercaseChar)
|
||||
|
||||
Reference in New Issue
Block a user