Skip to content

Commit db09487

Browse files
authored
Reference libXCTestBundleInject.dylib only if it exists (#460)
App will crash if this "optional" dylib does not exist in the host app bundle. Fixing it by making it truly optional.
1 parent 26a3761 commit db09487

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

bp/src/SimulatorHelper.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,16 @@ + (NSDictionary *)appLaunchEnvironmentWithBundleID:(NSString *)hostBundleID
6565
NSString *hostAppExecPath = [SimulatorHelper executablePathforPath:config.appBundlePath];
6666
NSString *hostAppPath = [hostAppExecPath stringByDeletingLastPathComponent];
6767
NSString *testSimulatorFrameworkPath = [hostAppPath stringByDeletingLastPathComponent];
68-
NSString *libXCTestBundleInject = [[hostAppPath stringByAppendingPathComponent:@"Frameworks"] stringByAppendingPathComponent:@"libXCTestBundleInject.dylib"];
68+
NSString *libXCTestBundleInjectPath = [[hostAppPath stringByAppendingPathComponent:@"Frameworks"] stringByAppendingPathComponent:@"libXCTestBundleInject.dylib"];
69+
NSString *libXCTestBundleInjectValue = libXCTestBundleInjectPath;
70+
if (![NSFileManager.defaultManager fileExistsAtPath:libXCTestBundleInjectPath]) {
71+
[BPUtils printInfo:DEBUGINFO withString:@"Not injecting libXCTestBundleInject dylib because it was not found in the app host bundle at path: %@", libXCTestBundleInjectValue];
72+
libXCTestBundleInjectValue = @"";
73+
}
6974
NSMutableDictionary<NSString *, NSString *> *environment = [@{
7075
@"DYLD_FALLBACK_FRAMEWORK_PATH" : [NSString stringWithFormat:@"%@/Library/Frameworks:%@/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks", config.xcodePath, config.xcodePath],
7176
@"DYLD_FALLBACK_LIBRARY_PATH" : [NSString stringWithFormat:@"%@/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib", config.xcodePath],
72-
@"DYLD_INSERT_LIBRARIES" : libXCTestBundleInject,
77+
@"DYLD_INSERT_LIBRARIES" : libXCTestBundleInjectValue,
7378
@"DYLD_LIBRARY_PATH" : [NSString stringWithFormat:@"%@/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks", config.xcodePath],
7479
@"DYLD_ROOT_PATH" : [NSString stringWithFormat:@"%@/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot", config.xcodePath],
7580
@"NSUnbufferedIO" : @"1",

0 commit comments

Comments
 (0)