Commit 644e4190 authored by Eloy Duran's avatar Eloy Duran

Generate separate xcconfig files for each target.

parent 985e4fce
module Pod module Pod
class Installer class Installer
class Target class Target
def initialize(podfile, target, definition) attr_reader :target
@podfile, @target, @definition = podfile, target, definition
def initialize(podfile, xcodeproj, definition)
@podfile, @xcodeproj, @definition = podfile, xcodeproj, definition
end end
def dependent_specification_sets def dependent_specification_sets
...@@ -17,9 +19,29 @@ module Pod ...@@ -17,9 +19,29 @@ module Pod
build_specification_sets.map(&:specification) build_specification_sets.map(&:specification)
end 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)/Pods"',
'ALWAYS_SEARCH_USER_PATHS' => 'YES',
# This makes categories from static libraries work, which many libraries
# require, so we add these by default.
'OTHER_LDFLAGS' => '-ObjC -all_load',
})
end
def xcconfig_filename
"#{@definition.lib_name}.xcconfig"
end
# TODO move xcconfig related code into the xcconfig method, like copy_resources_script and generate_bridge_support. # TODO move xcconfig related code into the xcconfig method, like copy_resources_script and generate_bridge_support.
def install! def install!
# First add the target to the project
@target = @xcodeproj.targets.new_static_library(@definition.lib_name)
user_header_search_paths = []
build_specifications.each do |spec| build_specifications.each do |spec|
xcconfig.merge!(spec.xcconfig)
# Only add implementation files to the compile phase # Only add implementation files to the compile phase
spec.implementation_files.each do |file| spec.implementation_files.each do |file|
@target.add_source_file(file, nil, spec.compiler_flags) @target.add_source_file(file, nil, spec.compiler_flags)
...@@ -32,7 +54,22 @@ module Pod ...@@ -32,7 +54,22 @@ module Pod
@target.add_source_file(file, copy_phase) @target.add_source_file(file, copy_phase)
end end
end end
# Collect all 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(" "))
# Add the xcconfig file to the project and make it the base of the target's configurations.
xcconfig_file = @xcodeproj.files.new("path" => xcconfig_filename)
@target.buildConfigurations.each do |config|
config.baseConfiguration = xcconfig_file
end
self
end
def create_files_in(root)
xcconfig.save_as(root + xcconfig_filename)
end end
end end
...@@ -54,17 +91,6 @@ module Pod ...@@ -54,17 +91,6 @@ module Pod
build_specification_sets.map(&:specification) build_specification_sets.map(&:specification)
end 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)/Pods"',
'ALWAYS_SEARCH_USER_PATHS' => 'YES',
# This makes categories from static libraries work, which many libraries
# require, so we add these by default.
'OTHER_LDFLAGS' => '-ObjC -all_load',
})
end
def template def template
@template ||= ProjectTemplate.new(@podfile.platform) @template ||= ProjectTemplate.new(@podfile.platform)
end end
...@@ -92,31 +118,17 @@ module Pod ...@@ -92,31 +118,17 @@ module Pod
# First we need to resolve dependencies across *all* targets, so that the # First we need to resolve dependencies across *all* targets, so that the
# same correct versions of pods are being used for all targets. This # same correct versions of pods are being used for all targets. This
# happens when we call `build_specifications'. # happens when we call `build_specifications'.
user_header_search_paths = []
build_specifications.each do |spec| build_specifications.each do |spec|
xcconfig.merge!(spec.xcconfig)
# Add all source files to the project grouped by pod # 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| spec.expanded_source_files.each do |path|
group.children.new('path' => path.to_s) group.children.new('path' => path.to_s)
end end
# Collect all 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(" "))
# Now we can generate the individual targets # Now we can generate the individual targets
@podfile.targets.values.each do |target_definition| @podfile.targets.values.map do |target_definition|
target = xcodeproj.targets.new_static_library(target_definition.lib_name) Target.new(@podfile, xcodeproj, target_definition).install!
Target.new(@podfile, target, target_definition).install!
end
# 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 end
end end
...@@ -131,14 +143,16 @@ module Pod ...@@ -131,14 +143,16 @@ module Pod
# This has to happen before we generate the individual targets to make the specs pass. # 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 # TODO However, this will move into the Target installer class as well, because each
# target needs its own xcconfig and bridgesupport. # target needs its own xcconfig and bridgesupport.
xcconfig.create_in(root)
if @podfile.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 targets = generate_project
targets.each do |target|
target.create_files_in(root)
end
pbxproj = File.join(root, 'Pods.xcodeproj') pbxproj = File.join(root, 'Pods.xcodeproj')
puts " * Writing Xcode project file to `#{pbxproj}'" if config.verbose? puts " * Writing Xcode project file to `#{pbxproj}'" if config.verbose?
xcodeproj.save_as(pbxproj) xcodeproj.save_as(pbxproj)
......
...@@ -25,8 +25,8 @@ module Pod ...@@ -25,8 +25,8 @@ module Pod
@attributes.map { |key, value| "#{key} = #{value}" }.join("\n") @attributes.map { |key, value| "#{key} = #{value}" }.join("\n")
end end
def create_in(pods_root) def save_as(pathname)
(pods_root + 'Pods.xcconfig').open('w') { |file| file << to_s } pathname.open('w') { |file| file << to_s }
end end
end end
end end
......
...@@ -68,7 +68,7 @@ else ...@@ -68,7 +68,7 @@ else
(root + 'JSONKit.podspec').should.exist (root + 'JSONKit.podspec').should.exist
(root + 'SSZipArchive.podspec').should.exist (root + 'SSZipArchive.podspec').should.exist
(root + 'Pods.xcconfig').read.should == installer.xcconfig.to_s #(root + 'Pods.xcconfig').read.should == installer.xcconfig.to_s
project_file = (root + 'Pods.xcodeproj/project.pbxproj').to_s project_file = (root + 'Pods.xcodeproj/project.pbxproj').to_s
NSDictionary.dictionaryWithContentsOfFile(project_file).should == installer.xcodeproj.to_hash NSDictionary.dictionaryWithContentsOfFile(project_file).should == installer.xcodeproj.to_hash
...@@ -160,6 +160,12 @@ else ...@@ -160,6 +160,12 @@ else
installer = Pod::Installer.new(podfile) installer = Pod::Installer.new(podfile)
installer.install! installer.install!
#exit
root = config.project_pods_root
(root + 'Pods.xcconfig').should.exist
(root + 'Pods-debug.xcconfig').should.exist
(root + 'Pods-test.xcconfig').should.exist
Dir.chdir(config.project_pods_root) do Dir.chdir(config.project_pods_root) do
puts "\n[!] Compiling static library `Pods'..." puts "\n[!] Compiling static library `Pods'..."
......
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