Permalink
Browse files

Move installation code into Installer class.

  • Loading branch information...
1 parent c14cdd6 commit bb500057ceda14f9678e8111fbb54cc487444959 @alloy alloy committed Sep 13, 2011
View
@@ -1,7 +1,7 @@
-#dependency 'SSZipArchive', '>= 1'
+dependency 'SSZipArchive', '>= 1'
-#dependency 'ASIHTTPRequest', '1.8'
+dependency 'ASIHTTPRequest', '1.8'
#dependency 'ASIWebPageRequest', '= 1.8'
# is part of ASIHTTPRequest 1.8 and 1.8.1
View
@@ -3,6 +3,7 @@ module Pod
autoload :Config, 'cocoa_pods/config'
autoload :Dependency, 'cocoa_pods/dependency'
autoload :Downloader, 'cocoa_pods/downloader'
+ autoload :Installer, 'cocoa_pods/installer'
autoload :Resolver, 'cocoa_pods/resolver'
autoload :Source, 'cocoa_pods/source'
autoload :Spec, 'cocoa_pods/specification'
@@ -3,8 +3,7 @@ class Command
class Install < Command
def run
if spec = Specification.from_podfile(podfile)
- spec.install_dependent_specifications!
- spec.create_static_library_project!
+ Installer.new(spec, config.project_pods_root).install!
else
$stderr.puts "No Podfile found in current working directory."
end
@@ -0,0 +1,66 @@
+module Pod
+ # TODO the static library needs an extra xcconfig which sets the values from issue #1.
+ # Or we could edit the project.pbxproj file, but that seems like more work...
+ class Installer
+ def initialize(top_level_specification, pods_root)
+ @top_level_specification, @pods_root = top_level_specification, pods_root
+ end
+
+ def dependent_specification_sets
+ @dependent_specifications_sets ||= Resolver.new(@top_level_specification).resolve
+ end
+
+ def xcconfig
+ @xcconfig ||= Xcode::Config.new({
+ # in a workspace this is where the static library headers should be found
+ 'USER_HEADER_SEARCH_PATHS' => '$(BUILT_PRODUCTS_DIR)',
+ # search the user headers
+ 'ALWAYS_SEARCH_USER_PATHS' => 'YES',
+ })
+ end
+
+ def xproj
+ @xproj ||= Xcode::Project.static_library
+ end
+
+ def install!
+ install_dependent_specifications!
+ generate_project
+ write_files!
+ end
+
+ def install_dependent_specifications!
+ dependent_specification_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?
+ set.specification.install!
+ end
+ end
+
+ def generate_project
+ puts "==> Creating Pods project files"
+ dependent_specification_sets.each do |set|
+ # In case the set is only part of other pods we don't need to build
+ # the pod itself.
+ next if set.only_part_of_other_pod?
+ spec = set.specification
+ spec.read(:source_files).each do |pattern|
+ pattern = spec.pod_destroot + pattern
+ pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory?
+ Dir.glob(pattern.to_s).each do |file|
+ file = Pathname.new(file)
+ file = file.relative_path_from(@pods_root)
+ xproj.add_source_file(file)
+ end
+ end
+ xcconfig << spec.read(:xcconfig)
+ end
+ end
+
+ def write_files!
+ xproj.create_in(@pods_root)
+ xcconfig.create_in(@pods_root)
+ end
+ end
+end
@@ -20,7 +20,7 @@ def find_dependency_sets(specification)
set.required_by(specification, dependency)
unless @sets.include?(set)
@sets << set
- find_dependency_sets(set.podspec)
+ find_dependency_sets(set.specification)
end
end
end
@@ -21,6 +21,7 @@ def self.from_podspec(pathname)
def initialize(&block)
@dependencies = []
+ @xcconfig = {}
instance_eval(&block) if block_given?
end
@@ -62,7 +63,6 @@ def description(description)
end
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
@@ -93,81 +93,57 @@ def xcconfig(hash)
# Not attributes
+ include Config::Mixin
+
# Returns the specification for the pod that this pod's source is a part of.
def part_of_specification
if @part_of
- Set.by_specification_name(@part_of.name).podspec
+ Set.by_specification_name(@part_of.name).specification
end
end
- # TODO move this all to an Installer class
-
- # 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!
- 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?
- set.podspec.install!
+ def pod_destroot
+ if part_of_other_pod?
+ part_of_specification.pod_destroot
+ else
+ config.project_pods_root + "#{@name}-#{@version}"
end
end
- def create_static_library_project!
- puts "==> Creating static library project"
-
- xcconfig = Xcode::Config.new({
- # in a workspace this is where the static library headers should be found
- 'USER_HEADER_SEARCH_PATHS' => '$(BUILT_PRODUCTS_DIR)',
- # search the user headers
- 'ALWAYS_SEARCH_USER_PATHS' => 'YES',
- })
-
- project = Xcode::Project.static_library
-
- resolved_dependent_specification_sets.each do |set|
- # In case the set is only part of other pods we don't need to build
- # the pod itself.
- next if set.only_part_of_other_pod?
- spec = set.podspec
-
- spec.read(:source_files).each do |pattern|
- pattern = spec.pod_destroot + pattern
- pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory?
- Dir.glob(pattern.to_s).each do |file|
- file = Pathname.new(file)
- file = file.relative_path_from(config.project_pods_root)
- project.add_source_file(file)
- end
- end
-
- if xcconfig_hash = spec.read(:xcconfig)
- xcconfig << xcconfig_hash
- end
- end
- project.create_in(config.project_pods_root)
-
- # TODO the static library needs an extra xcconfig which sets the values from issue #1.
- # Or we could edit the project.pbxproj file, but that seems like more work...
- xcconfig.create_in(config.project_pods_root)
+ def part_of_other_pod?
+ !@part_of.nil?
end
- include Config::Mixin
+ def from_podfile?
+ @name.nil? && @version.nil?
+ end
- def pod_destroot
- if part_of_other_pod?
- part_of_specification.pod_destroot
+ def to_s
+ if from_podfile?
+ "podfile at `#{@defined_in_file}'"
else
- config.project_pods_root + "#{@name}-#{@version}"
+ "`#{@name}' version `#{@version}'"
end
end
- # Places the activated podspec in the project's pods directory.
+ def inspect
+ "#<#{self.class.name} for #{to_s}>"
+ end
+
+ # Install and download hooks
+
+ # Places the activated specification in the project's pods directory.
+ #
+ # Override this if you need to perform work before or after activating the
+ # pod. Eg:
+ #
+ # Pod::Spec.new do
+ # def install!
+ # # pre-install
+ # super
+ # # post-install
+ # end
+ # end
def install!
puts "==> Installing: #{self}"
config.project_pods_root.mkpath
@@ -191,32 +167,22 @@ def download_if_necessary!
# Downloads the source of the pod and places it in the project's pods
# directory.
#
- # You can override this for custom downloading.
+ # Override this if you need to perform work before or after downloading the
+ # pod, or if you need to implement custom dowloading. Eg:
+ #
+ # Pod::Spec.new do
+ # def download!
+ # # pre-download
+ # super # or custom downloading
+ # # post-download
+ # end
+ # end
def download!
downloader = Downloader.for_source(@source, pod_destroot)
downloader.download
downloader.clean if config.clean
end
- def part_of_other_pod?
- !@part_of.nil?
- end
-
- def from_podfile?
- @name.nil? && @version.nil?
- end
-
- def to_s
- if from_podfile?
- "podfile at `#{@defined_in_file}'"
- else
- "`#{@name}' version `#{@version}'"
- end
- end
-
- def inspect
- "#<#{self.class.name} for #{to_s}>"
- end
end
Spec = Specification
@@ -48,7 +48,7 @@ def spec_pathname
@pod_dir + required_version.to_s + "#{name}.podspec"
end
- def podspec
+ def specification
Specification.from_podspec(spec_pathname)
end
@@ -3,7 +3,7 @@
module Pod
module Xcode
class Project
- TEMPLATES_DIR = Pathname.new(File.expand_path('../../../xcode-project-templates', __FILE__))
+ TEMPLATES_DIR = Pathname.new(File.expand_path('../../../../xcode-project-templates', __FILE__))
# TODO see if we really need different templates for iOS and OS X
def self.static_library

0 comments on commit bb50005

Please sign in to comment.