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.



462
463
464
# File 'lib/xcode/install.rb', line 462

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

Instance Attribute Details

#available_simulatorsObject (readonly)

Returns the value of attribute available_simulators.



460
461
462
# File 'lib/xcode/install.rb', line 460

def available_simulators
  @available_simulators
end

#bundle_versionObject (readonly)

Returns the value of attribute bundle_version.



457
458
459
# File 'lib/xcode/install.rb', line 457

def bundle_version
  @bundle_version
end

#downloadable_index_urlObject (readonly)

Returns the value of attribute downloadable_index_url.



459
460
461
# File 'lib/xcode/install.rb', line 459

def downloadable_index_url
  @downloadable_index_url
end

#pathObject (readonly)

Returns the value of attribute path.



455
456
457
# File 'lib/xcode/install.rb', line 455

def path
  @path
end

#uuidObject (readonly)

Returns the value of attribute uuid.



458
459
460
# File 'lib/xcode/install.rb', line 458

def uuid
  @uuid
end

#versionObject (readonly)

Returns the value of attribute version.



456
457
458
# File 'lib/xcode/install.rb', line 456

def version
  @version
end

Instance Method Details

#approve_licenseObject



488
489
490
491
492
493
494
495
# File 'lib/xcode/install.rb', line 488

def approve_license
  license_path = "#{@path}/Contents/Resources/English.lproj/License.rtf"
  license_id = IO.read(license_path).match(/\bEA\d{4}\b/)
  license_plist_path = '/Library/Preferences/com.apple.dt.Xcode.plist'
  `sudo rm -rf #{license_plist_path}`
  `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}`
end

#fetch_versionObject



527
528
529
530
531
# File 'lib/xcode/install.rb', line 527

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



505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# File 'lib/xcode/install.rb', line 505

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



523
524
525
# File 'lib/xcode/install.rb', line 523

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