[ObjC export] Provide basic support for short klib names
This commit is contained in:
committed by
Ilya Matveev
parent
ffe8ce5524
commit
92228d44af
+1
-1
@@ -112,7 +112,7 @@ open class CInteropArguments(argParser: ArgParser =
|
|||||||
|
|
||||||
val shortModuleName by argParser.option(ArgType.String,
|
val shortModuleName by argParser.option(ArgType.String,
|
||||||
fullName = SHORT_MODULE_NAME,
|
fullName = SHORT_MODULE_NAME,
|
||||||
description = "A short name used to denote this library in the IDE and during Objective-C export"
|
description = "A short name used to denote this library in the IDE"
|
||||||
)
|
)
|
||||||
|
|
||||||
val moduleName by argParser.option(ArgType.String,
|
val moduleName by argParser.option(ArgType.String,
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
|||||||
@Argument(
|
@Argument(
|
||||||
value = "-Xshort-module-name",
|
value = "-Xshort-module-name",
|
||||||
valueDescription = "<name>",
|
valueDescription = "<name>",
|
||||||
description = "A short name used to denote this library in the IDE and during Objective-C export"
|
description = "A short name used to denote this library in the IDE and in a generated Objective-C header"
|
||||||
)
|
)
|
||||||
var shortModuleName: String? = null
|
var shortModuleName: String? = null
|
||||||
|
|
||||||
|
|||||||
+11
-1
@@ -11,7 +11,10 @@ import org.jetbrains.kotlin.backend.konan.descriptors.isInterface
|
|||||||
import org.jetbrains.kotlin.descriptors.konan.isNativeStdlib
|
import org.jetbrains.kotlin.descriptors.konan.isNativeStdlib
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
|
import org.jetbrains.kotlin.descriptors.konan.*
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
|
import org.jetbrains.kotlin.library.shortName
|
||||||
|
import org.jetbrains.kotlin.library.uniqueName
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -857,7 +860,14 @@ private fun ObjCExportMapper.canHaveSameName(first: PropertyDescriptor, second:
|
|||||||
internal val ModuleDescriptor.namePrefix: String get() {
|
internal val ModuleDescriptor.namePrefix: String get() {
|
||||||
if (this.isNativeStdlib()) return "Kotlin"
|
if (this.isNativeStdlib()) return "Kotlin"
|
||||||
|
|
||||||
return abbreviate(this.name.asString().let { it.substring(1, it.lastIndex) })
|
val fullPrefix = when(val module = this.klibModuleOrigin) {
|
||||||
|
CurrentKlibModuleOrigin, SyntheticModulesOrigin ->
|
||||||
|
this.name.asString().let { it.substring(1, it.lastIndex) }
|
||||||
|
is DeserializedKlibModuleOrigin ->
|
||||||
|
module.library.let { it.shortName ?: it.uniqueName }
|
||||||
|
}
|
||||||
|
|
||||||
|
return abbreviate(fullPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun abbreviate(name: String): String {
|
internal fun abbreviate(name: String): String {
|
||||||
|
|||||||
@@ -3894,14 +3894,29 @@ if (isAppleTarget(project)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
konanArtifacts {
|
konanArtifacts {
|
||||||
|
def libraryName = frameworkName + "Library"
|
||||||
|
library(libraryName, targets: [target.name]) {
|
||||||
|
srcDir "objcexport/library"
|
||||||
|
artifactName "test-library"
|
||||||
|
|
||||||
|
extraOpts "-Xshort-module-name=MyLibrary"
|
||||||
|
extraOpts "-module-name", "org.jetbrains.kotlin.native.test-library"
|
||||||
|
}
|
||||||
|
|
||||||
framework(frameworkName, targets: [target.name]) {
|
framework(frameworkName, targets: [target.name]) {
|
||||||
srcDir 'objcexport'
|
srcFiles fileTree("objcexport") {
|
||||||
|
include "*.kt"
|
||||||
|
}
|
||||||
baseDir dir
|
baseDir dir
|
||||||
|
|
||||||
if (!useCustomDist) {
|
if (!useCustomDist) {
|
||||||
dependsOn ":${target.name}CrossDistRuntime", ':distCompiler'
|
dependsOn ":${target.name}CrossDistRuntime", ':distCompiler'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
libraries {
|
||||||
|
artifact libraryName
|
||||||
|
}
|
||||||
|
|
||||||
extraOpts "-Xembed-bitcode-marker"
|
extraOpts "-Xembed-bitcode-marker"
|
||||||
extraOpts "-Xemit-lazy-objc-header=$lazyHeader"
|
extraOpts "-Xemit-lazy-objc-header=$lazyHeader"
|
||||||
extraOpts project.globalTestArgs
|
extraOpts project.globalTestArgs
|
||||||
@@ -3924,14 +3939,29 @@ if (isAppleTarget(project)) {
|
|||||||
final String dir = "$testOutputFramework/$testName"
|
final String dir = "$testOutputFramework/$testName"
|
||||||
|
|
||||||
konanArtifacts {
|
konanArtifacts {
|
||||||
|
def libraryName = frameworkName + "Library"
|
||||||
|
library(libraryName, targets: [target.name]) {
|
||||||
|
srcDir "objcexport/library"
|
||||||
|
artifactName "test-library"
|
||||||
|
|
||||||
|
extraOpts "-Xshort-module-name=MyLibrary"
|
||||||
|
extraOpts "-module-name", "org.jetbrains.kotlin.native.test-library"
|
||||||
|
}
|
||||||
|
|
||||||
framework(frameworkName, targets: [target.name]) {
|
framework(frameworkName, targets: [target.name]) {
|
||||||
srcDir 'objcexport'
|
srcFiles fileTree("objcexport") {
|
||||||
|
include "*.kt"
|
||||||
|
}
|
||||||
baseDir dir
|
baseDir dir
|
||||||
|
|
||||||
if (!useCustomDist) {
|
if (!useCustomDist) {
|
||||||
dependsOn ":${target.name}CrossDistRuntime", ':distCompiler'
|
dependsOn ":${target.name}CrossDistRuntime", ':distCompiler'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
libraries {
|
||||||
|
artifact libraryName
|
||||||
|
}
|
||||||
|
|
||||||
extraOpts "-Xembed-bitcode-marker"
|
extraOpts "-Xembed-bitcode-marker"
|
||||||
extraOpts "-Xstatic-framework"
|
extraOpts "-Xstatic-framework"
|
||||||
extraOpts project.globalTestArgs
|
extraOpts project.globalTestArgs
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
package coroutines
|
package coroutines
|
||||||
|
|
||||||
import kotlin.coroutines.*
|
import kotlin.coroutines.*
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
import Kt
|
import Kt
|
||||||
|
|
||||||
private func testCallSimple() throws {
|
private func testCallSimple() throws {
|
||||||
|
|||||||
@@ -204,6 +204,14 @@ __attribute__((swift_name("GH4002Argument")))
|
|||||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||||
@end;
|
@end;
|
||||||
|
|
||||||
|
__attribute__((objc_subclassing_restricted))
|
||||||
|
__attribute__((swift_name("LibraryKt")))
|
||||||
|
@interface KtLibraryKt : KtBase
|
||||||
|
+ (NSString *)readDataFromLibraryClassInput:(KtA *)input __attribute__((swift_name("readDataFromLibraryClass(input:)")));
|
||||||
|
+ (NSString *)readDataFromLibraryInterfaceInput:(id<KtI>)input __attribute__((swift_name("readDataFromLibraryInterface(input:)")));
|
||||||
|
+ (NSString *)readDataFromLibraryEnumInput:(KtE *)input __attribute__((swift_name("readDataFromLibraryEnum(input:)")));
|
||||||
|
@end;
|
||||||
|
|
||||||
__attribute__((objc_subclassing_restricted))
|
__attribute__((objc_subclassing_restricted))
|
||||||
__attribute__((swift_name("DelegateClass")))
|
__attribute__((swift_name("DelegateClass")))
|
||||||
@interface KtDelegateClass : KtBase <KtKotlinReadWriteProperty>
|
@interface KtDelegateClass : KtBase <KtKotlinReadWriteProperty>
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
package gh4002
|
package gh4002
|
||||||
|
|
||||||
open class GH4002ArgumentBase
|
open class GH4002ArgumentBase
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
import Kt
|
import Kt
|
||||||
|
|
||||||
// See https://github.com/JetBrains/kotlin-native/issues/4002
|
// See https://github.com/JetBrains/kotlin-native/issues/4002
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package library
|
||||||
|
|
||||||
|
fun readDataFromLibraryClass(input: A): String {
|
||||||
|
return input.data
|
||||||
|
}
|
||||||
|
|
||||||
|
fun readDataFromLibraryInterface(input: I): String {
|
||||||
|
return input.data
|
||||||
|
}
|
||||||
|
|
||||||
|
fun readDataFromLibraryEnum(input: E): String {
|
||||||
|
return input.data
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Kt
|
||||||
|
|
||||||
|
func testAccessClassFromLibraryWithShortName() throws {
|
||||||
|
|
||||||
|
let object: MyLibraryA = MyLibraryA(data: "Data from Class")
|
||||||
|
let interface: MyLibraryI = MyLibraryA(data: "Data from Interface")
|
||||||
|
let enumObject: MyLibraryE = MyLibraryE.b
|
||||||
|
|
||||||
|
|
||||||
|
let dataFromClass = LibraryKt.readDataFromLibraryClass(input: object)
|
||||||
|
let dataFromInterface = LibraryKt.readDataFromLibraryInterface(input: interface)
|
||||||
|
let dataFromEnum = LibraryKt.readDataFromLibraryEnum(input: enumObject)
|
||||||
|
|
||||||
|
try assertEquals(actual: dataFromClass, expected: "Data from Class")
|
||||||
|
try assertEquals(actual: dataFromInterface, expected: "Data from Interface")
|
||||||
|
try assertEquals(actual: dataFromEnum, expected: "Enum entry B")
|
||||||
|
}
|
||||||
|
|
||||||
|
class LibraryTests : SimpleTestProvider {
|
||||||
|
override init() {
|
||||||
|
super.init()
|
||||||
|
|
||||||
|
test("testAccessClassFromLibraryWithShortName", testAccessClassFromLibraryWithShortName)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package library
|
||||||
|
|
||||||
|
interface I {
|
||||||
|
val data: String
|
||||||
|
}
|
||||||
|
|
||||||
|
class A(override val data: String): I
|
||||||
|
|
||||||
|
enum class E(val data: String) {
|
||||||
|
A("Enum entry A"),
|
||||||
|
B("Enum entry B"),
|
||||||
|
C("Enum entry C")
|
||||||
|
}
|
||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
*
|
* that can be found in the LICENSE file.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|||||||
Reference in New Issue
Block a user