Commit 985e4fce authored by Eloy Duran's avatar Eloy Duran

Make the integration spec, which creates a project with multiple targets and compiles them, pass.

parent a93f939b
module Pod module Pod
class Installer class Installer
class Target
def initialize(podfile, target, definition)
@podfile, @target, @definition = podfile, target, definition
end
def dependent_specification_sets
@dependent_specification_sets ||= Resolver.new(@podfile, @definition.dependencies).resolve
end
def build_specification_sets
dependent_specification_sets.reject(&:only_part_of_other_pod?)
end
def build_specifications
build_specification_sets.map(&:specification)
end
# TODO move xcconfig related code into the xcconfig method, like copy_resources_script and generate_bridge_support.
def install!
build_specifications.each do |spec|
# Only add implementation files to the compile phase
spec.implementation_files.each do |file|
@target.add_source_file(file, nil, spec.compiler_flags)
end
# Add header files to a `copy header build phase` for each destination
# directory in the pod's header directory.
spec.copy_header_mappings.each do |header_dir, files|
copy_phase = @target.copy_files_build_phases.new_pod_dir(spec.name, header_dir)
files.each do |file|
@target.add_source_file(file, copy_phase)
end
end
end
end
end
include Config::Mixin include Config::Mixin
def initialize(specification) def initialize(podfile)
@specification = specification @podfile = podfile
end end
def dependent_specification_sets def dependent_specification_sets
@dependent_specification_sets ||= Resolver.new(@specification).resolve @dependent_specification_sets ||= Resolver.new(@podfile).resolve
end end
def build_specification_sets def build_specification_sets
...@@ -30,83 +66,83 @@ module Pod ...@@ -30,83 +66,83 @@ module Pod
end end
def template def template
@template ||= ProjectTemplate.new(@specification.platform) @template ||= ProjectTemplate.new(@podfile.platform)
end end
def xcodeproj def xcodeproj
unless @xcodeproj @xcodeproj ||= Xcode::Project.new(template.xcodeproj_path)
@xcodeproj = Xcode::Project.new(template.xcodeproj_path) end
target = @xcodeproj.targets.new_static_library('Pods')
# TODO should create one programatically def copy_resources_script
xcconfig_file = @xcodeproj.files.find { |file| file.path == 'Pods.xcconfig' } @copy_resources_script ||= Xcode::CopyResourcesScript.new(build_specifications.map do |spec|
target.buildConfigurations.each do |config| spec.expanded_resources
config.baseConfiguration = xcconfig_file end.flatten)
end
def bridge_support_generator
BridgeSupportGenerator.new(build_specifications.map do |spec|
spec.header_files.map do |header|
config.project_pods_root + header
end end
end end.flatten)
@xcodeproj
end end
# TODO move xcconfig related code into the xcconfig method, like copy_resources_script and generate_bridge_support.
def generate_project def generate_project
puts "==> Generating Xcode project and xcconfig" unless config.silent? puts "==> Generating Xcode project and xcconfig" unless config.silent?
# First we need to resolve dependencies across *all* targets, so that the
# same correct versions of pods are being used for all targets. This
# happens when we call `build_specifications'.
user_header_search_paths = [] user_header_search_paths = []
target = xcodeproj.targets.first
build_specifications.each do |spec| build_specifications.each do |spec|
xcconfig.merge!(spec.xcconfig) xcconfig.merge!(spec.xcconfig)
# Add all source files to the project grouped by pod
group = xcodeproj.add_pod_group(spec.name) group = xcodeproj.add_pod_group(spec.name)
spec.expanded_source_files.each do |path|
# Only add implementation files to the compile phase group.children.new('path' => path.to_s)
spec.implementation_files.each do |file|
group << target.add_source_file(file, nil, spec.compiler_flags)
end
# Add header files to a `copy header build phase` for each destination
# directory in the pod's header directory.
spec.copy_header_mappings.each do |header_dir, files|
copy_phase = target.copy_files_build_phases.new_pod_dir(spec.name, header_dir)
files.each do |file|
group << target.add_source_file(file, copy_phase)
end
end end
# Collect all header search paths # Collect all header search paths
user_header_search_paths.concat(spec.user_header_search_paths) user_header_search_paths.concat(spec.user_header_search_paths)
end end
xcconfig.merge!('USER_HEADER_SEARCH_PATHS' => user_header_search_paths.sort.uniq.join(" ")) xcconfig.merge!('USER_HEADER_SEARCH_PATHS' => user_header_search_paths.sort.uniq.join(" "))
end
def copy_resources_script # Now we can generate the individual targets
@copy_resources_script ||= Xcode::CopyResourcesScript.new(build_specifications.map do |spec| @podfile.targets.values.each do |target_definition|
spec.expanded_resources target = xcodeproj.targets.new_static_library(target_definition.lib_name)
end.flatten) Target.new(@podfile, target, target_definition).install!
end end
def bridge_support_generator # TODO should create one programatically
BridgeSupportGenerator.new(build_specifications.map do |spec| xcconfig_file = xcodeproj.files.find { |file| file.path == 'Pods.xcconfig' }
spec.header_files.map do |header| xcodeproj.targets.each do |target|
config.project_pods_root + header target.buildConfigurations.each do |config|
config.baseConfiguration = xcconfig_file
end end
end.flatten) end
end end
def install! def install!
puts "Installing dependencies of: #{@specification.defined_in_file}" unless config.silent? puts "Installing dependencies of: #{@podfile.defined_in_file}" unless config.silent?
build_specifications.each(&:install!) build_specifications.each(&:install!)
generate_project
root = config.project_pods_root root = config.project_pods_root
puts " * Copying contents of template directory `#{template.path}' to `#{root}'" if config.verbose? puts " * Copying contents of template directory `#{template.path}' to `#{root}'" if config.verbose?
template.copy_to(root) template.copy_to(root)
pbxproj = File.join(root, 'Pods.xcodeproj')
puts " * Writing Xcode project file to `#{pbxproj}'" if config.verbose? # This has to happen before we generate the individual targets to make the specs pass.
xcodeproj.save_as(pbxproj) # TODO However, this will move into the Target installer class as well, because each
# target needs its own xcconfig and bridgesupport.
xcconfig.create_in(root) xcconfig.create_in(root)
if @specification.generate_bridge_support? if @podfile.generate_bridge_support?
path = bridge_support_generator.create_in(root) path = bridge_support_generator.create_in(root)
copy_resources_script.resources << path.relative_path_from(config.project_pods_root) copy_resources_script.resources << path.relative_path_from(config.project_pods_root)
end end
copy_resources_script.create_in(root) copy_resources_script.create_in(root)
generate_project
pbxproj = File.join(root, 'Pods.xcodeproj')
puts " * Writing Xcode project file to `#{pbxproj}'" if config.verbose?
xcodeproj.save_as(pbxproj)
build_specifications.each(&:post_install) build_specifications.each(&:post_install)
end end
......
...@@ -8,7 +8,7 @@ module Pod ...@@ -8,7 +8,7 @@ module Pod
end end
def lib_name def lib_name
name == :default ? "libPods" : "libPods-#{name}" name == :default ? "Pods" : "Pods-#{name}"
end end
# Returns *all* dependencies of this target, not only the target specific # Returns *all* dependencies of this target, not only the target specific
......
module Pod module Pod
class Resolver class Resolver
def initialize(specification) def initialize(specification, dependencies = nil)
@specification = specification @specification, @dependencies = specification, dependencies || specification.dependencies
end end
def resolve def resolve
@sets = [] @sets = []
find_dependency_sets(@specification) find_dependency_sets(@specification, @dependencies)
@sets @sets
end end
def find_dependency_sets(specification) def find_dependency_sets(specification, dependencies = nil)
specification.dependencies.each do |dependency| (dependencies || specification.dependencies).each do |dependency|
set = find_dependency_set(dependency) set = find_dependency_set(dependency)
set.required_by(specification) set.required_by(specification)
unless @sets.include?(set) unless @sets.include?(set)
......
...@@ -302,8 +302,9 @@ module Pod ...@@ -302,8 +302,9 @@ module Pod
buildPhases.select_by_class(PBXFrameworksBuildPhase) buildPhases.select_by_class(PBXFrameworksBuildPhase)
end end
# Finds an existing file reference or creates a new one.
def add_source_file(path, copy_header_phase = nil, compiler_flags = nil) def add_source_file(path, copy_header_phase = nil, compiler_flags = nil)
file = @project.files.new('path' => path.to_s) file = @project.files.find { |file| file.path == path.to_s } || @project.files.new('path' => path.to_s)
buildFile = file.buildFiles.new buildFile = file.buildFiles.new
if path.extname == '.h' if path.extname == '.h'
buildFile.settings = { 'ATTRIBUTES' => ["Public"] } buildFile.settings = { 'ATTRIBUTES' => ["Public"] }
...@@ -502,12 +503,6 @@ module Pod ...@@ -502,12 +503,6 @@ module Pod
FileUtils.mkdir_p(projpath) FileUtils.mkdir_p(projpath)
@plist.writeToFile(File.join(projpath, 'project.pbxproj'), atomically:true) @plist.writeToFile(File.join(projpath, 'project.pbxproj'), atomically:true)
end end
# A silly hack to pretty print the objects hash from MacRuby.
def pretty_print
puts `ruby -r pp -e 'pp(#{@template.inspect})'`
end
end end
end end
end end
...@@ -145,29 +145,31 @@ else ...@@ -145,29 +145,31 @@ else
project.source_files.should == installer.xcodeproj.source_files project.source_files.should == installer.xcodeproj.source_files
end end
#it "creates a project with multiple targets" do it "creates a project with multiple targets" do
#Pod::Source.reset! Pod::Source.reset!
#Pod::Spec::Set.reset! Pod::Spec::Set.reset!
#podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
## first ensure that the correct info is available to the specs when they load # first ensure that the correct info is available to the specs when they load
#config.rootspec = self config.rootspec = self
#self.platform platform self.platform platform
#target(:debug) { dependency 'SSZipArchive' } target(:debug) { dependency 'SSZipArchive' }
#target(:test, :exclusive => true) { dependency 'JSONKit' } target(:test, :exclusive => true) { dependency 'JSONKit' }
#dependency 'ASIHTTPRequest' dependency 'ASIHTTPRequest'
#end end
#installer = Pod::Installer.new(podfile) installer = Pod::Installer.new(podfile)
#installer.install! installer.install!
#puts "\n[!] Compiling static library..." Dir.chdir(config.project_pods_root) do
#Dir.chdir(config.project_pods_root) do puts "\n[!] Compiling static library `Pods'..."
##system("xcodebuild -target Pods").should == true system("xcodebuild -target Pods > /dev/null 2>&1").should == true
#system("xcodebuild -target Pods-debug").should == true puts "\n[!] Compiling static library `Pods-debug'..."
#system("xcodebuild -target Pods-test").should == true system("xcodebuild -target Pods-debug > /dev/null 2>&1").should == true
#end puts "\n[!] Compiling static library `Pods-test'..."
#end system("xcodebuild -target Pods-test > /dev/null 2>&1").should == true
end
end
it "sets up an existing project with pods" do it "sets up an existing project with pods" do
basename = platform == :ios ? 'iPhone' : 'Mac' basename = platform == :ios ? 'iPhone' : 'Mac'
......
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