Class: XCInvoke::Xcode
- Inherits:
-
Object
- Object
- XCInvoke::Xcode
- Extended by:
- Enumerable
- Defined in:
- lib/xcinvoke/xcode.rb
Instance Attribute Summary collapse
-
#developer_dir ⇒ Object
readonly
Returns the value of attribute developer_dir.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #as_env ⇒ Object
- #build_number ⇒ Object
- #dyld_framework_path ⇒ Object
- #dyld_library_path ⇒ Object
-
#initialize(path) ⇒ Xcode
constructor
A new instance of Xcode.
- #swift_version ⇒ Object
- #version ⇒ Object
- #xcrun(cmd, env: {}, err: false) ⇒ Object
Constructor Details
#initialize(path) ⇒ Xcode
Returns a new instance of Xcode.
10 11 12 |
# File 'lib/xcinvoke/xcode.rb', line 10 def initialize(path) @developer_dir = Pathname(path) end |
Instance Attribute Details
#developer_dir ⇒ Object (readonly)
Returns the value of attribute developer_dir.
8 9 10 |
# File 'lib/xcinvoke/xcode.rb', line 8 def developer_dir @developer_dir end |
Class Method Details
.all ⇒ Object
31 32 33 |
# File 'lib/xcinvoke/xcode.rb', line 31 def self.all to_a end |
.each(&blk) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/xcinvoke/xcode.rb', line 19 def self.each(&blk) xcodes, = Open3.capture2('mdfind', "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'", err: '/dev/null') xcodes = xcodes.split("\n").map(&:strip) xcodes = xcodes.map do |xc| xc = Pathname(xc) + 'Contents/Developer' new(xc) end xcodes.each(&blk) end |
.find_swift_version(swift_version) ⇒ Object
35 36 37 38 |
# File 'lib/xcinvoke/xcode.rb', line 35 def self.find_swift_version(swift_version) swift_version = Gem::Version.create(swift_version) select { |xc| xc.swift_version == swift_version }.sort.last end |
.selected ⇒ Object
14 15 16 17 |
# File 'lib/xcinvoke/xcode.rb', line 14 def self.selected dir, = Open3.capture2('xcode-select', '-p', err: '/dev/null') new(dir.strip) end |
Instance Method Details
#<=>(other) ⇒ Object
55 56 57 |
# File 'lib/xcinvoke/xcode.rb', line 55 def <=>(other) version <=> other.version end |
#as_env ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/xcinvoke/xcode.rb', line 81 def as_env { 'DEVELOPER_DIR' => developer_dir.to_path, 'DYLD_FRAMEWORK_PATH' => unshift_path(ENV['DYLD_FRAMEWORK_PATH'], dyld_framework_path), 'DYLD_LIBRARY_PATH' => unshift_path(ENV['DYLD_LIBRARY_PATH'], dyld_library_path), } end |
#build_number ⇒ Object
45 46 47 48 |
# File 'lib/xcinvoke/xcode.rb', line 45 def build_number info = xcodebuild_info info[1] if info end |
#dyld_framework_path ⇒ Object
91 92 93 |
# File 'lib/xcinvoke/xcode.rb', line 91 def dyld_framework_path developer_dir + 'Toolchains/XcodeDefault.xctoolchain/usr/lib' end |
#dyld_library_path ⇒ Object
95 96 97 |
# File 'lib/xcinvoke/xcode.rb', line 95 def dyld_library_path developer_dir + 'Toolchains/XcodeDefault.xctoolchain/usr/lib' end |
#swift_version ⇒ Object
40 41 42 43 |
# File 'lib/xcinvoke/xcode.rb', line 40 def swift_version info = swift_info Gem::Version.new(info.first) if info end |
#version ⇒ Object
50 51 52 53 |
# File 'lib/xcinvoke/xcode.rb', line 50 def version build = build_number Liferaft::Version.new(build) if build end |
#xcrun(cmd, env: {}, err: false) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/xcinvoke/xcode.rb', line 59 def xcrun(cmd, env: {}, err: false) env = env.merge(as_env) # xcrun self-lookup is a workaround for issues caused by having # multiple very old versions of Xcode installed # (see https://github.com/segiddins/xcinvoke/issues/3) @xcrun_path ||= Open3.capture3('xcrun', '-f', 'xcrun').first.strip # Env-based lookup is necessary for Xcode ≥8 @xcrun_path = 'xcrun' if @xcrun_path == '' cmd = [@xcrun_path] + cmd case err when :merge oe, = Open3.capture2e(env, *cmd) oe else o, e, = Open3.capture3(env, *cmd) err ? [o, e] : o end end |