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.
26 27 28 |
# File 'lib/xcinvoke/xcode.rb', line 26 def initialize(path) @developer_dir = Pathname(path) end |
Instance Attribute Details
#developer_dir ⇒ Object (readonly)
Returns the value of attribute developer_dir.
24 25 26 |
# File 'lib/xcinvoke/xcode.rb', line 24 def developer_dir @developer_dir end |
Class Method Details
.all ⇒ Object
47 48 49 |
# File 'lib/xcinvoke/xcode.rb', line 47 def self.all to_a end |
.each(&blk) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/xcinvoke/xcode.rb', line 35 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
51 52 53 54 |
# File 'lib/xcinvoke/xcode.rb', line 51 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
30 31 32 33 |
# File 'lib/xcinvoke/xcode.rb', line 30 def self.selected dir, = Open3.capture2('xcode-select', '-p', err: '/dev/null') new(dir.strip) end |
Instance Method Details
#<=>(other) ⇒ Object
71 72 73 |
# File 'lib/xcinvoke/xcode.rb', line 71 def <=>(other) version <=> other.version end |
#as_env ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/xcinvoke/xcode.rb', line 91 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
61 62 63 64 |
# File 'lib/xcinvoke/xcode.rb', line 61 def build_number info = xcodebuild_info info[1] if info end |
#dyld_framework_path ⇒ Object
101 102 103 |
# File 'lib/xcinvoke/xcode.rb', line 101 def dyld_framework_path developer_dir + 'Toolchains/XcodeDefault.xctoolchain/usr/lib' end |
#dyld_library_path ⇒ Object
105 106 107 |
# File 'lib/xcinvoke/xcode.rb', line 105 def dyld_library_path developer_dir + 'Toolchains/XcodeDefault.xctoolchain/usr/lib' end |
#swift_version ⇒ Object
56 57 58 59 |
# File 'lib/xcinvoke/xcode.rb', line 56 def swift_version info = swift_info Gem::Version.new(info.first) if info end |
#version ⇒ Object
66 67 68 69 |
# File 'lib/xcinvoke/xcode.rb', line 66 def version build = build_number Liferaft::Version.new(build) if build end |
#xcrun(cmd, env: {}, err: false) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/xcinvoke/xcode.rb', line 75 def xcrun(cmd, env: {}, err: false) env = env.merge(as_env) # explicitly dont use the env when computing the full path to xcrun @xcrun_path ||= Open3.capture2('xcrun', '-f', 'xcrun').first.strip 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 |