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
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
def initialize(specification)
@specification = specification
def initialize(podfile)
@podfile = podfile
end
def dependent_specification_sets
@dependent_specification_sets ||= Resolver.new(@specification).resolve
@dependent_specification_sets ||= Resolver.new(@podfile).resolve
end
def build_specification_sets
......@@ -30,83 +66,83 @@ module Pod
end
def template
@template ||= ProjectTemplate.new(@specification.platform)
@template ||= ProjectTemplate.new(@podfile.platform)
end
def xcodeproj
unless @xcodeproj
@xcodeproj = Xcode::Project.new(template.xcodeproj_path)
target = @xcodeproj.targets.new_static_library('Pods')
# TODO should create one programatically
xcconfig_file = @xcodeproj.files.find { |file| file.path == 'Pods.xcconfig' }
target.buildConfigurations.each do |config|
config.baseConfiguration = xcconfig_file
@xcodeproj ||= Xcode::Project.new(template.xcodeproj_path)
end
def copy_resources_script
@copy_resources_script ||= Xcode::CopyResourcesScript.new(build_specifications.map do |spec|
spec.expanded_resources
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
@xcodeproj
end.flatten)
end
# TODO move xcconfig related code into the xcconfig method, like copy_resources_script and generate_bridge_support.
def generate_project
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 = []
target = xcodeproj.targets.first
build_specifications.each do |spec|
xcconfig.merge!(spec.xcconfig)
# Add all source files to the project grouped by pod
group = xcodeproj.add_pod_group(spec.name)
# Only add implementation files to the compile phase
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
spec.expanded_source_files.each do |path|
group.children.new('path' => path.to_s)
end
# Collect all header search paths
user_header_search_paths.concat(spec.user_header_search_paths)
end
xcconfig.merge!('USER_HEADER_SEARCH_PATHS' => user_header_search_paths.sort.uniq.join(" "))
end
def copy_resources_script
@copy_resources_script ||= Xcode::CopyResourcesScript.new(build_specifications.map do |spec|
spec.expanded_resources
end.flatten)
end
# Now we can generate the individual targets
@podfile.targets.values.each do |target_definition|
target = xcodeproj.targets.new_static_library(target_definition.lib_name)
Target.new(@podfile, target, target_definition).install!
end
def bridge_support_generator
BridgeSupportGenerator.new(build_specifications.map do |spec|
spec.header_files.map do |header|
config.project_pods_root + header
# TODO should create one programatically
xcconfig_file = xcodeproj.files.find { |file| file.path == 'Pods.xcconfig' }
xcodeproj.targets.each do |target|
target.buildConfigurations.each do |config|
config.baseConfiguration = xcconfig_file
end
end.flatten)
end
end
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!)
generate_project
root = config.project_pods_root
puts " * Copying contents of template directory `#{template.path}' to `#{root}'" if config.verbose?
template.copy_to(root)
pbxproj = File.join(root, 'Pods.xcodeproj')
puts " * Writing Xcode project file to `#{pbxproj}'" if config.verbose?
xcodeproj.save_as(pbxproj)
# This has to happen before we generate the individual targets to make the specs pass.
# 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)
if @specification.generate_bridge_support?
if @podfile.generate_bridge_support?
path = bridge_support_generator.create_in(root)
copy_resources_script.resources << path.relative_path_from(config.project_pods_root)
end
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)
end
......
......@@ -8,7 +8,7 @@ module Pod
end
def lib_name
name == :default ? "libPods" : "libPods-#{name}"
name == :default ? "Pods" : "Pods-#{name}"
end
# Returns *all* dependencies of this target, not only the target specific
......
module Pod
class Resolver
def initialize(specification)
@specification = specification
def initialize(specification, dependencies = nil)
@specification, @dependencies = specification, dependencies || specification.dependencies
end
def resolve
@sets = []
find_dependency_sets(@specification)
find_dependency_sets(@specification, @dependencies)
@sets
end
def find_dependency_sets(specification)
specification.dependencies.each do |dependency|
def find_dependency_sets(specification, dependencies = nil)
(dependencies || specification.dependencies).each do |dependency|
set = find_dependency_set(dependency)
set.required_by(specification)
unless @sets.include?(set)
......
......@@ -302,8 +302,9 @@ module Pod
buildPhases.select_by_class(PBXFrameworksBuildPhase)
end
# Finds an existing file reference or creates a new one.
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
if path.extname == '.h'
buildFile.settings = { 'ATTRIBUTES' => ["Public"] }
......@@ -502,12 +503,6 @@ module Pod
FileUtils.mkdir_p(projpath)
@plist.writeToFile(File.join(projpath, 'project.pbxproj'), atomically:true)
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
......@@ -145,29 +145,31 @@ else
project.source_files.should == installer.xcodeproj.source_files
end
#it "creates a project with multiple targets" do
#Pod::Source.reset!
#Pod::Spec::Set.reset!
#podfile = Pod::Podfile.new do
## first ensure that the correct info is available to the specs when they load
#config.rootspec = self
#self.platform platform
#target(:debug) { dependency 'SSZipArchive' }
#target(:test, :exclusive => true) { dependency 'JSONKit' }
#dependency 'ASIHTTPRequest'
#end
#installer = Pod::Installer.new(podfile)
#installer.install!
#puts "\n[!] Compiling static library..."
#Dir.chdir(config.project_pods_root) do
##system("xcodebuild -target Pods").should == true
#system("xcodebuild -target Pods-debug").should == true
#system("xcodebuild -target Pods-test").should == true
#end
#end
it "creates a project with multiple targets" do
Pod::Source.reset!
Pod::Spec::Set.reset!
podfile = Pod::Podfile.new do
# first ensure that the correct info is available to the specs when they load
config.rootspec = self
self.platform platform
target(:debug) { dependency 'SSZipArchive' }
target(:test, :exclusive => true) { dependency 'JSONKit' }
dependency 'ASIHTTPRequest'
end
installer = Pod::Installer.new(podfile)
installer.install!
Dir.chdir(config.project_pods_root) do
puts "\n[!] Compiling static library `Pods'..."
system("xcodebuild -target Pods > /dev/null 2>&1").should == true
puts "\n[!] Compiling static library `Pods-debug'..."
system("xcodebuild -target Pods-debug > /dev/null 2>&1").should == true
puts "\n[!] Compiling static library `Pods-test'..."
system("xcodebuild -target Pods-test > /dev/null 2>&1").should == true
end
end
it "sets up an existing project with pods" do
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