class RunLoop::CLI::Instruments

Attributes

signal[RW]

Public Instance Methods

detect_bundle_id_or_bundle_path(options) click to toggle source
# File lib/run_loop/cli/instruments.rb, line 135
def detect_bundle_id_or_bundle_path(options)
  app = options[:app]
  ipa = options[:ipa]
  bundle_id = options[:bundle_id]

  if app && ipa
    raise RunLoop::CLI::ValidationError,
          "--app #{app} and --ipa #{ipa} are mutually exclusive arguments.  Pass one or the other, not both."
  end

  if app && bundle_id
    raise RunLoop::CLI::ValidationError,
          "--app #{app} and --bundle-id #{bundle_id} are mutually exclusive arguments. Pass one or the other, not both."
  end

  if ipa && bundle_id
    raise RunLoop::CLI::ValidationError,
          "--ipa #{ipa} and --bundle-id #{bundle_id} are mutually exclusive arguments. Pass one or the other, not both."
  end
  app || bundle_id
end
detect_device_udid_from_options(options) click to toggle source
# File lib/run_loop/cli/instruments.rb, line 157
def detect_device_udid_from_options(options)
  device = options[:device]
  app = options[:app]
  if app && !device
    RunLoop::Core.default_simulator
  else
    device
  end
end
launch() click to toggle source
# File lib/run_loop/cli/instruments.rb, line 101
def launch
  if RunLoop::Xcode.new.version_gte_8?
    puts "Launching applications with Xcode 8 is not supported"
    exit 1
  end

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

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

  begin
    launch_options = {
          :args => parse_app_launch_args(options),
          :udid => detect_device_udid_from_options(options),
          :app => detect_bundle_id_or_bundle_path(options)
    }
    run_loop = RunLoop.run(launch_options)
    puts JSON.generate(run_loop)
  ensure
    ENV['DEBUG'] = original_value if debug
  end
end
parse_app_launch_args(options) click to toggle source
# File lib/run_loop/cli/instruments.rb, line 126
def parse_app_launch_args(options)
  args = options[:args]
  if args.nil?
    []
  else
    args.split(',')
  end
end
quit() click to toggle source
# File lib/run_loop/cli/instruments.rb, line 28
def quit
  if RunLoop::Xcode.new.version_gte_8?
    puts "instruments quit with Xcode 8 is not supported"
    exit 1
  end

  signal = options[:signal]
  ENV['DEBUG'] = '1' if options[:debug]
  instruments = RunLoop::Instruments.new
  instruments.instruments_pids.each do |pid|
    terminator = RunLoop::ProcessTerminator.new(pid, signal, 'instruments')
    unless terminator.kill_process
      terminator = RunLoop::ProcessTerminator.new(pid, 'KILL', 'instruments')
      terminator.kill_process
    end
  end
end