Class: XcodeInstall::InstalledXcode

Inherits:
Object
  • Object
show all
Defined in:
lib/xcode/install.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ InstalledXcode

Returns a new instance of InstalledXcode.



592
593
594
# File 'lib/xcode/install.rb', line 592

def initialize(path)
  @path = Pathname.new(path)
end

Instance Attribute Details

#available_simulatorsObject (readonly)

Returns the value of attribute available_simulators.



590
591
592
# File 'lib/xcode/install.rb', line 590

def available_simulators
  @available_simulators
end

#bundle_versionObject (readonly)

Returns the value of attribute bundle_version.



587
588
589
# File 'lib/xcode/install.rb', line 587

def bundle_version
  @bundle_version
end

#downloadable_index_urlObject (readonly)

Returns the value of attribute downloadable_index_url.



589
590
591
# File 'lib/xcode/install.rb', line 589

def downloadable_index_url
  @downloadable_index_url
end

#pathObject (readonly)

Returns the value of attribute path.



585
586
587
# File 'lib/xcode/install.rb', line 585

def path
  @path
end

#uuidObject (readonly)

Returns the value of attribute uuid.



588
589
590
# File 'lib/xcode/install.rb', line 588

def uuid
  @uuid
end

#versionObject (readonly)

Returns the value of attribute version.



586
587
588
# File 'lib/xcode/install.rb', line 586

def version
  @version
end

Instance Method Details

#approve_licenseObject



618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
# File 'lib/xcode/install.rb', line 618

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_stringObject



674
675
676
677
678
679
680
681
# File 'lib/xcode/install.rb', line 674

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_versionObject

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



662
663
664
665
666
# File 'lib/xcode/install.rb', line 662

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_componentsObject



645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/xcode/install.rb', line 645

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) ⇒ Object



683
684
685
# File 'lib/xcode/install.rb', line 683

def plist_entry(keypath)
  `/usr/libexec/PlistBuddy -c "Print :#{keypath}" "#{path}/Contents/Info.plist"`.chomp
end

#verify_app_certObject



692
693
694
695
696
697
# File 'lib/xcode/install.rb', line 692

def verify_app_cert
  Fastlane::Actions::VerifyXcodeAction.run(xcode_path: @path.to_s)
  true
rescue
  false
end

#verify_app_security_assessmentObject



687
688
689
690
# File 'lib/xcode/install.rb', line 687

def verify_app_security_assessment
  puts `/usr/bin/codesign --verify --verbose #{@path}`
  $?.exitstatus.zero?
end

#verify_integrityObject



668
669
670
# File 'lib/xcode/install.rb', line 668

def verify_integrity
  verify_app_security_assessment && verify_app_cert
end