Method: FastlaneCore::DeviceManager.simulators

Defined in:
fastlane_core/lib/fastlane_core/device_manager.rb

.simulators(requested_os_type = "") ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'fastlane_core/lib/fastlane_core/device_manager.rb', line 27

def simulators(requested_os_type = "")
  UI.verbose("Fetching available simulator devices")

  @devices = []
  os_type = 'unknown'
  os_version = 'unknown'
  output = ''
  Open3.popen3('xcrun simctl list devices') do |stdin, stdout, stderr, wait_thr|
    output = stdout.read
  end

  unless output.include?("== Devices ==")
    UI.error("xcrun simctl CLI broken, run `xcrun simctl list devices` and make sure it works")
    UI.user_error!("xcrun simctl not working.")
  end

  output.split(/\n/).each do |line|
    next if line =~ /unavailable/
    next if line =~ /^== /
    if line =~ /^-- /
      (os_type, os_version) = line.gsub(/-- (.*) --/, '\1').split
    else
      next if os_type =~ /^Unavailable/

      # "    iPad (5th generation) (852A5796-63C3-4641-9825-65EBDC5C4259) (Shutdown)"
      # This line will turn the above string into
      # ["iPad (5th generation)", "(852A5796-63C3-4641-9825-65EBDC5C4259)", "(Shutdown)"]
      matches = line.strip.scan(/^(.*?) (\([^)]*?\)) (\([^)]*?\))$/).flatten.reject(&:empty?)
      state = matches.pop.to_s.delete('(').delete(')')
      udid = matches.pop.to_s.delete('(').delete(')')
      name = matches.join(' ')

      if matches.count && (os_type == requested_os_type || requested_os_type == "")
        # This is disabled here because the Device is defined later in the file, and that's a problem for the cop
        @devices << Device.new(name: name, os_type: os_type, os_version: os_version, udid: udid, state: state, is_simulator: true)
      end
    end
  end

  return @devices
end