@@ -124,7 +124,7 @@ def Shutdown(self):
124
124
'Can not shut down the simulator in state CREATING.' )
125
125
logging .info ('Shutting down simulator %s.' , self .simulator_id )
126
126
try :
127
- _RunSimctlCommand (['xcrun' , 'simctl' , 'shutdown' , self .simulator_id ])
127
+ RunSimctlCommand (['xcrun' , 'simctl' , 'shutdown' , self .simulator_id ])
128
128
except ios_errors .SimError as e :
129
129
if 'Unable to shutdown device in current state: Shutdown' in str (e ):
130
130
logging .info ('Simulator %s has already shut down.' , self .simulator_id )
@@ -143,13 +143,16 @@ def Delete(self):
143
143
Raises:
144
144
ios_errors.SimError: The simulator's state is not SHUTDOWN.
145
145
"""
146
- sim_state = self .GetSimulatorState ()
147
- if sim_state != ios_constants .SimState .SHUTDOWN :
148
- raise ios_errors .SimError (
149
- 'Can only delete the simulator with state SHUTDOWN. The current '
150
- 'state of simulator %s is %s.' % (self ._simulator_id , sim_state ))
146
+ # In Xcode 9+, simctl can delete Booted simulator. In prior of Xcode 9,
147
+ # we have to shutdown the simulator first before deleting it.
148
+ if xcode_info_util .GetXcodeVersionNumber () < 900 :
149
+ sim_state = self .GetSimulatorState ()
150
+ if sim_state != ios_constants .SimState .SHUTDOWN :
151
+ raise ios_errors .SimError (
152
+ 'Can only delete the simulator with state SHUTDOWN. The current '
153
+ 'state of simulator %s is %s.' % (self ._simulator_id , sim_state ))
151
154
try :
152
- _RunSimctlCommand (['xcrun' , 'simctl' , 'delete' , self .simulator_id ])
155
+ RunSimctlCommand (['xcrun' , 'simctl' , 'delete' , self .simulator_id ])
153
156
except ios_errors .SimError as e :
154
157
raise ios_errors .SimError (
155
158
'Failed to delete simulator %s: %s' % (self .simulator_id , str (e )))
@@ -187,14 +190,14 @@ def GetAppDocumentsPath(self, app_bundle_id):
187
190
"""Gets the path of the app's Documents directory."""
188
191
if xcode_info_util .GetXcodeVersionNumber () >= 830 :
189
192
try :
190
- app_data_container = _RunSimctlCommand (
193
+ app_data_container = RunSimctlCommand (
191
194
['xcrun' , 'simctl' , 'get_app_container' , self ._simulator_id ,
192
195
app_bundle_id , 'data' ])
193
196
return os .path .join (app_data_container , 'Documents' )
194
197
except ios_errors .SimError as e :
195
198
raise ios_errors .SimError (
196
- 'Failed to get data container of the app %s in simulator %s: %s' ,
197
- app_bundle_id , self ._simulator_id , str (e ))
199
+ 'Failed to get data container of the app %s in simulator %s: %s' %
200
+ ( app_bundle_id , self ._simulator_id , str (e ) ))
198
201
199
202
apps_dir = os .path .join (
200
203
self .simulator_root_dir , 'data/Containers/Data/Application' )
@@ -208,13 +211,13 @@ def GetAppDocumentsPath(self, app_bundle_id):
208
211
if current_app_bundle_id == app_bundle_id :
209
212
return os .path .join (apps_dir , sub_dir_name , 'Documents' )
210
213
raise ios_errors .SimError (
211
- 'Failed to get Documents directory of the app %s in simulator %s: %s' ,
212
- app_bundle_id , self ._simulator_id )
214
+ 'Failed to get Documents directory of the app %s in simulator %s' %
215
+ ( app_bundle_id , self ._simulator_id ) )
213
216
214
217
def IsAppInstalled (self , app_bundle_id ):
215
218
"""Checks if the simulator has installed the app with given bundle id."""
216
219
try :
217
- _RunSimctlCommand (
220
+ RunSimctlCommand (
218
221
['xcrun' , 'simctl' , 'get_app_container' , self ._simulator_id ,
219
222
app_bundle_id ])
220
223
return True
@@ -325,7 +328,7 @@ def CreateNewSimulator(device_type=None, os_version=None, name=None):
325
328
name , os_type , os_version , device_type )
326
329
for i in range (0 , _SIM_OPERATION_MAX_ATTEMPTS ):
327
330
try :
328
- new_simulator_id = _RunSimctlCommand (
331
+ new_simulator_id = RunSimctlCommand (
329
332
['xcrun' , 'simctl' , 'create' , name , device_type , runtime_id ])
330
333
except ios_errors .SimError as e :
331
334
raise ios_errors .SimError (
@@ -383,7 +386,7 @@ def GetSupportedSimDeviceTypes(os_type=None):
383
386
#
384
387
# See more examples in testdata/simctl_list_devicetypes.json
385
388
sim_types_infos_json = json .loads (
386
- _RunSimctlCommand (('xcrun' , 'simctl' , 'list' , 'devicetypes' , '-j' )))
389
+ RunSimctlCommand (('xcrun' , 'simctl' , 'list' , 'devicetypes' , '-j' )))
387
390
sim_types = []
388
391
for sim_types_info in sim_types_infos_json ['devicetypes' ]:
389
392
sim_type = sim_types_info ['name' ]
@@ -438,7 +441,9 @@ def GetSupportedSimOsVersions(os_type=ios_constants.OS.IOS):
438
441
# {
439
442
# "runtimes" : [
440
443
# {
441
- # "bundlePath" : "\/Applications\/Xcode10.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/Runtimes\/iOS.simruntime",
444
+ # "bundlePath" : "\/Applications\/Xcode10.app\/Contents\/Developer\
445
+ # /Platforms\/iPhoneOS.platform\/Developer\/Library\
446
+ # /CoreSimulator\/Profiles\/Runtimes\/iOS.simruntime",
442
447
# "availabilityError" : "",
443
448
# "buildversion" : "16A366",
444
449
# "availability" : "(available)",
@@ -451,7 +456,7 @@ def GetSupportedSimOsVersions(os_type=ios_constants.OS.IOS):
451
456
# See more examples in testdata/simctl_list_runtimes.json
452
457
xcode_version_num = xcode_info_util .GetXcodeVersionNumber ()
453
458
sim_runtime_infos_json = json .loads (
454
- _RunSimctlCommand (('xcrun' , 'simctl' , 'list' , 'runtimes' , '-j' )))
459
+ RunSimctlCommand (('xcrun' , 'simctl' , 'list' , 'runtimes' , '-j' )))
455
460
sim_versions = []
456
461
for sim_runtime_info in sim_runtime_infos_json ['runtimes' ]:
457
462
# Normally, the json does not contain unavailable runtimes. To be safe,
@@ -501,7 +506,7 @@ def GetLastSupportedSimOsVersion(os_type=ios_constants.OS.IOS,
501
506
supported_os_versions = GetSupportedSimOsVersions (os_type )
502
507
if not supported_os_versions :
503
508
raise ios_errors .SimError (
504
- 'Can not find supported OS version of %s.' , os_type )
509
+ 'Can not find supported OS version of %s.' % os_type )
505
510
if not device_type :
506
511
return supported_os_versions [- 1 ]
507
512
@@ -648,7 +653,7 @@ def IsCoreSimulatorCrash(sim_sys_log):
648
653
return pattern .search (sim_sys_log ) is not None
649
654
650
655
651
- def _RunSimctlCommand (command ):
656
+ def RunSimctlCommand (command ):
652
657
"""Runs simctl command."""
653
658
for i in range (_SIMCTL_MAX_ATTEMPTS ):
654
659
process = subprocess .Popen (
0 commit comments