Class: Xcselect::Xcode

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/xcselect/xcode.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fld) ⇒ Xcode

Returns a new instance of Xcode.



8
9
10
11
12
13
# File 'lib/xcselect/xcode.rb', line 8

def initialize(fld)
  @folder = fld
  ver_output = `#{xcodebuild_path} -version`
  @version = ver_output.match(/Xcode (.*)$/)[1]
  @build = ver_output.match(/Build version (.*)$/)[1]
end

Instance Attribute Details

#buildObject

Returns the value of attribute build.



7
8
9
# File 'lib/xcselect/xcode.rb', line 7

def build
  @build
end

#folderObject

Returns the value of attribute folder.



7
8
9
# File 'lib/xcselect/xcode.rb', line 7

def folder
  @folder
end

#versionObject

Returns the value of attribute version.



7
8
9
# File 'lib/xcselect/xcode.rb', line 7

def version
  @version
end

Class Method Details

.current_xcodeObject



44
45
46
# File 'lib/xcselect/xcode.rb', line 44

def self.current_xcode
  `xcode-select -print-path`.chomp
end

.current_xcode_pathObject



48
49
50
51
52
53
54
55
56
# File 'lib/xcselect/xcode.rb', line 48

def self.current_xcode_path
  path = self.current_xcode
  if path =~ /(.*Xcode(.*DP.*)?.app)/
    path = $1
  else
    path += "/Applications/Xcode.app"
  end
  return path
end

.find_allObject

Get an array of all installed xcode objects



24
25
26
27
28
29
30
31
32
33
# File 'lib/xcselect/xcode.rb', line 24

def self.find_all

  xcode_builds = `mdfind -name xcodebuild`.chomp.split
  #TODO: move this checking to init method
  xcode_builds = xcode_builds.select {|x| x =~ /\/xcodebuild$/ && !(x =~ /^\/(Volumes|usr\/bin\/)/) && File.exists?(x) }
  xcode_objs = xcode_builds.map {|p| Xcode.new p.sub( /\/usr\/bin.*/, '').chomp.strip }
  # Xcode in now in a single application, look for that and use that as a candidate
  xcode_objs += self.find_new_xcodes
  xcode_objs.sort
end

.find_new_xcodesObject



35
36
37
38
39
40
41
42
# File 'lib/xcselect/xcode.rb', line 35

def self.find_new_xcodes
  # Xcode is now in a single application, look for that and use that as a candidate
  newXcodes = `mdfind 'kMDItemCFBundleIdentifier = com.apple.dt.Xcode'`.chomp.split
  newXcodes = newXcodes.select do |x| 
    File.exists? x + "/Contents/Developer/usr/bin/xcodebuild"
  end
  newXcodes.map {|x| Xcode.new(x+"/Contents/Developer") }
end

Instance Method Details

#<=>(o) ⇒ Object

sort by version number and fallback to build number after



68
69
70
71
# File 'lib/xcselect/xcode.rb', line 68

def <=>(o)
  res = version.to_f <=> o.version.to_f
  return res == 0 ?  o.build <=> build : res;
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/xcselect/xcode.rb', line 58

def eql?(o)
  return false if o.nil? 
  return (o.folder == folder && o.version == version && o.build == build)
end

#sdksObject



63
64
65
# File 'lib/xcselect/xcode.rb', line 63

def sdks
  `#{xcodebuild_path} -showsdks`
end

#to_sObject



19
20
21
# File 'lib/xcselect/xcode.rb', line 19

def to_s
  "Xcode: #{folder} - #{version} (#{build})"
end

#xcodebuild_pathObject



15
16
17
# File 'lib/xcselect/xcode.rb', line 15

def xcodebuild_path
  "#{folder}/usr/bin/xcodebuild"
end