Commit bb500057 authored by Eloy Duran's avatar Eloy Duran

Move installation code into Installer class.

parent c14cdd66
#dependency 'SSZipArchive', '>= 1' dependency 'SSZipArchive', '>= 1'
#dependency 'ASIHTTPRequest', '1.8' dependency 'ASIHTTPRequest', '1.8'
#dependency 'ASIWebPageRequest', '= 1.8' #dependency 'ASIWebPageRequest', '= 1.8'
# is part of ASIHTTPRequest 1.8 and 1.8.1 # is part of ASIHTTPRequest 1.8 and 1.8.1
......
...@@ -3,6 +3,7 @@ module Pod ...@@ -3,6 +3,7 @@ module Pod
autoload :Config, 'cocoa_pods/config' autoload :Config, 'cocoa_pods/config'
autoload :Dependency, 'cocoa_pods/dependency' autoload :Dependency, 'cocoa_pods/dependency'
autoload :Downloader, 'cocoa_pods/downloader' autoload :Downloader, 'cocoa_pods/downloader'
autoload :Installer, 'cocoa_pods/installer'
autoload :Resolver, 'cocoa_pods/resolver' autoload :Resolver, 'cocoa_pods/resolver'
autoload :Source, 'cocoa_pods/source' autoload :Source, 'cocoa_pods/source'
autoload :Spec, 'cocoa_pods/specification' autoload :Spec, 'cocoa_pods/specification'
......
...@@ -3,8 +3,7 @@ module Pod ...@@ -3,8 +3,7 @@ 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! Installer.new(spec, config.project_pods_root).install!
spec.create_static_library_project!
else else
$stderr.puts "No Podfile found in current working directory." $stderr.puts "No Podfile found in current working directory."
end end
......
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 @@ module Pod ...@@ -20,7 +20,7 @@ module Pod
set.required_by(specification, dependency) set.required_by(specification, dependency)
unless @sets.include?(set) unless @sets.include?(set)
@sets << set @sets << set
find_dependency_sets(set.podspec) find_dependency_sets(set.specification)
end end
end end
end end
......
...@@ -21,6 +21,7 @@ module Pod ...@@ -21,6 +21,7 @@ module Pod
def initialize(&block) def initialize(&block)
@dependencies = [] @dependencies = []
@xcconfig = {}
instance_eval(&block) if block_given? instance_eval(&block) if block_given?
end end
...@@ -62,7 +63,6 @@ module Pod ...@@ -62,7 +63,6 @@ module Pod
end end
def part_of(name, *version_requirements) def part_of(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 @part_of.part_of_other_pod = true
end end
...@@ -93,81 +93,57 @@ module Pod ...@@ -93,81 +93,57 @@ module Pod
# Not attributes # Not attributes
include Config::Mixin
# Returns the specification for the pod that this pod's source is a part of. # Returns the specification for the pod that this pod's source is a part of.
def part_of_specification def part_of_specification
if @part_of if @part_of
Set.by_specification_name(@part_of.name).podspec Set.by_specification_name(@part_of.name).specification
end end
end end
# TODO move this all to an Installer class def pod_destroot
if part_of_other_pod?
# This also includes those that are only part of other specs, but are not part_of_specification.pod_destroot
# actually being used themselves. else
def resolved_dependent_specification_sets config.project_pods_root + "#{@name}-#{@version}"
@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!
end end
end end
def create_static_library_project! def part_of_other_pod?
puts "==> Creating static library project" !@part_of.nil?
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)
end end
include Config::Mixin def from_podfile?
@name.nil? && @version.nil?
end
def pod_destroot def to_s
if part_of_other_pod? if from_podfile?
part_of_specification.pod_destroot "podfile at `#{@defined_in_file}'"
else else
config.project_pods_root + "#{@name}-#{@version}" "`#{@name}' version `#{@version}'"
end end
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! def install!
puts "==> Installing: #{self}" puts "==> Installing: #{self}"
config.project_pods_root.mkpath config.project_pods_root.mkpath
...@@ -191,32 +167,22 @@ module Pod ...@@ -191,32 +167,22 @@ module Pod
# Downloads the source of the pod and places it in the project's pods # Downloads the source of the pod and places it in the project's pods
# directory. # 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! def download!
downloader = Downloader.for_source(@source, pod_destroot) downloader = Downloader.for_source(@source, pod_destroot)
downloader.download downloader.download
downloader.clean if config.clean downloader.clean if config.clean
end 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 end
Spec = Specification Spec = Specification
......
...@@ -48,7 +48,7 @@ module Pod ...@@ -48,7 +48,7 @@ module Pod
@pod_dir + required_version.to_s + "#{name}.podspec" @pod_dir + required_version.to_s + "#{name}.podspec"
end end
def podspec def specification
Specification.from_podspec(spec_pathname) Specification.from_podspec(spec_pathname)
end end
......
...@@ -3,7 +3,7 @@ framework 'Foundation' ...@@ -3,7 +3,7 @@ framework 'Foundation'
module Pod module Pod
module Xcode module Xcode
class Project 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 # TODO see if we really need different templates for iOS and OS X
def self.static_library def self.static_library
......
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