From 7ee2903e157fc9287cef208771053ad0967992e4 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Mon, 26 Feb 2024 08:56:59 +0100 Subject: [PATCH] [ObjCExport] ObjCExportDependenciesHeaderGeneratorTest: Add tests for exported / non exported dependencies KT-65670 --- ...jCExportDependenciesHeaderGeneratorTest.kt | 17 ++ .../exportedAndNotExportedDependency/Foo.kt | 2 +- .../!notExportedDependency.h | 172 ++++++++++++++++++ .../dependencies/notExportedDependency/Foo.kt | 2 + .../{ => org/jetbrains/a}/MyLibraryA.kt | 7 + .../{ => org/jetbrains/b}/MyLibraryB.kt | 7 + 6 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 native/objcexport-header-generator/testData/dependencies/notExportedDependency/!notExportedDependency.h create mode 100644 native/objcexport-header-generator/testData/dependencies/notExportedDependency/Foo.kt rename native/objcexport-header-generator/testDependencies/testLibraryA/src/nativeMain/kotlin/{ => org/jetbrains/a}/MyLibraryA.kt (57%) rename native/objcexport-header-generator/testDependencies/testLibraryB/src/nativeMain/kotlin/{ => org/jetbrains/b}/MyLibraryB.kt (57%) diff --git a/native/objcexport-header-generator/test/org/jetbrains/kotlin/backend/konan/tests/ObjCExportDependenciesHeaderGeneratorTest.kt b/native/objcexport-header-generator/test/org/jetbrains/kotlin/backend/konan/tests/ObjCExportDependenciesHeaderGeneratorTest.kt index 2c5783eb9bd..d3869ddfbf9 100644 --- a/native/objcexport-header-generator/test/org/jetbrains/kotlin/backend/konan/tests/ObjCExportDependenciesHeaderGeneratorTest.kt +++ b/native/objcexport-header-generator/test/org/jetbrains/kotlin/backend/konan/tests/ObjCExportDependenciesHeaderGeneratorTest.kt @@ -52,7 +52,24 @@ class ObjCExportDependenciesHeaderGeneratorTest( doTest(dependenciesDir.resolve("implementIterator")) } + @Test + fun `test - notExportedDependency`() { + doTest( + dependenciesDir.resolve("notExportedDependency"), configuration = HeaderGenerator.Configuration( + frameworkName = "MyApp", + generateBaseDeclarationStubs = true, + dependencies = listOf(testLibraryAKlibFile, testLibraryBKlibFile), + ) + ) + } + + /** + * https://youtrack.jetbrains.com/issue/KT-65327/Support-reading-klib-contents-in-Analysis-API + * Requires being able to use AA to iterate over symbols to 'export' the dependency + */ + @Test + @TodoAnalysisApi fun `test - exportedAndNotExportedDependency`() { doTest( dependenciesDir.resolve("exportedAndNotExportedDependency"), configuration = HeaderGenerator.Configuration( diff --git a/native/objcexport-header-generator/testData/dependencies/exportedAndNotExportedDependency/Foo.kt b/native/objcexport-header-generator/testData/dependencies/exportedAndNotExportedDependency/Foo.kt index e5266f3c554..2345466e51d 100644 --- a/native/objcexport-header-generator/testData/dependencies/exportedAndNotExportedDependency/Foo.kt +++ b/native/objcexport-header-generator/testData/dependencies/exportedAndNotExportedDependency/Foo.kt @@ -1,2 +1,2 @@ // LibraryA is exported, LibraryB will just be referenced in this return type */ -fun foo(): MyLibraryB = error("stub") \ No newline at end of file +fun foo(): org.jetbrains.b.MyLibraryB = error("stub") \ No newline at end of file diff --git a/native/objcexport-header-generator/testData/dependencies/notExportedDependency/!notExportedDependency.h b/native/objcexport-header-generator/testData/dependencies/notExportedDependency/!notExportedDependency.h new file mode 100644 index 00000000000..bc6e7f97a57 --- /dev/null +++ b/native/objcexport-header-generator/testData/dependencies/notExportedDependency/!notExportedDependency.h @@ -0,0 +1,172 @@ +#import +#import +#import +#import +#import +#import +#import + +@class MyAppTLAMyLibraryA; + +@protocol MyAppKotlinIterator; + +NS_ASSUME_NONNULL_BEGIN +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wincompatible-property-type" +#pragma clang diagnostic ignored "-Wnullability" + +#pragma push_macro("_Nullable_result") +#if !__has_feature(nullability_nullable_result) +#undef _Nullable_result +#define _Nullable_result _Nullable +#endif + +__attribute__((swift_name("KotlinBase"))) +@interface MyAppBase : NSObject +- (instancetype)init __attribute__((unavailable)); ++ (instancetype)new __attribute__((unavailable)); ++ (void)initialize __attribute__((objc_requires_super)); +@end + +@interface MyAppBase (MyAppBaseCopying) +@end + +__attribute__((swift_name("KotlinMutableSet"))) +@interface MyAppMutableSet : NSMutableSet +@end + +__attribute__((swift_name("KotlinMutableDictionary"))) +@interface MyAppMutableDictionary : NSMutableDictionary +@end + +@interface NSError (NSErrorMyAppKotlinException) +@property (readonly) id _Nullable kotlinException; +@end + +__attribute__((swift_name("KotlinNumber"))) +@interface MyAppNumber : NSNumber +- (instancetype)initWithChar:(char)value __attribute__((unavailable)); +- (instancetype)initWithUnsignedChar:(unsigned char)value __attribute__((unavailable)); +- (instancetype)initWithShort:(short)value __attribute__((unavailable)); +- (instancetype)initWithUnsignedShort:(unsigned short)value __attribute__((unavailable)); +- (instancetype)initWithInt:(int)value __attribute__((unavailable)); +- (instancetype)initWithUnsignedInt:(unsigned int)value __attribute__((unavailable)); +- (instancetype)initWithLong:(long)value __attribute__((unavailable)); +- (instancetype)initWithUnsignedLong:(unsigned long)value __attribute__((unavailable)); +- (instancetype)initWithLongLong:(long long)value __attribute__((unavailable)); +- (instancetype)initWithUnsignedLongLong:(unsigned long long)value __attribute__((unavailable)); +- (instancetype)initWithFloat:(float)value __attribute__((unavailable)); +- (instancetype)initWithDouble:(double)value __attribute__((unavailable)); +- (instancetype)initWithBool:(BOOL)value __attribute__((unavailable)); +- (instancetype)initWithInteger:(NSInteger)value __attribute__((unavailable)); +- (instancetype)initWithUnsignedInteger:(NSUInteger)value __attribute__((unavailable)); ++ (instancetype)numberWithChar:(char)value __attribute__((unavailable)); ++ (instancetype)numberWithUnsignedChar:(unsigned char)value __attribute__((unavailable)); ++ (instancetype)numberWithShort:(short)value __attribute__((unavailable)); ++ (instancetype)numberWithUnsignedShort:(unsigned short)value __attribute__((unavailable)); ++ (instancetype)numberWithInt:(int)value __attribute__((unavailable)); ++ (instancetype)numberWithUnsignedInt:(unsigned int)value __attribute__((unavailable)); ++ (instancetype)numberWithLong:(long)value __attribute__((unavailable)); ++ (instancetype)numberWithUnsignedLong:(unsigned long)value __attribute__((unavailable)); ++ (instancetype)numberWithLongLong:(long long)value __attribute__((unavailable)); ++ (instancetype)numberWithUnsignedLongLong:(unsigned long long)value __attribute__((unavailable)); ++ (instancetype)numberWithFloat:(float)value __attribute__((unavailable)); ++ (instancetype)numberWithDouble:(double)value __attribute__((unavailable)); ++ (instancetype)numberWithBool:(BOOL)value __attribute__((unavailable)); ++ (instancetype)numberWithInteger:(NSInteger)value __attribute__((unavailable)); ++ (instancetype)numberWithUnsignedInteger:(NSUInteger)value __attribute__((unavailable)); +@end + +__attribute__((swift_name("KotlinByte"))) +@interface MyAppByte : MyAppNumber +- (instancetype)initWithChar:(char)value; ++ (instancetype)numberWithChar:(char)value; +@end + +__attribute__((swift_name("KotlinUByte"))) +@interface MyAppUByte : MyAppNumber +- (instancetype)initWithUnsignedChar:(unsigned char)value; ++ (instancetype)numberWithUnsignedChar:(unsigned char)value; +@end + +__attribute__((swift_name("KotlinShort"))) +@interface MyAppShort : MyAppNumber +- (instancetype)initWithShort:(short)value; ++ (instancetype)numberWithShort:(short)value; +@end + +__attribute__((swift_name("KotlinUShort"))) +@interface MyAppUShort : MyAppNumber +- (instancetype)initWithUnsignedShort:(unsigned short)value; ++ (instancetype)numberWithUnsignedShort:(unsigned short)value; +@end + +__attribute__((swift_name("KotlinInt"))) +@interface MyAppInt : MyAppNumber +- (instancetype)initWithInt:(int)value; ++ (instancetype)numberWithInt:(int)value; +@end + +__attribute__((swift_name("KotlinUInt"))) +@interface MyAppUInt : MyAppNumber +- (instancetype)initWithUnsignedInt:(unsigned int)value; ++ (instancetype)numberWithUnsignedInt:(unsigned int)value; +@end + +__attribute__((swift_name("KotlinLong"))) +@interface MyAppLong : MyAppNumber +- (instancetype)initWithLongLong:(long long)value; ++ (instancetype)numberWithLongLong:(long long)value; +@end + +__attribute__((swift_name("KotlinULong"))) +@interface MyAppULong : MyAppNumber +- (instancetype)initWithUnsignedLongLong:(unsigned long long)value; ++ (instancetype)numberWithUnsignedLongLong:(unsigned long long)value; +@end + +__attribute__((swift_name("KotlinFloat"))) +@interface MyAppFloat : MyAppNumber +- (instancetype)initWithFloat:(float)value; ++ (instancetype)numberWithFloat:(float)value; +@end + +__attribute__((swift_name("KotlinDouble"))) +@interface MyAppDouble : MyAppNumber +- (instancetype)initWithDouble:(double)value; ++ (instancetype)numberWithDouble:(double)value; +@end + +__attribute__((swift_name("KotlinBoolean"))) +@interface MyAppBoolean : MyAppNumber +- (instancetype)initWithBool:(BOOL)value; ++ (instancetype)numberWithBool:(BOOL)value; +@end + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("FooKt"))) +@interface MyAppFooKt : MyAppBase ++ (MyAppTLAMyLibraryA *)foo __attribute__((swift_name("foo()"))); ++ (id)withIterator __attribute__((swift_name("withIterator()"))); +@end + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("TLAMyLibraryA"))) +@interface MyAppTLAMyLibraryA : MyAppBase +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); ++ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); +- (int32_t)returnInt __attribute__((swift_name("returnInt()"))); +- (MyAppTLAMyLibraryA *)returnMe __attribute__((swift_name("returnMe()"))); +@end + +__attribute__((swift_name("KotlinIterator"))) +@protocol MyAppKotlinIterator +@required +- (BOOL)hasNext __attribute__((swift_name("hasNext()"))); +- (id _Nullable)next __attribute__((swift_name("next()"))); +@end + +#pragma pop_macro("_Nullable_result") +#pragma clang diagnostic pop +NS_ASSUME_NONNULL_END diff --git a/native/objcexport-header-generator/testData/dependencies/notExportedDependency/Foo.kt b/native/objcexport-header-generator/testData/dependencies/notExportedDependency/Foo.kt new file mode 100644 index 00000000000..6f7c3a0a883 --- /dev/null +++ b/native/objcexport-header-generator/testData/dependencies/notExportedDependency/Foo.kt @@ -0,0 +1,2 @@ +fun foo(): org.jetbrains.a.MyLibraryA = error("stub") +fun withIterator(): Iterator = error("stub") \ No newline at end of file diff --git a/native/objcexport-header-generator/testDependencies/testLibraryA/src/nativeMain/kotlin/MyLibraryA.kt b/native/objcexport-header-generator/testDependencies/testLibraryA/src/nativeMain/kotlin/org/jetbrains/a/MyLibraryA.kt similarity index 57% rename from native/objcexport-header-generator/testDependencies/testLibraryA/src/nativeMain/kotlin/MyLibraryA.kt rename to native/objcexport-header-generator/testDependencies/testLibraryA/src/nativeMain/kotlin/org/jetbrains/a/MyLibraryA.kt index 49098714699..7f6a4167f89 100644 --- a/native/objcexport-header-generator/testDependencies/testLibraryA/src/nativeMain/kotlin/MyLibraryA.kt +++ b/native/objcexport-header-generator/testDependencies/testLibraryA/src/nativeMain/kotlin/org/jetbrains/a/MyLibraryA.kt @@ -1,4 +1,11 @@ +/* + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + @file:Suppress("unused") + +package org.jetbrains.a /* * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. diff --git a/native/objcexport-header-generator/testDependencies/testLibraryB/src/nativeMain/kotlin/MyLibraryB.kt b/native/objcexport-header-generator/testDependencies/testLibraryB/src/nativeMain/kotlin/org/jetbrains/b/MyLibraryB.kt similarity index 57% rename from native/objcexport-header-generator/testDependencies/testLibraryB/src/nativeMain/kotlin/MyLibraryB.kt rename to native/objcexport-header-generator/testDependencies/testLibraryB/src/nativeMain/kotlin/org/jetbrains/b/MyLibraryB.kt index 18a8ba3b049..aadcfdd2418 100644 --- a/native/objcexport-header-generator/testDependencies/testLibraryB/src/nativeMain/kotlin/MyLibraryB.kt +++ b/native/objcexport-header-generator/testDependencies/testLibraryB/src/nativeMain/kotlin/org/jetbrains/b/MyLibraryB.kt @@ -1,9 +1,16 @@ +/* + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + @file:Suppress("unused") /* * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ +package org.jetbrains.b + class MyLibraryB { fun returnInt(): Int = 42 fun returnMe(): MyLibraryB = this