Permalink
Browse files

Make sure that a pod's spec is not installed if it's only part of oth…

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

0 comments on commit e65536b

Please sign in to comment.