Class: Luffa::Xcode

Inherits:
Object
  • Object
show all
Defined in:
lib/luffa/ios/xcode.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ios_version_incompatible_with_xcode_version?(ios_version, xcode_version) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/luffa/ios/xcode.rb', line 43

def self.ios_version_incompatible_with_xcode_version?(ios_version, xcode_version)
  [(ios_version >= Luffa::Version.new('8.0') && xcode_version < Luffa::Version.new('6.0')),
   (ios_version >= Luffa::Version.new('8.1') && xcode_version < Luffa::Version.new('6.1')),
   (ios_version >= Luffa::Version.new('8.2') && xcode_version < Luffa::Version.new('6.2')),
   (ios_version >= Luffa::Version.new('8.3') && xcode_version < Luffa::Version.new('6.3'))].any?
end

.with_developer_dir(developer_dir, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/luffa/ios/xcode.rb', line 28

def self.with_developer_dir(developer_dir, &block)
  original_developer_dir = Luffa::Environment.developer_dir
  stripped = developer_dir.strip
  begin
    ENV['DEVELOPER_DIR'] = stripped
    block.call
  ensure
    ENV['DEVELOPER_DIR'] = original_developer_dir
  end
end

.with_xcode_install(xcode_install, &block) ⇒ Object



39
40
41
# File 'lib/luffa/ios/xcode.rb', line 39

def self.with_xcode_install(xcode_install, &block)
  self.with_developer_dir(xcode_install.path, &block)
end

Instance Method Details

#active_xcodeObject



89
90
91
# File 'lib/luffa/ios/xcode.rb', line 89

def active_xcode
  @active_xcode ||= Luffa::XcodeInstall.new(active_xcode_dir)
end

#active_xcode_dirObject

The developer dir at the time the tests start.

To change the active Xcode:

$ DEVELOPER_DIR=/path/to/Xcode.app/Contents/Developer be rake spec


73
74
75
76
77
78
79
80
81
82
83
# File 'lib/luffa/ios/xcode.rb', line 73

def active_xcode_dir
  @active_xcode_dir ||= lambda {
    env = Luffa::Environment.developer_dir
    if env
      env
    else
      # fall back to xcode-select
      xcode_select_path
    end
  }.call
end

#xcode_installsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/luffa/ios/xcode.rb', line 50

def xcode_installs
  @xcode_installs ||= lambda do
    min_xcode_version = Luffa::Version.new('5.1.1')
    active_xcode = Luffa::Xcode.new.active_xcode
    xcodes = [active_xcode]
    Dir.glob('/Xcode/*/*.app/Contents/Developer').each do |path|
      xcode_version = path[/(\d\.\d(\.\d)?)/, 0]
      if Luffa::Version.new(xcode_version) >= min_xcode_version
        install = Luffa::XcodeInstall.new(path)
        unless install == active_xcode
          xcodes << install
        end
      end
    end
    xcodes
  end.call
end

#xcode_select_pathObject



85
86
87
# File 'lib/luffa/ios/xcode.rb', line 85

def xcode_select_path
  @xcode_select_dir ||= `xcode-select --print-path`.strip
end