class XcodeInstall::InstalledXcode

Constants

AUTHORITY
TEAM_IDENTIFIER

Attributes

available_simulators[R]
bundle_version[R]
downloadable_index_url[R]
path[R]
uuid[R]
version[R]

Public Class Methods

new(path) click to toggle source
# File lib/xcode/install.rb, line 589
def initialize(path)
  @path = Pathname.new(path)
end

Public Instance Methods

approve_license() click to toggle source
# File lib/xcode/install.rb, line 615
def approve_license
  if Gem::Version.new(version) < Gem::Version.new('7.3')
    license_info_path = File.join(@path, 'Contents/Resources/LicenseInfo.plist')
    license_id = `/usr/libexec/PlistBuddy -c 'Print :licenseID' #{license_info_path}`
    license_type = `/usr/libexec/PlistBuddy -c 'Print :licenseType' #{license_info_path}`
    license_plist_path = '/Library/Preferences/com.apple.dt.Xcode.plist'
    `sudo rm -rf #{license_plist_path}`
    if license_type == 'GM'
      `sudo /usr/libexec/PlistBuddy -c "add :IDELastGMLicenseAgreedTo string #{license_id}" #{license_plist_path}`
      `sudo /usr/libexec/PlistBuddy -c "add :IDEXcodeVersionForAgreedToGMLicense string #{version}" #{license_plist_path}`
    else
      `sudo /usr/libexec/PlistBuddy -c "add :IDELastBetaLicenseAgreedTo string #{license_id}" #{license_plist_path}`
      `sudo /usr/libexec/PlistBuddy -c "add :IDEXcodeVersionForAgreedToBetaLicense string #{version}" #{license_plist_path}`
    end
  else
    `sudo #{@path}/Contents/Developer/usr/bin/xcodebuild -license accept`
  end
end
bundle_version_string() click to toggle source
# File lib/xcode/install.rb, line 671
def bundle_version_string
  digits = plist_entry(':DTXcode').to_i.to_s
  if digits.length < 3
    digits.split(//).join('.')
  else
    "#{digits[0..-3]}.#{digits[-2]}.#{digits[-1]}"
  end
end
fetch_version() click to toggle source

This method might take a few ms, this could be improved by implementing github.com/KrauseFx/xcode-install/issues/273

# File lib/xcode/install.rb, line 659
def fetch_version
  output = `DEVELOPER_DIR='' "#{@path}/Contents/Developer/usr/bin/xcodebuild" -version`
  return '0.0' if output.nil? || output.empty? # ¯\_(ツ)_/¯
  output.split("\n").first.split(' ')[1]
end
install_components() click to toggle source
# File lib/xcode/install.rb, line 642
def install_components
  # starting with Xcode 9, we have `xcodebuild -runFirstLaunch` available to do package
  # postinstalls using a documented option
  if Gem::Version.new(version) >= Gem::Version.new('9')
    `sudo #{@path}/Contents/Developer/usr/bin/xcodebuild -runFirstLaunch`
  else
    Dir.glob("#{@path}/Contents/Resources/Packages/*.pkg").each do |pkg|
      `sudo installer -pkg #{pkg} -target /`
    end
  end
  osx_build_version = `sw_vers -buildVersion`.chomp
  tools_version = `/usr/libexec/PlistBuddy -c "Print :ProductBuildVersion" "#{@path}/Contents/version.plist"`.chomp
  cache_dir = `getconf DARWIN_USER_CACHE_DIR`.chomp
  `touch #{cache_dir}com.apple.dt.Xcode.InstallCheckCache_#{osx_build_version}_#{tools_version}`
end
plist_entry(keypath) click to toggle source
# File lib/xcode/install.rb, line 680
def plist_entry(keypath)
  `/usr/libexec/PlistBuddy -c "Print :#{keypath}" "#{path}/Contents/Info.plist"`.chomp
end
verify_app_cert() click to toggle source
# File lib/xcode/install.rb, line 689
def verify_app_cert
  cert_info = Fastlane::Actions::VerifyBuildAction.gather_cert_info(@path.to_s)
  apple_team_identifier_result = cert_info['team_identifier'] == TEAM_IDENTIFIER
  apple_authority_result = cert_info['authority'].include?(AUTHORITY)
  apple_team_identifier_result && apple_authority_result
end
verify_app_security_assessment() click to toggle source
# File lib/xcode/install.rb, line 684
def verify_app_security_assessment
  puts `/usr/sbin/spctl --assess --verbose=4 --type execute #{@path}`
  $?.exitstatus.zero?
end
verify_integrity() click to toggle source
# File lib/xcode/install.rb, line 665
def verify_integrity
  verify_app_security_assessment && verify_app_cert
end