Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fetch a pod's source with git.

  • Loading branch information...
commit 99819b9f1b26526423da18753055f5e8855cbca1 1 parent 30d8b91
@alloy alloy authored
View
1  lib/cocoa_pods.rb
@@ -2,6 +2,7 @@ module Pod
autoload :Command, 'cocoa_pods/command'
autoload :Config, 'cocoa_pods/config'
autoload :Dependency, 'cocoa_pods/dependency'
+ autoload :Downloader, 'cocoa_pods/downloader'
autoload :Resolver, 'cocoa_pods/resolver'
autoload :Source, 'cocoa_pods/source'
autoload :Spec, 'cocoa_pods/specification'
View
7 lib/cocoa_pods/command/install.rb
@@ -3,13 +3,16 @@ class Command
class Install < Command
def run
if spec = Specification.from_podfile(podfile)
- p spec
- Resolver.new(spec).resolve
+ spec.install_dependent_specifications!(pods_root)
else
$stderr.puts "No Podfile found in current working directory."
end
end
+ def pods_root
+ Pathname.new(Dir.pwd) + 'Pods'
+ end
+
def podfile
File.join(Dir.pwd, 'Podfile')
end
View
47 lib/cocoa_pods/downloader.rb
@@ -0,0 +1,47 @@
+module Pod
+ class Downloader
+ def self.for_source(source)
+ options = source.dup
+ if url = options.delete(:git)
+ Git.new(url, options)
+ else
+ raise "Unsupported download strategy `#{source.inspect}'."
+ end
+ end
+
+ def initialize(url, options)
+ @url, @options = url, options
+ end
+
+ class Git < Downloader
+ require 'rubygems'
+ require 'executioner'
+ include Executioner
+ # TODO make Executioner:
+ # * not raise when there's output to either stdout/stderr, but check exit status
+ # * sync output
+ executable :git
+
+ def download_to(pod_root)
+ checkout = pod_root + 'source'
+ if tag = @options[:tag]
+ checkout.mkdir
+ Dir.chdir(checkout) 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}' '#{checkout}'"
+ Dir.chdir(checkout) do
+ git "checkout -b activated-pod-commit #{commit} 2>&1"
+ end
+ else
+ raise "Either a tag or a commit has to be specified."
+ end
+ end
+ end
+ end
+end
View
3  lib/cocoa_pods/resolver.rb
@@ -7,8 +7,7 @@ def initialize(specification)
def resolve
@sets = []
find_dependency_sets(@specification)
- specs = @sets.map(&:podspec)
- p specs
+ @sets.map(&:podspec)
end
def find_dependency_sets(specification)
View
42 lib/cocoa_pods/specification.rb
@@ -63,7 +63,7 @@ def description(description)
def part_of(name, *version_requirements)
#@part_of = Dependency.new(name, *version_requirements)
- dependency(name, *version_requirements)
+ @part_of = dependency(name, *version_requirements)
end
def source_files(*patterns)
@@ -76,11 +76,49 @@ def source(remote)
attr_reader :dependencies
def dependency(name, *version_requirements)
- @dependencies << Dependency.new(name, *version_requirements)
+ dep = Dependency.new(name, *version_requirements)
+ @dependencies << dep
+ dep
end
# Not attributes
+ def resolved_dependent_specifications
+ @resolved_dependent_specifications ||= Resolver.new(self).resolve
+ end
+
+ def install_dependent_specifications!(root)
+ 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}"
+ end
+ install_spec.install!(root)
+ end
+ end
+
+ # User can override this for custom installation
+ def install!(pods_root)
+ require 'fileutils'
+ pods_root.mkpath
+ pod_root = pods_root + "#{@name}-#{@version}"
+ if pod_root.exist?
+ puts " Skipping, the pod already exists: #{pod_root}"
+ else
+ pod_root.mkdir
+ FileUtils.cp(@defined_in_file, pod_root)
+ download_to(pod_root)
+ end
+ end
+
+ # User can override this for custom downloading
+ def download_to(pod_root)
+ Downloader.for_source(@source).download_to(pod_root)
+ end
+
def from_podfile?
@name.nil? && @version.nil?
end
Please sign in to comment.
Something went wrong with that request. Please try again.