Class: RunLoop::CLI::Simctl

Inherits:
Thor
  • Object
show all
Defined in:
lib/run_loop/cli/simctl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sim_controlObject (readonly)

Returns the value of attribute sim_control.



9
10
11
# File 'lib/run_loop/cli/simctl.rb', line 9

def sim_control
  @sim_control
end

Instance Method Details

#bootedObject



30
31
32
33
34
35
36
37
38
# File 'lib/run_loop/cli/simctl.rb', line 30

def booted
  device = booted_device
  if device.nil?
    version = Xcode.new.version
    puts "No simulator for active Xcode (version #{version}) is booted."
  else
    puts device
  end
end

#doctorObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/run_loop/cli/simctl.rb', line 55

def doctor
  debug = options[:debug]
  device = options[:device]

  if device
    device = expect_device(options)
    if debug
      RunLoop::Environment.with_debugging do
        launch_simulator(device)
      end
    else
      launch_simulator(device)
    end
  else
    if debug
      RunLoop::Environment.with_debugging do
        launch_each_simulator
      end
    else
      launch_each_simulator
    end
  end
end

#installObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/run_loop/cli/simctl.rb', line 158

def install
  debug = options[:debug]

  if debug
    ENV['DEBUG'] = '1'
  end

  debug_logging = RunLoop::Environment.debug?

  device = expect_device(options)
  app = expect_app(options, device)

  bridge = RunLoop::Simctl::Bridge.new(device, app.path)

  xcode = bridge.sim_control.xcode
  if xcode.version >= RunLoop::Version.new('7.0')
    puts "ERROR: Xcode #{xcode.version.to_s} detected."
    puts "ERROR: Apple's simctl install/uninstall is broken for this version of Xcode."
    puts "ERROR: See the following links for details:"
    puts "ERROR: https://forums.developer.apple.com/message/51922"
    puts "ERROR: https://github.com/calabash/run_loop/issues/235"
    puts "ERROR: exiting 1"
    exit 1
  end

  force_reinstall = options[:force]

  before = Time.now

  if bridge.app_is_installed?
    if debug_logging
      puts "App with bundle id '#{app.bundle_identifier}' is already installed."
    end

    if force_reinstall
      if debug_logging
        puts 'Will force a re-install.'
      end
      bridge.uninstall
      bridge.install
    else
      new_digest = RunLoop::Directory.directory_digest(app.path)
      if debug_logging
        puts "      New app has SHA: '#{new_digest}'."
      end
      installed_app_bundle = bridge.fetch_app_dir
      old_digest = RunLoop::Directory.directory_digest(installed_app_bundle)
      if debug_logging
        puts "Installed app has SHA: '#{old_digest}'."
      end
      if new_digest != old_digest
        if debug_logging
          puts "Will re-install '#{app.bundle_identifier}' because the SHAs don't match."
        end
        bridge.uninstall
        bridge.install
      else
        if debug_logging
          puts "Will not re-install '#{app.bundle_identifier}' because the SHAs match."
        end
      end
    end
  else
    bridge.install
  end

  if debug_logging
    "Launching took #{Time.now-before} seconds"
    puts "Installed '#{app.bundle_identifier}' on #{device} in #{Time.now-before} seconds."
  end
end

#manage_processesObject



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/run_loop/cli/simctl.rb', line 104

def manage_processes
  debug = options[:debug]
  original_value = ENV['DEBUG']

  ENV['DEBUG'] = '1' if debug

  begin
    RunLoop::SimControl.terminate_all_sims
    RunLoop::LifeCycle::Simulator.new.terminate_core_simulator_processes
  ensure
    ENV['DEBUG'] = original_value if debug
  end
end

#tailObject



12
13
14
# File 'lib/run_loop/cli/simctl.rb', line 12

def tail
  tail_booted
end