mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-20 02:18:26 +00:00
Extract the ruby script for finding iOS simulators to a separate file
This commit is contained in:
parent
9a31febc4c
commit
d278649fee
22
scripts/find-ios-device.rb
Normal file
22
scripts/find-ios-device.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/ruby
|
||||||
|
|
||||||
|
require 'json'
|
||||||
|
|
||||||
|
ios_sim_default_device_type = ENV["IOS_SIM_DEVICE_TYPE"] or "iPhone 5s"
|
||||||
|
ios_sim_default_ios_version = ENV["IOS_SIM_OS"] or "iOS 10.1"
|
||||||
|
mode = ARGV[0]
|
||||||
|
|
||||||
|
devices = JSON.parse(%x{xcrun simctl list devices --json})['devices']
|
||||||
|
.each { |os, group| group.each{ |dev| dev['os'] = os } }
|
||||||
|
.flat_map { |x| x[1] }
|
||||||
|
if mode == "booted" then
|
||||||
|
device = devices.select{|x| x['state'] == 'Booted'}
|
||||||
|
else
|
||||||
|
device = devices
|
||||||
|
.select{ |x| x['availability'] == '(available)' }
|
||||||
|
.each { |x| x['score'] = (x['name'] == '$ios_sim_default_device_type' ? 1 : 0) + (x['os'] == '$ios_sim_default_ios_version' ? 1 : 0) }
|
||||||
|
.sort_by! { |x| [x['score'], x['name']] }
|
||||||
|
.reverse!
|
||||||
|
end
|
||||||
|
|
||||||
|
puts device[0]['udid']
|
@ -14,8 +14,6 @@ if echo "$CONFIGURATION" | grep -i "^Debug$" > /dev/null ; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
IOS_SIM_DEVICE=${IOS_SIM_DEVICE:-} # use preferentially, otherwise will be set and re-exported
|
IOS_SIM_DEVICE=${IOS_SIM_DEVICE:-} # use preferentially, otherwise will be set and re-exported
|
||||||
ios_sim_default_device_type=${IOS_SIM_DEVICE_TYPE:-iPhone 5s}
|
|
||||||
ios_sim_default_ios_version=${IOS_SIM_OS:-iOS 10.1}
|
|
||||||
|
|
||||||
PATH="/opt/android-sdk-linux/platform-tools:$PATH"
|
PATH="/opt/android-sdk-linux/platform-tools:$PATH"
|
||||||
SRCROOT=$(cd "$(dirname "$0")/.." && pwd)
|
SRCROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||||
@ -165,42 +163,43 @@ setup_ios_simulator() {
|
|||||||
# -- Ensure that the simulator is ready
|
# -- Ensure that the simulator is ready
|
||||||
|
|
||||||
if [ $CI_RUN == true ]; then
|
if [ $CI_RUN == true ]; then
|
||||||
# - Kill the Simulator to ensure we are running the correct one, only when running in CI
|
# - Kill the Simulator to ensure we are running the correct one, only when running in CI
|
||||||
echo "Resetting simulator using toolchain from: $DEVELOPER_DIR"
|
echo "Resetting simulator using toolchain from: $DEVELOPER_DIR"
|
||||||
|
|
||||||
# Quit Simulator.app to give it a chance to go down gracefully
|
# Quit Simulator.app to give it a chance to go down gracefully
|
||||||
local deadline=$((SECONDS+5))
|
local deadline=$((SECONDS+5))
|
||||||
while pgrep -qx Simulator && [ $SECONDS -lt $deadline ]; do
|
while pgrep -qx Simulator && [ $SECONDS -lt $deadline ]; do
|
||||||
osascript -e 'tell app "Simulator" to quit without saving' || true
|
osascript -e 'tell app "Simulator" to quit without saving' || true
|
||||||
sleep 0.25 # otherwise the pkill following will get it too early
|
sleep 0.25 # otherwise the pkill following will get it too early
|
||||||
done
|
done
|
||||||
|
|
||||||
# stop CoreSimulatorService
|
# stop CoreSimulatorService
|
||||||
launchctl remove com.apple.CoreSimulator.CoreSimulatorService 2>/dev/null || true
|
launchctl remove com.apple.CoreSimulator.CoreSimulatorService 2>/dev/null || true
|
||||||
sleep 0.25 # launchtl can take a small moment to kill services
|
sleep 0.25 # launchtl can take a small moment to kill services
|
||||||
|
|
||||||
# kill them with fire
|
# kill them with fire
|
||||||
while pgrep -qx Simulator com.apple.CoreSimulator.CoreSimulatorService; do
|
while pgrep -qx Simulator com.apple.CoreSimulator.CoreSimulatorService; do
|
||||||
pkill -9 -x Simulator com.apple.CoreSimulator.CoreSimulatorService || true
|
pkill -9 -x Simulator com.apple.CoreSimulator.CoreSimulatorService || true
|
||||||
sleep 0.05
|
sleep 0.05
|
||||||
done
|
done
|
||||||
|
|
||||||
# - Prod `simctl` a few times as sometimes it fails the first couple of times after switching XCode vesions
|
# - Prod `simctl` a few times as sometimes it fails the first couple of times after switching XCode vesions
|
||||||
local deadline=$((SECONDS+5))
|
local deadline=$((SECONDS+5))
|
||||||
while [ -z "$(xcrun simctl list devices 2>/dev/null)" ] && [ $SECONDS -lt $deadline ]; do
|
while [ -z "$(xcrun simctl list devices 2>/dev/null)" ] && [ $SECONDS -lt $deadline ]; do
|
||||||
: # nothing to see here, will stop cycling on the first successful run
|
: # nothing to see here, will stop cycling on the first successful run
|
||||||
done
|
done
|
||||||
|
|
||||||
# - Choose a device, if it has not already been chosen
|
# - Choose a device, if it has not already been chosen
|
||||||
local deadline=$((SECONDS+5))
|
local deadline=$((SECONDS+5))
|
||||||
while [ -z "$IOS_SIM_DEVICE" ] && [ $SECONDS -lt $deadline ]; do
|
IOS_DEVICE=""
|
||||||
IOS_DEVICE=$(ruby -rjson -e "puts JSON.parse(%x{xcrun simctl list devices --json})['devices'].each{|os,group| group.each{|dev| dev['os'] = os}}.flat_map{|x| x[1]}.select{|x| x['availability'] == '(available)'}.each{|x| x['score'] = (x['name'] == '$ios_sim_default_device_type' ? 1 : 0) + (x['os'] == '$ios_sim_default_ios_version' ? 1 : 0)}.sort_by!{|x| [x['score'], x['name']]}.reverse![0]['udid']")
|
while [ -z "$IOS_DEVICE" ] && [ $SECONDS -lt $deadline ]; do
|
||||||
export IOS_SIM_DEVICE=$IOS_DEVICE
|
IOS_DEVICE="$(ruby $SRCROOT/scripts/find-ios-device.rb best)"
|
||||||
done
|
done
|
||||||
if [ -z "$IOS_SIM_DEVICE" ]; then
|
if [ -z "$IOS_DEVICE" ]; then
|
||||||
echo "*** Failed to determine the iOS Simulator device to use ***"
|
echo "*** Failed to determine the iOS Simulator device to use ***"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
export IOS_SIM_DEVICE=$IOS_DEVICE
|
||||||
|
|
||||||
# - Reset the device we will be using if running in CI
|
# - Reset the device we will be using if running in CI
|
||||||
xcrun simctl shutdown "$IOS_SIM_DEVICE" 1>/dev/null 2>/dev/null || true # sometimes simctl gets confused
|
xcrun simctl shutdown "$IOS_SIM_DEVICE" 1>/dev/null 2>/dev/null || true # sometimes simctl gets confused
|
||||||
@ -214,19 +213,20 @@ setup_ios_simulator() {
|
|||||||
startedSimulator=true
|
startedSimulator=true
|
||||||
|
|
||||||
else
|
else
|
||||||
# - ensure that the simulator is running on a developer's workstation
|
# - ensure that the simulator is running on a developer's workstation
|
||||||
open "$DEVELOPER_DIR/Applications/Simulator.app"
|
open "$DEVELOPER_DIR/Applications/Simulator.app"
|
||||||
|
|
||||||
# - Select the first device booted in the simulator, since it will boot something for us
|
# - Select the first device booted in the simulator, since it will boot something for us
|
||||||
local deadline=$((SECONDS+10))
|
local deadline=$((SECONDS+10))
|
||||||
while [ -z "$IOS_SIM_DEVICE" ] && [ $SECONDS -lt $deadline ]; do
|
IOS_DEVICE=""
|
||||||
IOS_DEVICE=$(ruby -rjson -e "puts JSON.parse(%x{xcrun simctl list devices --json})['devices'].each{|os,group| group.each{|dev| dev['os'] = os}}.flat_map{|x| x[1]}.select{|x| x['state'] == 'Booted'}[0]['udid']")
|
while [ -z "$IOS_DEVICE" ] && [ $SECONDS -lt $deadline ]; do
|
||||||
export IOS_SIM_DEVICE=$IOS_DEVICE
|
IOS_DEVICE="$(ruby $SRCROOT/scripts/find-ios-device.rb booted)"
|
||||||
done
|
done
|
||||||
if [ -z "$IOS_SIM_DEVICE" ]; then
|
if [ -z "$IOS_DEVICE" ]; then
|
||||||
echo "*** Failed to determine the iOS Simulator device in use ***"
|
echo "*** Failed to determine the iOS Simulator device in use ***"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
export IOS_SIM_DEVICE=$IOS_DEVICE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Wait until the boot completes
|
# Wait until the boot completes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user