Sha256: 35822106776464ee6c5000ecc11b92b4caaf720bf089fb6b380bbfe097a310ef

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require 'tmpdir'
require 'background_process'

module ICuke
  class Simulator
    include Timeout
    
    def launch(project_file, options = {})
      options = {
        :configuration => 'Debug',
        :env => {}
      }.merge(options)
      
      app_name = File.basename(project_file, '.xcodeproj')
      directory = "#{File.dirname(project_file)}/build/#{options[:configuration]}-iphonesimulator"
      
      ENV['DYLD_ROOT_PATH'] = '/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.2.sdk'
      ENV['DYLD_FRAMEWORK_PATH'] = directory
      ENV['IPHONE_SIMULATOR_ROOT'] = '/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.2.sdk'
      home = Dir.mktmpdir
      FileUtils.mkdir_p File.join(home, 'Library', 'Preferences')
      FileUtils.cp File.join(File.dirname(__FILE__), 'com.apple.Accessibility.plist'), File.join(home, 'Library', 'Preferences')
      FileUtils.mkdir File.join(home, 'Documents')
      ENV['CFFIXED_USER_HOME'] = home
      ENV['ICUKE_KEEP_PREFERENCES'] = '1'
      
      options[:env].each_pair do |k, v|
        ENV[k] = v
      end
      
      command = "#{directory}/#{app_name}.app/#{app_name} -RegisterForSystemEvents"
      @pid = fork {
        STDIN.close
        STDERR.close
        STDOUT.close
        
        exec(command)
      }
      
      timeout(30) do
        begin
          view
        rescue Errno::ECONNREFUSED
          sleep(0.5)
          retry
        end
      end
    end
    
    def quit
      Process.kill('TERM', @pid)
      Process.wait(@pid)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
iCuke-0.5.1 lib/icuke/headless.rb