@@ -110,6 +110,10 @@ bool CheckError(MCError err)
110110
111111// //////////////////////////////////////////////////////////////////////////////
112112
113+ // MM-2014-10-07: [[ Bug 13584 ]] The choosen sim runtime, does a similar job to s_simulator_system_root.
114+ // Ensures we launch the correct simulator version.
115+ SimRuntime * s_simulator_runtime;
116+
113117// the currently set simulator root, corresponding to a specific version of the
114118// iPhone SDK
115119DTiPhoneSimulatorSystemRoot *s_simulator_system_root = nil ;
@@ -162,25 +166,55 @@ bool revIPhoneListSimulatorSDKs(MCVariableRef *argv, uint32_t argc, MCVariableRe
162166 return t_success;
163167}
164168
165- static bool fetch_named_simulator_root (const char *p_display_name, DTiPhoneSimulatorSystemRoot *&r_root)
166- {
167- DTiPhoneSimulatorSystemRoot *t_root = nil ;
168- NSArray *t_knownroots;
169- t_knownroots = [s_simulator_proxy getKnownRoots ];
170- NSString *t_sdk_string = [NSString stringWithCString: p_display_name encoding: NSMacOSRomanStringEncoding];
171- for (DTiPhoneSimulatorSystemRoot *t_candidate in t_knownroots)
169+ // MM-2014-10-07: [[ Bug 13584 ]] Also return the SimRuntime where applicable.
170+ static bool fetch_named_simulator_root (const char *p_display_name, DTiPhoneSimulatorSystemRoot *&r_root, SimRuntime *&r_runtime)
171+ {
172+ DTiPhoneSimulatorSystemRoot *t_root;
173+ t_root = nil ;
174+ SimRuntime *t_runtime;
175+ t_runtime = nil ;
176+
177+ NSString *t_sdk_string;
178+ t_sdk_string = [NSString stringWithCString: p_display_name encoding: NSMacOSRomanStringEncoding];
179+
180+ NSArray *t_runtimes;
181+ t_runtimes = [s_simulator_proxy getSimRuntimes ];
182+
183+ if (t_runtimes != nil )
172184 {
173- if ([[t_candidate sdkDisplayName ] caseInsensitiveCompare: t_sdk_string] == NSOrderedSame ||
174- [[t_candidate sdkVersion ] caseInsensitiveCompare: t_sdk_string] == NSOrderedSame ||
175- [[t_candidate sdkRootPath ] caseInsensitiveCompare: t_sdk_string] == NSOrderedSame)
185+ for (SimRuntime *t_candidate in t_runtimes)
186+ {
187+ if ([[t_candidate name ] caseInsensitiveCompare: t_sdk_string] == NSOrderedSame ||
188+ [[t_candidate identifier ] caseInsensitiveCompare: t_sdk_string] == NSOrderedSame ||
189+ [[t_candidate root ] caseInsensitiveCompare: t_sdk_string] == NSOrderedSame ||
190+ [[t_candidate versionString ] caseInsensitiveCompare: t_sdk_string] == NSOrderedSame)
191+ {
192+ t_runtime = t_candidate;
193+ t_root = [s_simulator_proxy getRootWithSimRuntime: t_runtime];
194+ break ;
195+ }
196+ }
197+ }
198+ else
199+ {
200+ NSArray *t_knownroots;
201+ t_knownroots = [s_simulator_proxy getKnownRoots ];
202+ for (DTiPhoneSimulatorSystemRoot *t_candidate in t_knownroots)
176203 {
177- t_root = t_candidate;
178- break ;
204+ if ([[t_candidate sdkDisplayName ] caseInsensitiveCompare: t_sdk_string] == NSOrderedSame ||
205+ [[t_candidate sdkVersion ] caseInsensitiveCompare: t_sdk_string] == NSOrderedSame ||
206+ [[t_candidate sdkRootPath ] caseInsensitiveCompare: t_sdk_string] == NSOrderedSame)
207+ {
208+ t_root = t_candidate;
209+ break ;
210+ }
179211 }
180212 }
213+
181214 if (t_root != nil )
182215 {
183216 r_root = t_root;
217+ r_runtime = t_runtime;
184218 return true ;
185219 }
186220 return false ;
@@ -204,7 +238,10 @@ bool revIPhoneSetSimulatorSDK(MCVariableRef *argv, uint32_t argc, MCVariableRef
204238 s_simulator_proxy == nil )
205239 t_success = Throw (" no toolset" );
206240
207- DTiPhoneSimulatorSystemRoot * t_root = nil ;
241+ DTiPhoneSimulatorSystemRoot * t_root;
242+ t_root = nil ;
243+ SimRuntime *t_runtime;
244+ t_runtime = nil ;
208245 if (t_success)
209246 {
210247 if (argc == 0 )
@@ -217,7 +254,7 @@ bool revIPhoneSetSimulatorSDK(MCVariableRef *argv, uint32_t argc, MCVariableRef
217254 t_success = CheckError (MCVariableFetch (argv[0 ], kMCOptionAsCString , &t_sdk_cstring));
218255 if (t_success)
219256 {
220- t_success = fetch_named_simulator_root (t_sdk_cstring, t_root);
257+ t_success = fetch_named_simulator_root (t_sdk_cstring, t_root, t_runtime );
221258 if (!t_success)
222259 {
223260 t_success = Throw (" iPhone Simulator version not found" );
@@ -236,6 +273,8 @@ bool revIPhoneSetSimulatorSDK(MCVariableRef *argv, uint32_t argc, MCVariableRef
236273 if (t_root != nil )
237274 [t_root retain ];
238275 s_simulator_system_root = t_root;
276+ if (t_runtime != nil )
277+ s_simulator_runtime = t_runtime;
239278 }
240279 if (!t_success)
241280 Catch (result);
@@ -499,7 +538,14 @@ bool revIPhoneLaunchAppInSimulator(MCVariableRef *argv, uint32_t argc, MCVariabl
499538 t_session_config = [s_simulator_proxy newSessionConfig ];
500539
501540 [t_session_config setApplicationToSimulateOnStart: t_app_spec];
541+
502542 [t_session_config setSimulatedSystemRoot: s_simulator_system_root];
543+
544+ // MM-2014-10-07: [[ Bug 13584 ]] As well as setting the sys root, also set the sim runtime where applicable.
545+ // Ensures we launch the correct version of the simulator.
546+ if (s_simulator_runtime != nil && [t_session_config respondsToSelector: @selector (setRuntime: )])
547+ [t_session_config setRuntime: s_simulator_runtime];
548+
503549 [t_session_config setSimulatedApplicationShouldWaitForDebugger: NO ];
504550 [t_session_config setSimulatedApplicationLaunchArgs: [NSArray array ]];
505551 [t_session_config setSimulatedApplicationLaunchEnvironment: [NSDictionary dictionary ]];
@@ -520,6 +566,8 @@ bool revIPhoneLaunchAppInSimulator(MCVariableRef *argv, uint32_t argc, MCVariabl
520566
521567 // MM-2014-09-30: [[ iOS 8 Support ]] For iOS 8, we must choose a device from the set the simulator offers
522568 // in order to launch successfully.
569+ // MM-2014-10-07: [[ Bug 13584 ]] Make sure we choose the device which matches the sim runtime. This ensures
570+ // we launch the correct device when the sim SDK has multiple sim versions installed.
523571 NSArray *t_devices;
524572 t_devices = [s_simulator_proxy getSimDeviceSet ];
525573 if (t_devices != nil )
@@ -547,7 +595,7 @@ bool revIPhoneLaunchAppInSimulator(MCVariableRef *argv, uint32_t argc, MCVariabl
547595 {
548596 NSNumber *t_state;
549597 t_state = [t_dev_plist objectForKey: @" state" ];
550- if (t_state != nil && [t_state intValue ] == 3 )
598+ if (t_state != nil && [t_state intValue ] == 3 && [t_device runtime ] == s_simulator_runtime )
551599 {
552600 t_found_device = true ;
553601 break ;
@@ -559,14 +607,15 @@ bool revIPhoneLaunchAppInSimulator(MCVariableRef *argv, uint32_t argc, MCVariabl
559607 // If the last run device is not suitable or not found, then just choose the first device in the list of the desired type.
560608 if (!t_found_device)
561609 for (t_device in t_devices)
562- if (t_is_ipad && [[t_device name ] hasPrefix: @" iPad" ] || !t_is_ipad && [[t_device name ] hasPrefix: @" iPhone" ])
610+ if ((t_is_ipad && [[t_device name ] hasPrefix: @" iPad" ] || !t_is_ipad && [[t_device name ] hasPrefix: @" iPhone" ])
611+ && [t_device runtime ] == s_simulator_runtime)
563612 {
564613 t_found_device = true ;
565614 break ;
566615 }
567616
568617 if (t_found_device)
569- t_session_config . device = t_device;
618+ [ t_session_config setDevice: t_device] ;
570619 }
571620 else if ([t_session_config respondsToSelector: @selector (setSimulatedDeviceInfoName: )])
572621 {
0 commit comments