@@ -120,9 +120,7 @@ def Shutdown(self):
120
120
'Can not shut down the simulator in state CREATING.' )
121
121
logging .info ('Shutting down simulator %s.' , self .simulator_id )
122
122
try :
123
- subprocess .check_output (
124
- ['xcrun' , 'simctl' , 'shutdown' , self .simulator_id ],
125
- stderr = subprocess .STDOUT )
123
+ _RunSimctlCommand (['xcrun' , 'simctl' , 'shutdown' , self .simulator_id ])
126
124
except subprocess .CalledProcessError as e :
127
125
if 'Unable to shutdown device in current state: Shutdown' in e .output :
128
126
logging .info ('Simulator %s has already shut down.' , self .simulator_id )
@@ -147,7 +145,7 @@ def Delete(self):
147
145
'Can only delete the simulator with state SHUTDOWN. The current '
148
146
'state of simulator %s is %s.' % (self ._simulator_id , sim_state ))
149
147
try :
150
- subprocess . check_call (['xcrun' , 'simctl' , 'delete' , self .simulator_id ])
148
+ _RunSimctlCommand (['xcrun' , 'simctl' , 'delete' , self .simulator_id ])
151
149
except subprocess .CalledProcessError as e :
152
150
raise ios_errors .SimError (
153
151
'Failed to delete simulator %s: %s' % (self .simulator_id , e .output ))
@@ -185,9 +183,9 @@ def GetAppDocumentsPath(self, app_bundle_id):
185
183
"""Gets the path of the app's Documents directory."""
186
184
if xcode_info_util .GetXcodeVersionNumber () >= 830 :
187
185
try :
188
- app_data_container = subprocess . check_output (
186
+ app_data_container = _RunSimctlCommand (
189
187
['xcrun' , 'simctl' , 'get_app_container' , self ._simulator_id ,
190
- app_bundle_id , 'data' ]). strip ()
188
+ app_bundle_id , 'data' ])
191
189
return os .path .join (app_data_container , 'Documents' )
192
190
except subprocess .CalledProcessError as e :
193
191
raise ios_errors .SimError (
@@ -313,8 +311,8 @@ def CreateNewSimulator(device_type=None, os_version=None, name=None):
313
311
name , os_type , os_version , device_type )
314
312
for i in range (0 , _SIM_OPERATION_MAX_ATTEMPTS ):
315
313
try :
316
- new_simulator_id = subprocess . check_output (
317
- ['xcrun' , 'simctl' , 'create' , name , device_type , runtime_id ]). strip ()
314
+ new_simulator_id = _RunSimctlCommand (
315
+ ['xcrun' , 'simctl' , 'create' , name , device_type , runtime_id ])
318
316
except subprocess .CalledProcessError as e :
319
317
raise ios_errors .SimError (
320
318
'Failed to create simulator: %s' % e .output )
@@ -371,8 +369,7 @@ def GetSupportedSimDeviceTypes(os_type=None):
371
369
#
372
370
# See more examples in testdata/simctl_list_devicetypes.json
373
371
sim_types_infos_json = ast .literal_eval (
374
- subprocess .check_output (
375
- ('xcrun' , 'simctl' , 'list' , 'devicetypes' , '-j' )))
372
+ _RunSimctlCommand (('xcrun' , 'simctl' , 'list' , 'devicetypes' , '-j' )))
376
373
sim_types = []
377
374
for sim_types_info in sim_types_infos_json ['devicetypes' ]:
378
375
sim_type = sim_types_info ['name' ]
@@ -438,8 +435,7 @@ def GetSupportedSimOsVersions(os_type=ios_constants.OS.IOS):
438
435
#
439
436
# See more examples in testdata/simctl_list_runtimes.json
440
437
sim_runtime_infos_json = ast .literal_eval (
441
- subprocess .check_output (
442
- ('xcrun' , 'simctl' , 'list' , 'runtimes' , '-j' )))
438
+ _RunSimctlCommand (('xcrun' , 'simctl' , 'list' , 'runtimes' , '-j' )))
443
439
sim_versions = []
444
440
for sim_runtime_info in sim_runtime_infos_json ['runtimes' ]:
445
441
# Normally, the json does not contain unavailable runtimes. To be safe,
@@ -610,3 +606,14 @@ def IsXctestFailedToLaunchOnSim(sim_sys_log):
610
606
"""
611
607
pattern = re .compile (_PATTERN_XCTEST_PROCESS_CRASH_ON_SIM )
612
608
return pattern .search (sim_sys_log ) is not None
609
+
610
+
611
+ def _RunSimctlCommand (command ):
612
+ """Runs simctl command."""
613
+ for i in range (2 ):
614
+ try :
615
+ return subprocess .check_output (command , stderr = subprocess .STDOUT ).strip ()
616
+ except subprocess .CalledProcessError as e :
617
+ if i == 0 and ios_constants .CORESIMULATOR_INTERRUPTED_ERROR in e .output :
618
+ continue
619
+ raise e
0 commit comments