Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to install CLI tools #350

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ to a dialog popping up. Feel free to dupe [the radar][5]. 📡

XcodeInstall normally relies on the Spotlight index to locate installed versions of Xcode. If you use it while
indexing is happening, it might show inaccurate results and it will not be able to see installed
versions on unindexed volumes.
versions on unindexed volumes.

To workaround the Spotlight limitation, XcodeInstall searches `/Applications` folder to locate Xcodes when Spotlight is disabled on the machine, or when Spotlight query for Xcode does not return any results. But it still won't work if your Xcodes are not located under `/Applications` folder.

Expand Down
17 changes: 10 additions & 7 deletions lib/xcode/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def fetch(url: nil,
progress: nil,
progress_block: nil)
options = cookies.nil? ? [] : ['--cookie', cookies, '--cookie-jar', COOKIES_PATH]

uri = URI.parse(url)
output ||= File.basename(uri.path)
output = (Pathname.new(directory) + Pathname.new(output)) if directory
Expand Down Expand Up @@ -329,7 +328,7 @@ def mount(dmg_path)
node.text
end

private
#private

def spaceship
@spaceship ||= begin
Expand Down Expand Up @@ -379,7 +378,7 @@ def fetch_seedlist
'/services-account/QH65B2/downloadws/listDownloads.action').body)

names = @xcodes.map(&:name)
@xcodes += prereleases.reject { |pre| names.include?(pre.name) }
# @xcodes += prereleases.reject { |pre| names.include?(pre.name) }

File.open(LIST_FILE, 'wb') do |f|
f << Marshal.dump(xcodes)
Expand Down Expand Up @@ -442,10 +441,14 @@ def prereleases

return [] if scan.empty?

version = scan.first.gsub(/<.*?>/, '').gsub(/.*Xcode /, '')
link = body.scan(%r{<button .*"(.+?.(dmg|xip))".*</button>}).first.first
notes = body.scan(%r{<a.+?href="(/go/\?id=xcode-.+?)".*>(.*)</a>}).first.first
links << Xcode.new(version, link, notes)
begin
version = scan.first.gsub(/<.*?>/, '').gsub(/.*Xcode /, '')
link = body.scan(%r{<button .*"(.+?.(dmg|xip))".*</button>}).first.first
notes = body.scan(%r{<a.+?href="(/go/\?id=xcode-.+?)".*>(.*)</a>}).first.first
links << Xcode.new(version, link, notes)
rescue StandardError => e
print "Error finding prerelease Xcode" + e
end
end

links
Expand Down
3 changes: 2 additions & 1 deletion lib/xcode/install/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class Command < CLAide::Command
require 'xcode/install/list'
require 'xcode/install/select'
require 'xcode/install/selected'
require 'xcode/install/simulators'
require 'xcode/install/tools.rb'
require 'xcode/install/uninstall'
require 'xcode/install/update'
require 'xcode/install/simulators'

self.abstract_command = true
self.command = 'xcversion'
Expand Down
62 changes: 62 additions & 0 deletions lib/xcode/install/tools.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'claide'
require 'spaceship'

module XcodeInstall
class Command
class Tools < Command
self.command = 'tools'
self.summary = 'List or install Xcode CLI tools.'

def self.options
[['--install=name', 'Install simulator beginning with name, e.g. \'iOS 8.4\', \'tvOS 9.0\'.'],
['--force', 'Install even if the same version is already installed.'],
['--no-install', 'Only download DMG, but do not install it.'],
['--no-progress', 'Don’t show download progress.']].concat(super)
end

def initialize(argv)
@install = argv.option('install')
@force = argv.flag?('force', false)
@should_install = argv.flag?('install', true)
@progress = argv.flag?('progress', true)
@installer = XcodeInstall::Installer.new
super
end

def run
@install ? install : list
end

:private

def download(package)
puts("Downloading #{package}")
url = 'https://developer.apple.com/devcenter/download.action?path=' + package
dmg_file = File.basename(url)
Curl.new.fetch(
url: url,
directory: XcodeInstall::CACHE_DIR,
cookies: @installer.spaceship.cookie,
output: dmg_file,
progress: false
)
XcodeInstall::CACHE_DIR + dmg_file
end

def install
dmg_path = download(@install)
puts("Downloaded to from #{dmg_path}")
mount_dir = @installer.mount(dmg_path)
puts("Mounted to #{mount_dir}")
pkg_path = Dir.glob(File.join(mount_dir, '*.pkg')).first
puts("Installing from #{pkg_path}")
prompt = "Please authenticate to install Command Line Tools.\nPassword: "
`sudo -p "#{prompt}" installer -verbose -pkg "#{pkg_path}" -target /`
end

def list
raise NotImplementedError, 'Listing is not implemented'
end
end
end
end
2 changes: 1 addition & 1 deletion xcode-install.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
# contains spaceship, which is used for auth and dev portal interactions
spec.add_dependency 'fastlane', '>= 2.1.0', '< 3.0.0'

spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'bundler', '~> 2.0.2'
spec.add_development_dependency 'rake', '~> 10.0'
end