@@ -26,6 +26,39 @@ def __get_simulators():
26
26
Log .error ('Failed to parse json ' + os .linesep + result .output )
27
27
return json .loads ('{}' )
28
28
29
+ # noinspection PyBroadException
30
+ @staticmethod
31
+ def get_max_runtime_version (version ):
32
+ # Parse runtimes
33
+ result = Simctl .run_simctl_command (command = 'list --json runtimes' )
34
+ runtimes = None
35
+ try :
36
+ runtimes = json .loads (result .output )
37
+ except ValueError :
38
+ Log .error ('Failed to parse json ' + os .linesep + result .output )
39
+ return json .loads ('{}' )
40
+
41
+ # Get max runtime version
42
+ exact_sdk_version = None
43
+ for runtime in runtimes ['runtimes' ]:
44
+ if str (version ) in runtime ['version' ] and runtime ['name' ].startswith ('iOS' ) and runtime ['isAvailable' ]:
45
+ exact_sdk_version = runtime ['version' ]
46
+ if exact_sdk_version is None :
47
+ raise Exception ('Can not find iOS SDK {0}' .format (version ))
48
+
49
+ return exact_sdk_version
50
+
51
+ @staticmethod
52
+ def __get_devices_by_version (version ):
53
+ exact_sdk_version = Simctl .get_max_runtime_version (version )
54
+ devices = Simctl .__get_simulators ()['devices' ]
55
+ placeholder = 'iOS {0}'
56
+ device_key = placeholder .format (exact_sdk_version )
57
+ if device_key not in devices :
58
+ placeholder_dash = placeholder .format (exact_sdk_version ).replace (' ' , '-' ).replace ('.' , '-' )
59
+ device_key = 'com.apple.CoreSimulator.SimRuntime.{0}' .format (placeholder_dash )
60
+ return devices [device_key ]
61
+
29
62
@staticmethod
30
63
def __get_availability (sim ):
31
64
available = False
@@ -46,14 +79,7 @@ def start(simulator_info):
46
79
47
80
@staticmethod
48
81
def is_running (simulator_info ):
49
- devices = Simctl .__get_simulators ()['devices' ]
50
- placeholder = 'iOS {0}'
51
- device_key = placeholder .format (simulator_info .sdk )
52
- if device_key not in devices :
53
- placeholder_dash = placeholder .format (simulator_info .sdk ).replace (' ' , '-' ).replace ('.' , '-' )
54
- device_key = 'com.apple.CoreSimulator.SimRuntime.{0}' .format (placeholder_dash )
55
- sims = devices [device_key ]
56
- for sim in sims :
82
+ for sim in Simctl .__get_devices_by_version (simulator_info .sdk ):
57
83
if sim ['name' ] == simulator_info .name and sim ['state' ] == 'Booted' :
58
84
# simctl returns Booted too early, so we will wait some untill service is started
59
85
simulator_info .id = str (sim ['udid' ])
@@ -85,14 +111,7 @@ def wait_until_boot(simulator_info, timeout=180):
85
111
86
112
@staticmethod
87
113
def is_available (simulator_info ):
88
- devices = Simctl .__get_simulators ()['devices' ]
89
- placeholder = 'iOS {0}'
90
- device_key = placeholder .format (simulator_info .sdk )
91
- if device_key not in devices :
92
- placeholder_dash = placeholder .format (simulator_info .sdk ).replace (' ' , '-' ).replace ('.' , '-' )
93
- device_key = 'com.apple.CoreSimulator.SimRuntime.{0}' .format (placeholder_dash )
94
- sims = devices [device_key ]
95
- for sim in sims :
114
+ for sim in Simctl .__get_devices_by_version (simulator_info .sdk ):
96
115
if sim ['name' ] == simulator_info .name and Simctl .__get_availability (sim ):
97
116
simulator_info .id = str (sim ['udid' ])
98
117
return simulator_info
0 commit comments