class Xcode

Constants

DEFAULT_XCODE_PATHS

Hardcoded paths in case mdfind is not working because Spotlight is disabled

XCODE_BUNDLE_IDENTIFIER

Attributes

signed[RW]

Public Class Methods

find_xcodes() click to toggle source
# File lib/xcode.rb, line 13
def self.find_xcodes
  output = `mdfind kMDItemCFBundleIdentifier = "#{XCODE_BUNDLE_IDENTIFIER}"`
  paths = output.lines + DEFAULT_XCODE_PATHS

  paths.map(&:strip).uniq.collect do |xcode_path|
    Xcode.from_bundle(xcode_path)
  end.compact.keep_if(&:valid?)
end
from_bundle(path) click to toggle source
# File lib/xcode.rb, line 22
def self.from_bundle(path)
  xcode = new(path)
  xcode.valid? ? xcode : nil
end

Public Instance Methods

binary_restorable?() click to toggle source
# File lib/xcode.rb, line 48
def binary_restorable?
  File.exist?("#{binary_path}.signed")
end
detailed_description() click to toggle source
# File lib/xcode.rb, line 84
def detailed_description
  "Xcode (#{version}) [#{uuid}]: #{path}"
end
restorable?() click to toggle source
# File lib/xcode.rb, line 44
def restorable?
  binary_restorable? || xcodebuild_restorable?
end
restore_binary!() click to toggle source
# File lib/xcode.rb, line 64
def restore_binary!
  restore!(binary_path)
end
restore_xcodebuild!() click to toggle source
# File lib/xcode.rb, line 68
def restore_xcodebuild!
  restore!(xcodebuild_path)
end
signed?() click to toggle source
# File lib/xcode.rb, line 35
def signed?
  if signed.nil?
    self.signed = `codesign -dv "#{path}" 2>/dev/null` &&
                  $CHILD_STATUS.exitstatus == 0
  end

  signed
end
to_s() click to toggle source
# File lib/xcode.rb, line 76
def to_s
  unless signed.nil?
    codesign_status = signed ? ' [Signed]' : ' [Unsigned]'
  end

  "Xcode (#{version})#{codesign_status}: #{path}"
end
unsign_binary!() click to toggle source
# File lib/xcode.rb, line 56
def unsign_binary!
  unsign!(binary_path)
end
unsign_xcodebuild!() click to toggle source
# File lib/xcode.rb, line 60
def unsign_xcodebuild!
  unsign!(xcodebuild_path)
end
uuid() click to toggle source
# File lib/xcode.rb, line 72
def uuid
  defaults_read('DVTPlugInCompatibilityUUID')
end
valid?() click to toggle source
# File lib/xcode.rb, line 27
def valid?
  is_app = path.end_with?('.app')
  has_info = File.exist?(info_path)
  return false unless is_app && has_info

  bundle_identifier == XCODE_BUNDLE_IDENTIFIER
end
xcodebuild_restorable?() click to toggle source
# File lib/xcode.rb, line 52
def xcodebuild_restorable?
  File.exist?("#{xcodebuild_path}.signed")
end

Private Instance Methods

binary_path() click to toggle source
# File lib/xcode.rb, line 90
def binary_path
  "#{path}/Contents/MacOS/Xcode"
end
restore!(target) click to toggle source
# File lib/xcode.rb, line 118
def restore!(target)
  signed_target = "#{target}.signed"

  CLI.chown_if_required(File.dirname(target)) do
    File.exist?(signed_target) &&
      File.exist?(target) &&
      FileUtils.mv(signed_target, target)
  end
end
unsign!(target) click to toggle source
# File lib/xcode.rb, line 104
def unsign!(target)
  unsigned_target = "#{target}.unsigned"
  signed_target = "#{target}.signed"

  CLI.chown_if_required(File.dirname(target)) do
    `#{unsign_path} "#{target}"` &&
      $CHILD_STATUS.exitstatus == 0
      File.exist?(unsigned_target) &&
      FileUtils.mv(target, signed_target) &&
      File.exist?(signed_target) &&
      FileUtils.mv(unsigned_target, target)
  end
end
unsign_path() click to toggle source
# File lib/xcode.rb, line 98
def unsign_path
  lib_path = File.expand_path(File.dirname(__FILE__))

  "#{lib_path}/bin/unsign"
end
xcodebuild_path() click to toggle source
# File lib/xcode.rb, line 94
def xcodebuild_path
  "#{path}/Contents/Developer/usr/bin/xcodebuild"
end