|
| 1 | +// Check that Objective-C is able to use a resilient class stub emitted |
| 2 | +// by the Swift compiler. |
| 3 | + |
| 4 | +// RUN: %empty-directory(%t) |
| 5 | +// RUN: %target-build-swift -emit-library -emit-module -o %t/libfirst.dylib -emit-objc-header-path %t/first.h %S/Inputs/class-stubs-weak/first.swift -Xlinker -install_name -Xlinker @executable_path/libfirst.dylib -enable-library-evolution |
| 6 | +// RUN: %target-build-swift -emit-library -o %t/libsecond.dylib -emit-objc-header-path %t/second.h -I %t %S/Inputs/class-stubs-weak/second.swift -Xlinker -install_name -Xlinker @executable_path/libsecond.dylib -lfirst -L %t -Xfrontend -enable-resilient-objc-class-stubs -DBEFORE |
| 7 | +// RUN: cp %S/Inputs/class-stubs-weak/module.map %t/ |
| 8 | +// RUN: xcrun %clang %s -I %t -L %t -fmodules -fobjc-arc -o %t/main -lfirst -lsecond -Wl,-U,_objc_loadClassref |
| 9 | + |
| 10 | +// Now rebuild the library, omitting the weak-exported class |
| 11 | +// RUN: %target-build-swift -emit-library -o %t/libsecond.dylib -I %t %S/Inputs/class-stubs-weak/second.swift -Xlinker -install_name -Xlinker @executable_path/libsecond.dylib -lfirst -L %t -Xfrontend -enable-resilient-objc-class-stubs |
| 12 | + |
| 13 | +// RUN: %target-codesign %t/main %t/libfirst.dylib %t/libsecond.dylib |
| 14 | +// RUN: %target-run %t/main %t/libfirst.dylib %t/libsecond.dylib |
| 15 | + |
| 16 | +// REQUIRES: executable_test |
| 17 | +// REQUIRES: objc_interop |
| 18 | + |
| 19 | +#import <dlfcn.h> |
| 20 | +#import <stdio.h> |
| 21 | +#import "second.h" |
| 22 | + |
| 23 | +@implementation DerivedClass (MyCategory) |
| 24 | + |
| 25 | +- (int)instanceMethod { |
| 26 | + return [super instanceMethod] + 1; |
| 27 | +} |
| 28 | + |
| 29 | ++ (int)classMethod { |
| 30 | + return [super classMethod] + 1; |
| 31 | +} |
| 32 | + |
| 33 | +@end |
| 34 | + |
| 35 | +int main(int argc, const char * const argv[]) { |
| 36 | + // Only test the new behavior on a new enough libobjc. |
| 37 | + if (!dlsym(RTLD_NEXT, "_objc_loadClassref")) { |
| 38 | + fprintf(stderr, "skipping evolution tests; OS too old\n"); |
| 39 | + return EXIT_SUCCESS; |
| 40 | + } |
| 41 | + |
| 42 | + Class cls = [DerivedClass class]; |
| 43 | + if (cls) { |
| 44 | + printf("Class is not null"); |
| 45 | + return EXIT_FAILURE; |
| 46 | + } |
| 47 | + |
| 48 | + printf("Class is null"); |
| 49 | + return EXIT_SUCCESS; |
| 50 | +} |
0 commit comments