From e76652dac543aa46de598ab277851dddf12403f1 Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Sun, 8 Oct 2023 22:07:20 -0500 Subject: [PATCH 1/3] update test scripts and ci.yaml for macOS 13 --- .ci.yaml | 4 ++-- .ci/scripts/boot_simulator.sh | 12 ++++++++++++ .ci/scripts/create_simulator.sh | 14 ++++++++++++++ .ci/targets/ios_platform_tests.yaml | 6 +++++- packages/pigeon/tool/shared/test_suites.dart | 2 +- 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100755 .ci/scripts/boot_simulator.sh diff --git a/.ci.yaml b/.ci.yaml index 868d82d387d..f6dd193e40a 100644 --- a/.ci.yaml +++ b/.ci.yaml @@ -64,7 +64,7 @@ platform_properties: [ {"dependency": "gems", "version": "v3.3.14"} ] - os: Mac-12 + os: Mac-13 device_type: none cpu: arm64 $flutter/osx_sdk : >- @@ -77,7 +77,7 @@ platform_properties: [ {"dependency": "gems", "version": "v3.3.14"} ] - os: Mac-12 + os: Mac-13 device_type: none cpu: x86 $flutter/osx_sdk : >- diff --git a/.ci/scripts/boot_simulator.sh b/.ci/scripts/boot_simulator.sh new file mode 100755 index 00000000000..0b1d82e10ca --- /dev/null +++ b/.ci/scripts/boot_simulator.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +set -e + +# The name here must match create_simulator.sh +readonly DEVICE_NAME=Flutter-iPhone + +xcrun simctl boot "$DEVICE_NAME" || : +echo -e "" +xcrun simctl list \ No newline at end of file diff --git a/.ci/scripts/create_simulator.sh b/.ci/scripts/create_simulator.sh index 04d8fd1e9cd..39f0bb5ef73 100755 --- a/.ci/scripts/create_simulator.sh +++ b/.ci/scripts/create_simulator.sh @@ -11,5 +11,19 @@ readonly DEVICE_NAME=Flutter-iPhone readonly DEVICE=com.apple.CoreSimulator.SimDeviceType.iPhone-14 readonly OS=com.apple.CoreSimulator.SimRuntime.iOS-16-4 +# Delete any existing devices named Flutter-iPhone. Having more than one may +# cause issues when builds target the device. +echo -e "Deleting any existing devices names $DEVICE_NAME..." +RESULT=0 +while [[ $RESULT == 0 ]]; do + xcrun simctl delete "$DEVICE_NAME" || RESULT=1 + if [ $RESULT == 0 ]; then + echo -e "Deleted $DEVICE_NAME" + fi +done +echo -e "" + xcrun simctl list +echo -e "\nCreating $DEVICE_NAME $DEVICE $OS ...\n" xcrun simctl create "$DEVICE_NAME" "$DEVICE" "$OS" | xargs xcrun simctl boot +xcrun simctl list diff --git a/.ci/targets/ios_platform_tests.yaml b/.ci/targets/ios_platform_tests.yaml index 212c8c95b0a..f6fb94db724 100644 --- a/.ci/targets/ios_platform_tests.yaml +++ b/.ci/targets/ios_platform_tests.yaml @@ -21,7 +21,11 @@ tasks: args: ["xcode-analyze", "--ios", "--ios-min-version=13.0"] - name: native test script: script/tool_runner.sh - args: ["native-test", "--ios", "--ios-destination", "platform=iOS Simulator,name=iPhone 14,OS=latest"] + args: ["native-test", "--ios", "--ios-destination", "platform=iOS Simulator,name=Flutter-iPhone,OS=16.4"] + - name: boot simulator + # Ensure simulator is still booted + script: .ci/scripts/boot_simulator.sh + infra_step: true # Note infra steps failing prevents "always" from running. - name: drive examples # `drive-examples` contains integration tests, which changes the UI of the application. # This UI change sometimes affects `xctest`. diff --git a/packages/pigeon/tool/shared/test_suites.dart b/packages/pigeon/tool/shared/test_suites.dart index 39250f81653..3d80c5188fc 100644 --- a/packages/pigeon/tool/shared/test_suites.dart +++ b/packages/pigeon/tool/shared/test_suites.dart @@ -297,7 +297,7 @@ Future _runIOSPluginUnitTests(String testPluginPath) async { return runXcodeBuild( '$examplePath/ios', sdk: 'iphonesimulator', - destination: 'platform=iOS Simulator,name=iPhone 14', + destination: 'platform=iOS Simulator,name=Flutter-iPhone,OS=16.4', extraArguments: ['test'], ); } From 6fb70b7100c378c58beb7a5cbda02ae4cf27620f Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Mon, 9 Oct 2023 12:38:11 -0500 Subject: [PATCH 2/3] create and delete simulator for pigeon tests, add some comments and newline --- .ci/scripts/boot_simulator.sh | 4 +- packages/pigeon/tool/shared/test_suites.dart | 45 +++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/.ci/scripts/boot_simulator.sh b/.ci/scripts/boot_simulator.sh index 0b1d82e10ca..cce170240b6 100755 --- a/.ci/scripts/boot_simulator.sh +++ b/.ci/scripts/boot_simulator.sh @@ -7,6 +7,8 @@ set -e # The name here must match create_simulator.sh readonly DEVICE_NAME=Flutter-iPhone +# Allow boot to fail; cases like "Unable to boot device in current state: Booted" +# exit with failure. xcrun simctl boot "$DEVICE_NAME" || : echo -e "" -xcrun simctl list \ No newline at end of file +xcrun simctl list diff --git a/packages/pigeon/tool/shared/test_suites.dart b/packages/pigeon/tool/shared/test_suites.dart index 3d80c5188fc..aecc380ef47 100644 --- a/packages/pigeon/tool/shared/test_suites.dart +++ b/packages/pigeon/tool/shared/test_suites.dart @@ -294,11 +294,54 @@ Future _runIOSPluginUnitTests(String testPluginPath) async { return compileCode; } + const String deviceName = 'Pigeon-Test-iPhone'; + const String deviceType = 'com.apple.CoreSimulator.SimDeviceType.iPhone-14'; + const String deviceRuntime = 'com.apple.CoreSimulator.SimRuntime.iOS-16-4'; + const String deviceOS = '16.4'; + await _createSimulator(deviceName, deviceType, deviceRuntime); return runXcodeBuild( '$examplePath/ios', sdk: 'iphonesimulator', - destination: 'platform=iOS Simulator,name=Flutter-iPhone,OS=16.4', + destination: 'platform=iOS Simulator,name=$deviceName,OS=$deviceOS', extraArguments: ['test'], + ).whenComplete(() => _deleteSimulator(deviceName)); +} + +Future _createSimulator( + String deviceName, + String deviceType, + String deviceRuntime, +) async { + // Delete any existing simulators with the same name until it fails. It will + // fail once there are no simulators with the name. Having more than one may + // cause issues when builds target the device. + int deleteResult = 0; + while (deleteResult == 0) { + deleteResult = await _deleteSimulator(deviceName); + } + return runProcess( + 'xcrun', + [ + 'simctl', + 'create', + deviceName, + deviceType, + deviceRuntime, + ], + streamOutput: false, + logFailure: true, + ); +} + +Future _deleteSimulator(String deviceName) async { + return runProcess( + 'xcrun', + [ + 'simctl', + 'delete', + deviceName, + ], + streamOutput: false, ); } From 9d8d5c1f010ea737ccd224775fb5be707c5153d8 Mon Sep 17 00:00:00 2001 From: Victoria Ashworth Date: Mon, 9 Oct 2023 15:11:58 -0500 Subject: [PATCH 3/3] fix nits, run on macOS 12 or 13 --- .ci.yaml | 4 ++-- .ci/scripts/create_simulator.sh | 1 - .ci/targets/ios_platform_tests.yaml | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.ci.yaml b/.ci.yaml index f6dd193e40a..2d5bac34552 100644 --- a/.ci.yaml +++ b/.ci.yaml @@ -64,7 +64,7 @@ platform_properties: [ {"dependency": "gems", "version": "v3.3.14"} ] - os: Mac-13 + os: "Mac-12|Mac-13" device_type: none cpu: arm64 $flutter/osx_sdk : >- @@ -77,7 +77,7 @@ platform_properties: [ {"dependency": "gems", "version": "v3.3.14"} ] - os: Mac-13 + os: "Mac-12|Mac-13" device_type: none cpu: x86 $flutter/osx_sdk : >- diff --git a/.ci/scripts/create_simulator.sh b/.ci/scripts/create_simulator.sh index 39f0bb5ef73..722fb4014b0 100755 --- a/.ci/scripts/create_simulator.sh +++ b/.ci/scripts/create_simulator.sh @@ -23,7 +23,6 @@ while [[ $RESULT == 0 ]]; do done echo -e "" -xcrun simctl list echo -e "\nCreating $DEVICE_NAME $DEVICE $OS ...\n" xcrun simctl create "$DEVICE_NAME" "$DEVICE" "$OS" | xargs xcrun simctl boot xcrun simctl list diff --git a/.ci/targets/ios_platform_tests.yaml b/.ci/targets/ios_platform_tests.yaml index f6fb94db724..eea677edb1c 100644 --- a/.ci/targets/ios_platform_tests.yaml +++ b/.ci/targets/ios_platform_tests.yaml @@ -21,6 +21,7 @@ tasks: args: ["xcode-analyze", "--ios", "--ios-min-version=13.0"] - name: native test script: script/tool_runner.sh + # Simulator name must match name in create_simulator.sh args: ["native-test", "--ios", "--ios-destination", "platform=iOS Simulator,name=Flutter-iPhone,OS=16.4"] - name: boot simulator # Ensure simulator is still booted