Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Reference libXCTestBundleInject.dylib only if it exists (MobileNative…
Browse files Browse the repository at this point in the history
…Foundation#460)

App will crash if this "optional" dylib does not exist in the host app bundle. Fixing it by making it truly optional.
  • Loading branch information
RainNapper authored Oct 9, 2020
1 parent 26a3761 commit db09487
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions bp/src/SimulatorHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@ + (NSDictionary *)appLaunchEnvironmentWithBundleID:(NSString *)hostBundleID
NSString *hostAppExecPath = [SimulatorHelper executablePathforPath:config.appBundlePath];
NSString *hostAppPath = [hostAppExecPath stringByDeletingLastPathComponent];
NSString *testSimulatorFrameworkPath = [hostAppPath stringByDeletingLastPathComponent];
NSString *libXCTestBundleInject = [[hostAppPath stringByAppendingPathComponent:@"Frameworks"] stringByAppendingPathComponent:@"libXCTestBundleInject.dylib"];
NSString *libXCTestBundleInjectPath = [[hostAppPath stringByAppendingPathComponent:@"Frameworks"] stringByAppendingPathComponent:@"libXCTestBundleInject.dylib"];
NSString *libXCTestBundleInjectValue = libXCTestBundleInjectPath;
if (![NSFileManager.defaultManager fileExistsAtPath:libXCTestBundleInjectPath]) {
[BPUtils printInfo:DEBUGINFO withString:@"Not injecting libXCTestBundleInject dylib because it was not found in the app host bundle at path: %@", libXCTestBundleInjectValue];
libXCTestBundleInjectValue = @"";
}
NSMutableDictionary<NSString *, NSString *> *environment = [@{
@"DYLD_FALLBACK_FRAMEWORK_PATH" : [NSString stringWithFormat:@"%@/Library/Frameworks:%@/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks", config.xcodePath, config.xcodePath],
@"DYLD_FALLBACK_LIBRARY_PATH" : [NSString stringWithFormat:@"%@/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib", config.xcodePath],
@"DYLD_INSERT_LIBRARIES" : libXCTestBundleInject,
@"DYLD_INSERT_LIBRARIES" : libXCTestBundleInjectValue,
@"DYLD_LIBRARY_PATH" : [NSString stringWithFormat:@"%@/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks", config.xcodePath],
@"DYLD_ROOT_PATH" : [NSString stringWithFormat:@"%@/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot", config.xcodePath],
@"NSUnbufferedIO" : @"1",
Expand Down

0 comments on commit db09487

Please sign in to comment.