Commit af1c8727 authored by Samuel E. Giddins's avatar Samuel E. Giddins

[Downloader] Centralize downloading in Downloader.download

parent 3a30b7a2
...@@ -15,6 +15,7 @@ module Pod ...@@ -15,6 +15,7 @@ module Pod
:verbose => false, :verbose => false,
:silent => false, :silent => false,
:skip_repo_update => false, :skip_repo_update => false,
:skip_download_cache => !ENV['COCOAPODS_SKIP_CACHE'].nil?,
:clean => true, :clean => true,
:integrate_targets => true, :integrate_targets => true,
...@@ -66,6 +67,11 @@ module Pod ...@@ -66,6 +67,11 @@ module Pod
attr_accessor :skip_repo_update attr_accessor :skip_repo_update
alias_method :skip_repo_update?, :skip_repo_update alias_method :skip_repo_update?, :skip_repo_update
# @return [Bool] Whether the installer should skip the download cache.
#
attr_accessor :skip_download_cache
alias_method :skip_download_cache?, :skip_download_cache
public public
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -82,10 +88,6 @@ module Pod ...@@ -82,10 +88,6 @@ module Pod
@cache_root @cache_root
end end
def download_cache
@download_cache ||= Downloader::Cache.new(cache_root + 'Pods')
end
public public
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
......
require 'cocoapods-downloader' require 'cocoapods-downloader'
require 'claide/informative_error' require 'claide/informative_error'
require 'fileutils'
require 'tmpdir'
module Pod module Pod
module Downloader module Downloader
require 'cocoapods/downloader/cache' require 'cocoapods/downloader/cache'
def self.download(
name_or_spec,
download_target,
released: false,
downloader_options: nil,
head: false,
cache_path: !Config.instance.skip_download_cache && Config.instance.cache_root + 'Pods'
)
cache_path, tmp_cache = Pathname(Dir.mktmpdir), true unless cache_path
cache = Cache.new(cache_path)
result = cache.download_pod(name_or_spec, released, downloader_options, head)
if download_target
FileUtils.rm_rf download_target
FileUtils.cp_r(result.location, download_target)
end
result
ensure
FileUtils.rm_r cache_path if tmp_cache
end
class DownloaderError; include CLAide::InformativeError; end class DownloaderError; include CLAide::InformativeError; end
class Base class Base
......
...@@ -98,11 +98,7 @@ module Pod ...@@ -98,11 +98,7 @@ module Pod
title = "Pre-downloading: `#{name}` #{description}" title = "Pre-downloading: `#{name}` #{description}"
UI.titled_section(title, :verbose_prefix => '-> ') do UI.titled_section(title, :verbose_prefix => '-> ') do
target = sandbox.pod_dir(name) target = sandbox.pod_dir(name)
target.rmtree if target.exist? download_result = Downloader.download(name, target, :downloader_options => params)
download_result = Config.instance.download_cache.download_pod(name, false, params)
FileUtils.cp_r(download_result.location, target)
spec = download_result.spec spec = download_result.spec
raise Informative, "Unable to find a specification for '#{name}'." unless spec raise Informative, "Unable to find a specification for '#{name}'." unless spec
......
...@@ -8,8 +8,6 @@ module Pod ...@@ -8,8 +8,6 @@ module Pod
# @note This class needs to consider all the activated specs of a Pod. # @note This class needs to consider all the activated specs of a Pod.
# #
class PodSourceInstaller class PodSourceInstaller
include Config::Mixin
# @return [Sandbox] # @return [Sandbox]
# #
attr_reader :sandbox attr_reader :sandbox
...@@ -76,9 +74,7 @@ module Pod ...@@ -76,9 +74,7 @@ module Pod
# @return [void] # @return [void]
# #
def download_source def download_source
download_result = config.download_cache.download_pod(root_spec, released?, nil, head_pod?) download_result = Downloader.download(root_spec, root, :released => released?, :head => head_pod?)
root.rmtree if root.exist?
FileUtils.cp_r(download_result.location, root)
if @specific_source = download_result.checkout_options if @specific_source = download_result.checkout_options
sandbox.store_checkout_source(root_spec.name, specific_source) sandbox.store_checkout_source(root_spec.name, specific_source)
......
...@@ -99,7 +99,7 @@ describe_cli 'pod' do ...@@ -99,7 +99,7 @@ describe_cli 'pod' do
s.executable = "ruby #{ROOT + 'bin/pod'}" s.executable = "ruby #{ROOT + 'bin/pod'}"
s.environment_vars = { s.environment_vars = {
'CP_REPOS_DIR' => ROOT + 'spec/fixtures/spec-repos', 'CP_REPOS_DIR' => ROOT + 'spec/fixtures/spec-repos',
'CP_AGGRESSIVE_CACHE' => 'TRUE', 'COCOAPODS_SKIP_CACHE' => 'TRUE',
'XCODEPROJ_DISABLE_XCPROJ' => 'TRUE', 'XCODEPROJ_DISABLE_XCPROJ' => 'TRUE',
'CLAIDE_DISABLE_AUTO_WRAP' => 'TRUE', 'CLAIDE_DISABLE_AUTO_WRAP' => 'TRUE',
} }
......
...@@ -43,17 +43,6 @@ module Pod ...@@ -43,17 +43,6 @@ module Pod
}, },
} }
end end
it 'checks for JSON podspecs' do
path = config.download_cache.send(:path_for_pod, 'Reachability', nil, @subject.params)
podspec_path = path + 'Reachability.podspec.json'
path.mkpath
File.open(podspec_path, 'w') { |f| f.write '{"name":"Reachability"}' }
Pathname.any_instance.stubs(:rmtree)
Downloader::Git.any_instance.stubs(:download)
config.sandbox.expects(:store_podspec).with('Reachability', %({\n "name": "Reachability"\n}\n), true, true)
@subject.send(:pre_download, config.sandbox)
end
end end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment