Commit e65536b2 authored by Eloy Duran's avatar Eloy Duran

Make sure that a pod's spec is not installed if it's only part of other pods.

parent 2b933ce8
...@@ -3,7 +3,8 @@ module Pod ...@@ -3,7 +3,8 @@ module Pod
class Install < Command class Install < Command
def run def run
if spec = Specification.from_podfile(podfile) if spec = Specification.from_podfile(podfile)
spec.install_dependent_specifications!(pods_root, true) #config.clean = false
spec.install_dependent_specifications!
else else
$stderr.puts "No Podfile found in current working directory." $stderr.puts "No Podfile found in current working directory."
end end
......
...@@ -10,10 +10,19 @@ module Pod ...@@ -10,10 +10,19 @@ module Pod
@instance = instance @instance = instance
end end
attr_accessor :repos_dir attr_accessor :repos_dir, :clean
def initialize def initialize
@repos_dir = Pathname.new(File.expand_path("~/.cocoa-pods")) @repos_dir = Pathname.new(File.expand_path("~/.cocoa-pods"))
@clean = true
end
def project_root
Pathname.new(Dir.pwd)
end
def project_pods_root
project_root + 'Pods'
end end
module Mixin module Mixin
......
...@@ -4,5 +4,6 @@ require 'rubygems/dependency' ...@@ -4,5 +4,6 @@ require 'rubygems/dependency'
module Pod module Pod
class Dependency < Gem::Dependency class Dependency < Gem::Dependency
attr_accessor :part_of_other_pod
end end
end end
...@@ -22,32 +22,36 @@ module Pod ...@@ -22,32 +22,36 @@ module Pod
# * sync output # * sync output
executable :git executable :git
def source_dir
@pod_root + 'source'
end
def download def download
if tag = @options[:tag] if @options[:tag]
source_dir.mkdir download_tag
Dir.chdir(source_dir) do elsif @options[:commit]
git "init" download_commit
git "remote add origin '#{@url}'"
git "fetch origin tags/#{tag} 2>&1"
git "reset --hard FETCH_HEAD"
git "checkout -b activated-pod-commit 2>&1"
end
elsif commit = @options[:commit]
git "clone '#{@url}' '#{source_dir}'"
Dir.chdir(source_dir) do
git "checkout -b activated-pod-commit #{commit} 2>&1"
end
else else
raise "Either a tag or a commit has to be specified." raise "Either a tag or a commit has to be specified."
end end
end end
def download_tag
@pod_root.mkdir
Dir.chdir(@pod_root) do
git "init"
git "remote add origin '#{@url}'"
git "fetch origin tags/#{@options[:tag]} 2>&1"
git "reset --hard FETCH_HEAD"
git "checkout -b activated-pod-commit 2>&1"
end
end
def download_commit
git "clone '#{@url}' '#{@pod_root}'"
Dir.chdir(@pod_root) do
git "checkout -b activated-pod-commit #{@options[:commit]} 2>&1"
end
end
def clean def clean
(source_dir + '.git').rmtree (@pod_root + '.git').rmtree
end end
end end
end end
......
...@@ -7,7 +7,8 @@ module Pod ...@@ -7,7 +7,8 @@ module Pod
def resolve def resolve
@sets = [] @sets = []
find_dependency_sets(@specification) find_dependency_sets(@specification)
@sets.map(&:podspec) #@sets.reject(&:only_part_of_other_pod?).map(&:podspec)
@sets
end end
def find_dependency_sets(specification) def find_dependency_sets(specification)
......
...@@ -64,6 +64,7 @@ module Pod ...@@ -64,6 +64,7 @@ module Pod
def part_of(name, *version_requirements) def part_of(name, *version_requirements)
#@part_of = Dependency.new(name, *version_requirements) #@part_of = Dependency.new(name, *version_requirements)
@part_of = dependency(name, *version_requirements) @part_of = dependency(name, *version_requirements)
@part_of.part_of_other_pod = true
end end
def source_files(*patterns) def source_files(*patterns)
...@@ -83,42 +84,68 @@ module Pod ...@@ -83,42 +84,68 @@ module Pod
# Not attributes # Not attributes
def resolved_dependent_specifications # This also includes those that are only part of other specs, but are not
@resolved_dependent_specifications ||= Resolver.new(self).resolve # actually being used themselves.
def resolved_dependent_specification_sets
@resolved_dependent_specifications_sets ||= Resolver.new(self).resolve
end end
def install_dependent_specifications!(root, clean) def install_dependent_specifications!
resolved_dependent_specifications.each do |spec| sets = resolved_dependent_specification_sets
install_spec = spec sets.each do |set|
if part_of_spec_dep = spec.read(:part_of) # In case the set is only part of other pods we don't need to install
install_spec = resolved_dependent_specifications.find { |s| s.read(:name) == part_of_spec_dep.name } # the pod itself.
puts "-- Installing: #{install_spec} for #{spec}" next if set.only_part_of_other_pod?
else
puts "-- Installing: #{install_spec}" spec = set.podspec
spec.install!
# In case spec is part of another pod we need to dowload the other
# pod's source.
if spec.part_of_other_pod?
# Find the specification of the pod that spec's source is a part of.
part_of_name = spec.read(:part_of).name
spec = sets.find { |set| set.name == part_of_name }.podspec
end end
install_spec.install!(root, clean) spec.download_if_necessary!
end end
end end
# User can override this for custom installation include Config::Mixin
def install!(pods_root, clean)
def pod_destroot
config.project_pods_root + "#{@name}-#{@version}"
end
# Places the activated podspec in the project's pods directory.
def install!
puts "==> Installing: #{self}"
config.project_pods_root.mkpath
require 'fileutils' require 'fileutils'
pods_root.mkpath FileUtils.cp(@defined_in_file, config.project_pods_root)
pod_root = pods_root + "#{@name}-#{@version}" end
if pod_root.exist?
puts " Skipping, the pod already exists: #{pod_root}" def download_if_necessary!
if pod_destroot.exist?
puts " * Skipping download of #{self}, pod already downloaded"
else else
pod_root.mkdir puts " * Downloading: #{self}"
FileUtils.cp(@defined_in_file, pod_root) download!
download_to(pod_root, clean)
end end
end end
# User can override this for custom downloading # Downloads the source of the pod and places it in the project's pods
def download_to(pod_root, clean) # directory.
downloader = Downloader.for_source(@source, pod_root) #
# You can override this for custom downloading.
def download!
downloader = Downloader.for_source(@source, pod_destroot)
downloader.download downloader.download
downloader.clean if clean downloader.clean if config.clean
end
def part_of_other_pod?
!@part_of.nil?
end end
def from_podfile? def from_podfile?
......
...@@ -20,6 +20,10 @@ module Pod ...@@ -20,6 +20,10 @@ module Pod
@required_by.inject(Dependency.new(name)) { |previous, (_, dep)| previous.merge(dep) } @required_by.inject(Dependency.new(name)) { |previous, (_, dep)| previous.merge(dep) }
end end
def only_part_of_other_pod?
@required_by.all? { |_, dep| dep.part_of_other_pod }
end
def name def name
@pod_dir.basename.to_s @pod_dir.basename.to_s
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