Commit 76345711 authored by Eloy Durán's avatar Eloy Durán

Clean pods *after* resolving and activating. Fixes #414.

parent 135ce81b
...@@ -7,7 +7,7 @@ group :development do ...@@ -7,7 +7,7 @@ group :development do
gem "mocha", "~> 0.11.4" gem "mocha", "~> 0.11.4"
gem "bacon" gem "bacon"
gem "kicker" gem "kicker", "~> 3.0.0pre1"
gem "mocha-on-bacon" gem "mocha-on-bacon"
gem "rake" gem "rake"
gem "rb-fsevent" gem "rb-fsevent"
......
...@@ -41,7 +41,7 @@ GEM ...@@ -41,7 +41,7 @@ GEM
hashie (1.2.0) hashie (1.2.0)
i18n (0.6.0) i18n (0.6.0)
json (1.7.3) json (1.7.3)
kicker (2.6.1) kicker (3.0.0pre1)
listen listen
listen (0.4.7) listen (0.4.7)
rb-fchange (~> 0.0.5) rb-fchange (~> 0.0.5)
...@@ -88,7 +88,7 @@ DEPENDENCIES ...@@ -88,7 +88,7 @@ DEPENDENCIES
bacon bacon
cocoapods! cocoapods!
github-markup github-markup
kicker kicker (~> 3.0.0pre1)
mocha (~> 0.11.4) mocha (~> 0.11.4)
mocha-on-bacon mocha-on-bacon
pry pry
......
...@@ -146,16 +146,20 @@ module Pod ...@@ -146,16 +146,20 @@ module Pod
end end
def specification_from_sandbox(sandbox, platform) def specification_from_sandbox(sandbox, platform)
specification_from_local(sandbox, platform) || specification_from_external(sandbox, platform)
end
def specification_from_local(sandbox, platform)
if local_pod = sandbox.installed_pod_named(name, platform) if local_pod = sandbox.installed_pod_named(name, platform)
local_pod.top_specification local_pod.top_specification
else
copy_external_source_into_sandbox(sandbox)
local_pod = sandbox.installed_pod_named(name, platform)
local_pod.clean if config.clean? && local_pod.exists?
local_pod.top_specification
end end
end end
def specification_from_external(sandbox, platform)
copy_external_source_into_sandbox(sandbox, platform)
specification_from_local(sandbox, platform)
end
def ==(other_source) def ==(other_source)
return if other_source.nil? return if other_source.nil?
name == other_source.name && params == other_source.params name == other_source.name && params == other_source.params
...@@ -163,10 +167,12 @@ module Pod ...@@ -163,10 +167,12 @@ module Pod
end end
class GitSource < AbstractExternalSource class GitSource < AbstractExternalSource
def copy_external_source_into_sandbox(sandbox) def copy_external_source_into_sandbox(sandbox, platform)
puts " * Pre-downloading: '#{name}'" unless config.silent? puts " * Pre-downloading: '#{name}'" unless config.silent?
Downloader.for_target(sandbox.root + name, @params).tap do |downloader| downloader = Downloader.for_target(sandbox.root + name, @params)
downloader.download downloader.download
if local_pod = sandbox.installed_pod_named(name, platform)
local_pod.downloaded = true
end end
end end
...@@ -181,7 +187,7 @@ module Pod ...@@ -181,7 +187,7 @@ module Pod
# can be http, file, etc # can be http, file, etc
class PodspecSource < AbstractExternalSource class PodspecSource < AbstractExternalSource
def copy_external_source_into_sandbox(sandbox) def copy_external_source_into_sandbox(sandbox, _)
output_path = sandbox.root + "Local Podspecs/#{name}.podspec" output_path = sandbox.root + "Local Podspecs/#{name}.podspec"
output_path.dirname.mkpath output_path.dirname.mkpath
puts " * Fetching podspec for `#{name}' from: #{@params[:podspec]}" unless config.silent? puts " * Fetching podspec for `#{name}' from: #{@params[:podspec]}" unless config.silent?
......
...@@ -57,12 +57,17 @@ module Pod ...@@ -57,12 +57,17 @@ module Pod
puts marker << ( pod.exists? ? "Using #{name}" : "Installing #{name}".green ) puts marker << ( pod.exists? ? "Using #{name}" : "Installing #{name}".green )
end end
unless pod.exists? download_pod(pod) unless pod.exists?
download_pod(pod)
# The docs need to be generated before cleaning because # This will not happen if the pod existed before we started the install
# the documentation is created for all the subspecs. # process.
if pod.downloaded?
# The docs need to be generated before cleaning because the
# documentation is created for all the subspecs.
generate_docs(pod) generate_docs(pod)
pod.clean if config.clean # Here we clean pod's that just have been downloaded or have been
# pre-downloaded in AbstractExternalSource#specification_from_sandbox.
pod.clean! if config.clean?
end end
end end
end end
...@@ -79,6 +84,7 @@ module Pod ...@@ -79,6 +84,7 @@ module Pod
else else
downloader.download downloader.download
end end
pod.downloaded = true
end end
#TODO: move to generator ? #TODO: move to generator ?
...@@ -207,18 +213,12 @@ module Pod ...@@ -207,18 +213,12 @@ module Pod
specs_by_target.each do |target_definition, specs| specs_by_target.each do |target_definition, specs|
@pods_by_spec[target_definition.platform] = {} @pods_by_spec[target_definition.platform] = {}
result[target_definition] = specs.map do |spec| result[target_definition] = specs.map do |spec|
pod = pod_for_spec(spec, target_definition.platform) @sandbox.local_pod_for_spec(spec, target_definition.platform)
pod.add_specification(spec)
pod
end.uniq.compact end.uniq.compact
end end
result result
end end
def pod_for_spec(spec, platform)
@pods_by_spec[platform][spec.top_level_parent.name] ||= LocalPod.new(spec, @sandbox, platform)
end
private private
def print_title(title, only_verbose = true) def print_title(title, only_verbose = true)
......
...@@ -38,6 +38,13 @@ module Pod ...@@ -38,6 +38,13 @@ module Pod
# #
attr_reader :platform attr_reader :platform
# @return [Boolean] Wether or not the pod has been downloaded in the
# current install process and still needs its docs
# generated and be cleaned.
#
attr_accessor :downloaded
alias_method :downloaded?, :downloaded
# @param [Specification] specification # @param [Specification] specification
# The first activated specification of the pod. # The first activated specification of the pod.
# @param [Sandbox] sandbox # @param [Sandbox] sandbox
...@@ -139,7 +146,7 @@ module Pod ...@@ -139,7 +146,7 @@ module Pod
# #
# @return [void] # @return [void]
# #
def clean def clean!
clean_paths.each { |path| FileUtils.rm_rf(path) } clean_paths.each { |path| FileUtils.rm_rf(path) }
@cleaned = true @cleaned = true
end end
...@@ -299,8 +306,8 @@ module Pod ...@@ -299,8 +306,8 @@ module Pod
# #
def all_specs_public_header_files def all_specs_public_header_files
if @cleaned if @cleaned
raise Informative, "The pod is cleaned and cannot compute the all the "\ raise Informative, "The pod is cleaned and cannot compute the " \
"header files as they might be deleted." "header files, as some might have been deleted."
end end
all_specs = [ top_specification ] + top_specification.subspecs all_specs = [ top_specification ] + top_specification.subspecs
......
...@@ -9,6 +9,7 @@ module Pod ...@@ -9,6 +9,7 @@ module Pod
def initialize(path) def initialize(path)
@root = Pathname.new(path) @root = Pathname.new(path)
@header_search_paths = [HEADERS_DIR] @header_search_paths = [HEADERS_DIR]
@cached_local_pods = {}
FileUtils.mkdir_p(@root) FileUtils.mkdir_p(@root)
end end
...@@ -56,17 +57,25 @@ module Pod ...@@ -56,17 +57,25 @@ module Pod
headers_root.rmtree if headers_root.exist? headers_root.rmtree if headers_root.exist?
end end
def podspec_for_name(name) def local_pod_for_spec(spec, platform)
if spec_path = Dir[root + "#{name}/*.podspec"].first key = [spec.top_level_parent.name, platform.to_sym]
Pathname.new(spec_path) (@cached_local_pods[key] ||= LocalPod.new(spec.top_level_parent, self, platform)).tap do |pod|
elsif spec_path = Dir[root + "Local Podspecs/#{name}.podspec"].first pod.add_specification(spec)
Pathname.new(spec_path)
end end
end end
def installed_pod_named(name, platform) def installed_pod_named(name, platform)
if spec_path = podspec_for_name(name) if spec_path = podspec_for_name(name)
LocalPod.from_podspec(spec_path, self, platform) key = [name, platform.to_sym]
@cached_local_pods[key] ||= LocalPod.from_podspec(spec_path, self, platform)
end
end
def podspec_for_name(name)
if spec_path = Dir[root + "#{name}/*.podspec"].first
Pathname.new(spec_path)
elsif spec_path = Dir[root + "Local Podspecs/#{name}.podspec"].first
Pathname.new(spec_path)
end end
end end
end end
......
...@@ -88,5 +88,19 @@ module Pod ...@@ -88,5 +88,19 @@ module Pod
end end
end end
end end
describe Dependency::ExternalSources::GitSource do
before do
@dependency = Dependency.new("cocoapods", :git => "git://github.com/cocoapods/cocoapods")
end
it "marks a LocalPod as downloaded if it's downloaded" do
Downloader.stubs(:for_target).returns(stub_everything)
pod = mock('LocaPod', :downloaded= => true)
sandbox = stub('Sandbox', :root => '', :installed_pod_named => pod)
@dependency.external_source.copy_external_source_into_sandbox(sandbox, Platform.ios)
end
end
end end
end end
...@@ -76,4 +76,38 @@ describe Pod::Sandbox do ...@@ -76,4 +76,38 @@ describe Pod::Sandbox do
@sandbox.prepare_for_install @sandbox.prepare_for_install
@sandbox.headers_root.should.not.exist @sandbox.headers_root.should.not.exist
end end
it "returns the path to a spec file in the root of the pod's dir" do
FileUtils.cp_r(fixture('banana-lib'), @sandbox.root + 'BananaLib')
@sandbox.podspec_for_name('BananaLib').should == @sandbox.root + 'BananaLib/BananaLib.podspec'
end
it "returns the path to a spec file in the 'Local Podspecs' dir" do
(@sandbox.root + 'Local Podspecs').mkdir
FileUtils.cp(fixture('banana-lib') + 'BananaLib.podspec', @sandbox.root + 'Local Podspecs')
@sandbox.podspec_for_name('BananaLib').should == @sandbox.root + 'Local Podspecs/BananaLib.podspec'
end
it "returns a LocalPod for a spec file in the sandbox" do
FileUtils.cp_r(fixture('banana-lib'), @sandbox.root + 'BananaLib')
pod = @sandbox.installed_pod_named('BananaLib', Pod::Platform.ios)
pod.should.be.instance_of Pod::LocalPod
pod.top_specification.name.should == 'BananaLib'
end
it "returns a LocalPod for a spec instance which source is expected to be in the sandbox" do
spec = Pod::Specification.from_file(fixture('banana-lib') + 'BananaLib.podspec')
pod = @sandbox.local_pod_for_spec(spec, Pod::Platform.ios)
pod.should.be.instance_of Pod::LocalPod
pod.top_specification.name.should == 'BananaLib'
end
it "always returns the same cached LocalPod instance for the same spec and platform" do
FileUtils.cp_r(fixture('banana-lib'), @sandbox.root + 'BananaLib')
spec = Pod::Specification.from_file(@sandbox.root + 'BananaLib/BananaLib.podspec')
pod = @sandbox.installed_pod_named('BananaLib', Pod::Platform.ios)
@sandbox.installed_pod_named('BananaLib', Pod::Platform.ios).should.eql pod
@sandbox.local_pod_for_spec(spec, Pod::Platform.ios).should.eql pod
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