Commit 10befd83 authored by Eloy Duran's avatar Eloy Duran

Generate copy resources scripts for each target.

parent 644e4190
module Pod module Pod
class Installer class Installer
class Target module Shared
attr_reader :target
def initialize(podfile, xcodeproj, definition)
@podfile, @xcodeproj, @definition = podfile, xcodeproj, definition
end
def dependent_specification_sets def dependent_specification_sets
@dependent_specification_sets ||= Resolver.new(@podfile, @definition.dependencies).resolve @dependent_specification_sets ||= Resolver.new(@podfile, @definition ? @definition.dependencies : nil).resolve
end end
def build_specification_sets def build_specification_sets
...@@ -18,6 +12,16 @@ module Pod ...@@ -18,6 +12,16 @@ module Pod
def build_specifications def build_specifications
build_specification_sets.map(&:specification) build_specification_sets.map(&:specification)
end end
end
class Target
include Shared
attr_reader :target
def initialize(podfile, xcodeproj, definition)
@podfile, @xcodeproj, @definition = podfile, xcodeproj, definition
end
def xcconfig def xcconfig
@xcconfig ||= Xcode::Config.new({ @xcconfig ||= Xcode::Config.new({
...@@ -34,6 +38,16 @@ module Pod ...@@ -34,6 +38,16 @@ module Pod
"#{@definition.lib_name}.xcconfig" "#{@definition.lib_name}.xcconfig"
end end
def copy_resources_script
@copy_resources_script ||= Xcode::CopyResourcesScript.new(build_specifications.map do |spec|
spec.expanded_resources
end.flatten)
end
def copy_resources_filename
"#{@definition.lib_name}-resources.sh"
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 # First add the target to the project
...@@ -64,45 +78,40 @@ module Pod ...@@ -64,45 +78,40 @@ module Pod
@target.buildConfigurations.each do |config| @target.buildConfigurations.each do |config|
config.baseConfiguration = xcconfig_file config.baseConfiguration = xcconfig_file
end end
self
end end
def create_files_in(root) def create_files_in(root)
xcconfig.save_as(root + xcconfig_filename) xcconfig.save_as(root + xcconfig_filename)
copy_resources_script.save_as(root + copy_resources_filename)
end end
end end
include Config::Mixin include Config::Mixin
include Shared
def initialize(podfile) def initialize(podfile)
@podfile = podfile @podfile = podfile
end end
def dependent_specification_sets
@dependent_specification_sets ||= Resolver.new(@podfile).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
def template def template
@template ||= ProjectTemplate.new(@podfile.platform) @template ||= ProjectTemplate.new(@podfile.platform)
end end
def xcodeproj def xcodeproj
@xcodeproj ||= Xcode::Project.new(template.xcodeproj_path) unless @xcodeproj
end @xcodeproj = Xcode::Project.new(template.xcodeproj_path)
# First we need to resolve dependencies across *all* targets, so that the
def copy_resources_script # same correct versions of pods are being used for all targets. This
@copy_resources_script ||= Xcode::CopyResourcesScript.new(build_specifications.map do |spec| # happens when we call `build_specifications'.
spec.expanded_resources build_specifications.each do |spec|
end.flatten) # Add all source files to the project grouped by pod
group = xcodeproj.add_pod_group(spec.name)
spec.expanded_source_files.each do |path|
group.children.new('path' => path.to_s)
end
end
end
@xcodeproj
end end
def bridge_support_generator def bridge_support_generator
...@@ -113,22 +122,9 @@ module Pod ...@@ -113,22 +122,9 @@ module Pod
end.flatten) end.flatten)
end end
def generate_project def targets
puts "==> Generating Xcode project and xcconfig" unless config.silent? @targets ||= @podfile.targets.values.map do |target_definition|
# First we need to resolve dependencies across *all* targets, so that the Target.new(@podfile, xcodeproj, target_definition)
# same correct versions of pods are being used for all targets. This
# happens when we call `build_specifications'.
build_specifications.each do |spec|
# Add all source files to the project grouped by pod
group = xcodeproj.add_pod_group(spec.name)
spec.expanded_source_files.each do |path|
group.children.new('path' => path.to_s)
end
end
# Now we can generate the individual targets
@podfile.targets.values.map do |target_definition|
Target.new(@podfile, xcodeproj, target_definition).install!
end end
end end
...@@ -143,14 +139,14 @@ module Pod ...@@ -143,14 +139,14 @@ 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.
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)
targets = generate_project puts "==> Generating Xcode project and xcconfig" unless config.silent?
targets.each do |target| targets.each do |target|
target.install!
target.create_files_in(root) target.create_files_in(root)
end end
pbxproj = File.join(root, 'Pods.xcodeproj') pbxproj = File.join(root, 'Pods.xcodeproj')
......
module Pod module Pod
module Xcode module Xcode
class CopyResourcesScript class CopyResourcesScript
CONTENT = <<EOS
#!/bin/sh
install_resource()
{
echo "cp -R ${SRCROOT}/Pods/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
cp -R ${SRCROOT}/Pods/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}
}
EOS
attr_reader :resources attr_reader :resources
# A list of files relative to the project pods root. # A list of files relative to the project pods root.
...@@ -8,13 +18,15 @@ module Pod ...@@ -8,13 +18,15 @@ module Pod
@resources = resources @resources = resources
end end
def create_in(root) def save_as(pathname)
return if @resources.empty? pathname.open('w') do |script|
(root + 'PodsResources.sh').open('a') do |script| script.puts CONTENT
@resources.each do |resource| @resources.each do |resource|
script.puts "install_resource '#{resource}'" script.puts "install_resource '#{resource}'"
end end
end end
# TODO use File api
system("chmod +x '#{pathname}'")
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.targets.first.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
...@@ -106,11 +106,10 @@ else ...@@ -106,11 +106,10 @@ else
end end
installer = SpecHelper::Installer.new(spec) installer = SpecHelper::Installer.new(spec)
dependency_spec = installer.build_specifications.first installer.targets.first.build_specifications.first.resources = 'LICEN*', 'Readme.*'
dependency_spec.resources = 'LICEN*', 'Readme.*'
installer.install! installer.install!
contents = (config.project_pods_root + 'PodsResources.sh').read contents = (config.project_pods_root + 'Pods-resources.sh').read
contents.should.include "install_resource 'SSZipArchive/LICENSE'\n" \ contents.should.include "install_resource 'SSZipArchive/LICENSE'\n" \
"install_resource 'SSZipArchive/Readme.markdown'" "install_resource 'SSZipArchive/Readme.markdown'"
end end
...@@ -139,8 +138,6 @@ else ...@@ -139,8 +138,6 @@ else
installer = SpecHelper::Installer.new(spec) installer = SpecHelper::Installer.new(spec)
installer.install! installer.install!
installer = Pod::Installer.new(spec)
installer.generate_project
project = Pod::Xcode::Project.new(config.project_pods_root + 'Pods.xcodeproj') project = Pod::Xcode::Project.new(config.project_pods_root + 'Pods.xcodeproj')
project.source_files.should == installer.xcodeproj.source_files project.source_files.should == installer.xcodeproj.source_files
end end
...@@ -160,12 +157,20 @@ else ...@@ -160,12 +157,20 @@ else
installer = Pod::Installer.new(podfile) installer = Pod::Installer.new(podfile)
installer.install! installer.install!
#exit
#project = Pod::Xcode::Project.new(config.project_pods_root + 'Pods.xcodeproj')
#p project
#project.targets.each do |target|
#target.source_build_phases.
#end
root = config.project_pods_root root = config.project_pods_root
(root + 'Pods.xcconfig').should.exist (root + 'Pods.xcconfig').should.exist
(root + 'Pods-debug.xcconfig').should.exist (root + 'Pods-debug.xcconfig').should.exist
(root + 'Pods-test.xcconfig').should.exist (root + 'Pods-test.xcconfig').should.exist
(root + 'Pods-resources.sh').should.exist
(root + 'Pods-debug-resources.sh').should.exist
(root + 'Pods-test-resources.sh').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'..."
......
#!/bin/sh
install_resource()
{
echo "cp -R ${SRCROOT}/Pods/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
cp -R ${SRCROOT}/Pods/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}
}
#!/bin/sh
install_resource()
{
echo "cp -R ${SRCROOT}/Pods/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
cp -R ${SRCROOT}/Pods/$1 ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}
}
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