From be1596a08f3b7d182e3f993f187c2fa579586373 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 20 Jul 2021 19:58:58 -0400 Subject: [PATCH] Filter out unavailable via simctl --- script/tool/lib/src/common/xcode.dart | 9 ++- script/tool/test/common/xcode_test.dart | 79 +---------------------- script/tool/test/xctest_command_test.dart | 11 +++- 3 files changed, 15 insertions(+), 84 deletions(-) diff --git a/script/tool/lib/src/common/xcode.dart b/script/tool/lib/src/common/xcode.dart index 1176dd5b5984..d6bbae419eda 100644 --- a/script/tool/lib/src/common/xcode.dart +++ b/script/tool/lib/src/common/xcode.dart @@ -91,7 +91,10 @@ class Xcode { final List findSimulatorsArguments = [ 'simctl', 'list', - '--json' + 'devices', + 'runtimes', + 'available', + '--json', ]; final String findSimulatorCompleteCommand = '$_xcRunCommand ${findSimulatorsArguments.join(' ')}'; @@ -141,10 +144,6 @@ class Xcode { // Looking for runtimes, trying to find latest version of device. for (final Map rawDevice in devicesForRuntime.reversed) { final Map device = rawDevice.cast(); - if (device['availabilityError'] != null || - (device['isAvailable'] as bool?) == false) { - continue; - } id = device['udid'] as String?; if (id == null) { continue; diff --git a/script/tool/test/common/xcode_test.dart b/script/tool/test/common/xcode_test.dart index 565a25055bec..7e046a2446c2 100644 --- a/script/tool/test/common/xcode_test.dart +++ b/script/tool/test/common/xcode_test.dart @@ -100,83 +100,6 @@ void main() { expect(await xcode.findBestAvailableIphoneSimulator(), expectedDeviceId); }); - test('skips unavailable devices', () async { - const String expectedDeviceId = '2706BBEB-1E01-403E-A8E9-70E8E5A24774'; - // Note: This uses `dynamic` deliberately, and should not be updated to - // Object, in order to ensure that the code correctly handles this return - // type from JSON decoding. - final Map devices = { - 'runtimes': >[ - { - 'bundlePath': - '/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 13.0.simruntime', - 'buildversion': '17A577', - 'runtimeRoot': - '/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 13.0.simruntime/Contents/Resources/RuntimeRoot', - 'identifier': 'com.apple.CoreSimulator.SimRuntime.iOS-13-0', - 'version': '13.0', - 'isAvailable': true, - 'name': 'iOS 13.0' - }, - { - 'bundlePath': - '/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 13.4.simruntime', - 'buildversion': '17L255', - 'runtimeRoot': - '/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 13.4.simruntime/Contents/Resources/RuntimeRoot', - 'identifier': 'com.apple.CoreSimulator.SimRuntime.iOS-13-4', - 'version': '13.4', - 'isAvailable': true, - 'name': 'iOS 13.4' - }, - { - 'bundlePath': - '/Applications/Xcode_11_7.app/Contents/Developer/Platforms/WatchOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/watchOS.simruntime', - 'buildversion': '17T531', - 'runtimeRoot': - '/Applications/Xcode_11_7.app/Contents/Developer/Platforms/WatchOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/watchOS.simruntime/Contents/Resources/RuntimeRoot', - 'identifier': 'com.apple.CoreSimulator.SimRuntime.watchOS-6-2', - 'version': '6.2.1', - 'isAvailable': true, - 'name': 'watchOS 6.2' - } - ], - 'devices': { - 'com.apple.CoreSimulator.SimRuntime.iOS-13-4': >[ - { - 'dataPath': - '/Users/xxx/Library/Developer/CoreSimulator/Devices/2706BBEB-1E01-403E-A8E9-70E8E5A24774/data', - 'logPath': - '/Users/xxx/Library/Logs/CoreSimulator/2706BBEB-1E01-403E-A8E9-70E8E5A24774', - 'udid': expectedDeviceId, - 'isAvailable': true, - 'deviceTypeIdentifier': - 'com.apple.CoreSimulator.SimDeviceType.iPhone-8', - 'state': 'Shutdown', - 'name': 'iPhone 8' - }, - { - 'dataPath': - '/Users/xxx/Library/Developer/CoreSimulator/Devices/1E76A0FD-38AC-4537-A989-EA639D7D012A/data', - 'logPath': - '/Users/xxx/Library/Logs/CoreSimulator/1E76A0FD-38AC-4537-A989-EA639D7D012A', - 'udid': '1E76A0FD-38AC-4537-A989-EA639D7D012A', - 'isAvailable': false, - 'deviceTypeIdentifier': - 'com.apple.CoreSimulator.SimDeviceType.iPhone-8-Plus', - 'state': 'Shutdown', - 'name': 'iPhone 8 Plus' - } - ] - } - }; - - processRunner.processToReturn = MockProcess.succeeding(); - processRunner.resultStdout = jsonEncode(devices); - - expect(await xcode.findBestAvailableIphoneSimulator(), expectedDeviceId); - }); - test('ignores non-iOS runtimes', () async { // Note: This uses `dynamic` deliberately, and should not be updated to // Object, in order to ensure that the code correctly handles this return @@ -204,7 +127,7 @@ void main() { 'logPath': '/Users/xxx/Library/Logs/CoreSimulator/1E76A0FD-38AC-4537-A989-EA639D7D012A', 'udid': '1E76A0FD-38AC-4537-A989-EA639D7D012A', - 'isAvailable': false, + 'isAvailable': true, 'deviceTypeIdentifier': 'com.apple.CoreSimulator.SimDeviceType.Apple-Watch-38mm', 'state': 'Shutdown', diff --git a/script/tool/test/xctest_command_test.dart b/script/tool/test/xctest_command_test.dart index f25805166f30..324dea0e71ef 100644 --- a/script/tool/test/xctest_command_test.dart +++ b/script/tool/test/xctest_command_test.dart @@ -368,7 +368,16 @@ void main() { processRunner.recordedCalls, orderedEquals([ const ProcessCall( - 'xcrun', ['simctl', 'list', '--json'], null), + 'xcrun', + [ + 'simctl', + 'list', + 'devices', + 'runtimes', + 'available', + '--json', + ], + null), ProcessCall( 'xcrun', const [