Skip to content

Commit

Permalink
addressing feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
wuaar1003 committed Dec 11, 2023
1 parent d9ac907 commit 962248b
Show file tree
Hide file tree
Showing 8 changed files with 3,195 additions and 125 deletions.
24 changes: 9 additions & 15 deletions fastlane_core/lib/fastlane_core/device_manager.rb
Expand Up @@ -15,6 +15,15 @@ def all(requested_os_type = "")
def simulators(requested_os_type = "")
UI.verbose("Fetching available simulator devices")

output, status = Open3.capture2('xcrun simctl list runtimes -j')
unless status.success?
UI.error('xcrun simctl CLI broken; cun `xcrun simctl list runtimes` and make sure it works')
UI.user_error!('xcrun simctl not working')
end

json = JSON.parse(output)
@runtime_build_os_versions = json['runtimes'].map { |h| [h['buildversion'], h['version']] }.to_h

@devices = []
os_type = 'unknown'
os_version = 'unknown'
Expand All @@ -23,21 +32,6 @@ def simulators(requested_os_type = "")
output = stdout.read
end

runtime_info = ''
Open3.popen3('xcrun simctl list runtimes') do |stdin, stdout, stderr, wait_thr|
# This regex outputs the version info in the format "<platform> <version><exact version>"
runtime_info = stdout.read
end
unless runtime_info.include?("== Runtimes ==")
UI.error("xcrun simctl CLI broken, run `xcrun simctl list devices` and make sure it works")
UI.user_error!("xcrun simctl not working.")
end

@runtime_build_os_versions = runtime_info.lines.drop(1).each_with_object({}) do |line, res|
matches = line.match(/.*\((?<version>\S+)\s-\s(?<build>\S+)\)[\S\s]*/)
res[matches[:build]] = matches[:version]
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.")
Expand Down
66 changes: 34 additions & 32 deletions fastlane_core/spec/device_manager_spec.rb
Expand Up @@ -29,9 +29,9 @@
response = "response"
expect(response).to receive(:read).and_return(@simctl_output)
expect(Open3).to receive(:popen3).with("xcrun simctl list devices").and_yield(nil, response, nil, nil)
thing = {}
expect(thing).to receive(:read).and_return("== Runtimes ==\n")
allow(Open3).to receive(:popen3).with("xcrun simctl list runtimes").and_yield(nil, thing, nil, nil)

status = double('status', "success?": true)
expect(Open3).to receive(:capture2).with("xcrun simctl list runtimes -j").and_return(['{"runtimes": [] }', status])

devices = FastlaneCore::Simulator.all
expect(devices.count).to eq(6)
Expand Down Expand Up @@ -79,9 +79,9 @@
simctl_output = File.read('./fastlane_core/spec/fixtures/DeviceManagerSimctlOutputXcode8')
expect(response).to receive(:read).and_return(simctl_output)
expect(Open3).to receive(:popen3).with("xcrun simctl list devices").and_yield(nil, response, nil, nil)
thing = {}
expect(thing).to receive(:read).and_return("== Runtimes ==\n")
allow(Open3).to receive(:popen3).with("xcrun simctl list runtimes").and_yield(nil, thing, nil, nil)

status = double('status', "success?": true)
expect(Open3).to receive(:capture2).with("xcrun simctl list runtimes -j").and_return(['{"runtimes": [] }', status])

devices = FastlaneCore::Simulator.all
expect(devices.count).to eq(12)
Expand Down Expand Up @@ -111,9 +111,9 @@
simctl_output = File.read('./fastlane_core/spec/fixtures/DeviceManagerSimctlOutputXcode9')
expect(response).to receive(:read).and_return(simctl_output)
expect(Open3).to receive(:popen3).with("xcrun simctl list devices").and_yield(nil, response, nil, nil)
thing = {}
expect(thing).to receive(:read).and_return("== Runtimes ==\n")
allow(Open3).to receive(:popen3).with("xcrun simctl list runtimes").and_yield(nil, thing, nil, nil)

status = double('status', "success?": true)
expect(Open3).to receive(:capture2).with("xcrun simctl list runtimes -j").and_return(['{"runtimes": [] }', status])

devices = FastlaneCore::Simulator.all
expect(devices.count).to eq(15)
Expand Down Expand Up @@ -143,9 +143,9 @@
simctl_output = File.read('./fastlane_core/spec/fixtures/DeviceManagerSimctlOutputXcode11')
expect(response).to receive(:read).and_return(simctl_output)
expect(Open3).to receive(:popen3).with("xcrun simctl list devices").and_yield(nil, response, nil, nil)
thing = {}
expect(thing).to receive(:read).and_return("== Runtimes ==\n")
allow(Open3).to receive(:popen3).with("xcrun simctl list runtimes").and_yield(nil, thing, nil, nil)

status = double('status', "success?": true)
expect(Open3).to receive(:capture2).with("xcrun simctl list runtimes -j").and_return(['{"runtimes": [] }', status])

devices = FastlaneCore::Simulator.all
expect(devices.count).to eq(29)
Expand Down Expand Up @@ -175,9 +175,9 @@
response = "response"
expect(response).to receive(:read).and_return(@simctl_output)
expect(Open3).to receive(:popen3).with("xcrun simctl list devices").and_yield(nil, response, nil, nil)
thing = {}
expect(thing).to receive(:read).and_return("== Runtimes ==\n")
allow(Open3).to receive(:popen3).with("xcrun simctl list runtimes").and_yield(nil, thing, nil, nil)

status = double('status', "success?": true)
expect(Open3).to receive(:capture2).with("xcrun simctl list runtimes -j").and_return(['{"runtimes": [] }', status])

devices = FastlaneCore::SimulatorTV.all
expect(devices.count).to eq(1)
Expand All @@ -194,9 +194,9 @@
response = "response"
expect(response).to receive(:read).and_return(@simctl_output)
expect(Open3).to receive(:popen3).with("xcrun simctl list devices").and_yield(nil, response, nil, nil)
thing = {}
expect(thing).to receive(:read).and_return("== Runtimes ==\n")
allow(Open3).to receive(:popen3).with("xcrun simctl list runtimes").and_yield(nil, thing, nil, nil)

status = double('status', "success?": true)
expect(Open3).to receive(:capture2).with("xcrun simctl list runtimes -j").and_return(['{"runtimes": [] }', status])

devices = FastlaneCore::SimulatorWatch.all
expect(devices.count).to eq(2)
Expand All @@ -219,9 +219,9 @@
response = "response"
expect(response).to receive(:read).and_return(@simctl_output)
expect(Open3).to receive(:popen3).with("xcrun simctl list devices").and_yield(nil, response, nil, nil)
thing = {}
expect(thing).to receive(:read).and_return("== Runtimes ==\n")
allow(Open3).to receive(:popen3).with("xcrun simctl list runtimes").and_yield(nil, thing, nil, nil)

status = double('status', "success?": true)
expect(Open3).to receive(:capture2).with("xcrun simctl list runtimes -j").and_return(['{"runtimes": [] }', status])

devices = FastlaneCore::DeviceManager.simulators
expect(devices.count).to eq(9)
Expand Down Expand Up @@ -275,9 +275,9 @@
simctl_output = File.read('./fastlane_core/spec/fixtures/DeviceManagerSimctlOutputXcode10BootedUnavailable')
expect(response).to receive(:read).and_return(simctl_output)
expect(Open3).to receive(:popen3).with("xcrun simctl list devices").and_yield(nil, response, nil, nil)
thing = {}
expect(thing).to receive(:read).and_return("== Runtimes ==\n")
allow(Open3).to receive(:popen3).with("xcrun simctl list runtimes").and_yield(nil, thing, nil, nil)

status = double('status', "success?": true)
expect(Open3).to receive(:capture2).with("xcrun simctl list runtimes -j").and_return(['{"runtimes": [] }', status])

devices = FastlaneCore::DeviceManager.simulators
expect(devices.count).to eq(3)
Expand Down Expand Up @@ -384,9 +384,9 @@

expect(response).to receive(:read).and_return(@simctl_output)
expect(Open3).to receive(:popen3).with("xcrun simctl list devices").and_yield(nil, response, nil, nil)
thing = {}
expect(thing).to receive(:read).and_return("== Runtimes ==\n")
allow(Open3).to receive(:popen3).with("xcrun simctl list runtimes").and_yield(nil, thing, nil, nil)

status = double('status', "success?": true)
expect(Open3).to receive(:capture2).with("xcrun simctl list runtimes -j").and_return(['{"runtimes": [] }', status])

devices = FastlaneCore::DeviceManager.all('iOS')
expect(devices.count).to eq(8)
Expand Down Expand Up @@ -439,9 +439,9 @@

expect(response).to receive(:read).and_return(@simctl_output)
expect(Open3).to receive(:popen3).with("xcrun simctl list devices").and_yield(nil, response, nil, nil)
thing = {}
expect(thing).to receive(:read).and_return("== Runtimes ==\n")
allow(Open3).to receive(:popen3).with("xcrun simctl list runtimes").and_yield(nil, thing, nil, nil)

status = double('status', "success?": true)
expect(Open3).to receive(:capture2).with("xcrun simctl list runtimes -j").and_return(['{"runtimes": [] }', status])

devices = FastlaneCore::DeviceManager.all('tvOS')
expect(devices.count).to eq(2)
Expand All @@ -464,13 +464,15 @@
response = double('xcrun simctl list devices', read: '== Devices ==')
allow(Open3).to receive(:popen3).with('xcrun simctl list devices').and_yield(nil, response, nil, nil)

thing = double('xcrun simctl list runtimes', read: "== Runtimes ==\niOS 17.0 (17.0 - 21A328) - com.apple.CoreSimulator.SimRuntime.iOS-17-0\niOS 17.0 (17.0.1 - 21A342) - com.apple.CoreSimulator.SimRuntime.iOS-17-0")
allow(Open3).to receive(:popen3).with("xcrun simctl list runtimes").and_yield(nil, thing, nil, nil)
status = double('status', "success?": true)
runtime_output = File.read('./fastlane_core/spec/fixtures/XcrunSimctlListRuntimesOutput')
expect(Open3).to receive(:capture2).with("xcrun simctl list runtimes -j").and_return([runtime_output, status])

devices = FastlaneCore::DeviceManager.simulators

expect(FastlaneCore::DeviceManager.runtime_build_os_versions['21A328']).to eq('17.0')
expect(FastlaneCore::DeviceManager.runtime_build_os_versions['21A342']).to eq('17.0.1')
expect(FastlaneCore::DeviceManager.runtime_build_os_versions['21R355']).to eq('10.0')
end

describe FastlaneCore::DeviceManager::Device do
Expand Down

0 comments on commit 962248b

Please sign in to comment.