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

Generate copy resources scripts for each target.

parent 644e4190
module Pod
class Installer
class Target
attr_reader :target
def initialize(podfile, xcodeproj, definition)
@podfile, @xcodeproj, @definition = podfile, xcodeproj, definition
end
module Shared
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
def build_specification_sets
......@@ -18,6 +12,16 @@ module Pod
def build_specifications
build_specification_sets.map(&:specification)
end
end
class Target
include Shared
attr_reader :target
def initialize(podfile, xcodeproj, definition)
@podfile, @xcodeproj, @definition = podfile, xcodeproj, definition
end
def xcconfig
@xcconfig ||= Xcode::Config.new({
......@@ -34,6 +38,16 @@ module Pod
"#{@definition.lib_name}.xcconfig"
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.
def install!
# First add the target to the project
......@@ -64,45 +78,40 @@ module Pod
@target.buildConfigurations.each do |config|
config.baseConfiguration = xcconfig_file
end
self
end
def create_files_in(root)
xcconfig.save_as(root + xcconfig_filename)
copy_resources_script.save_as(root + copy_resources_filename)
end
end
include Config::Mixin
include Shared
def initialize(podfile)
@podfile = podfile
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
@template ||= ProjectTemplate.new(@podfile.platform)
end
def xcodeproj
@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)
unless @xcodeproj
@xcodeproj = Xcode::Project.new(template.xcodeproj_path)
# 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'.
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
end
@xcodeproj
end
def bridge_support_generator
......@@ -113,22 +122,9 @@ module Pod
end.flatten)
end
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'.
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!
def targets
@targets ||= @podfile.targets.values.map do |target_definition|
Target.new(@podfile, xcodeproj, target_definition)
end
end
......@@ -143,14 +139,14 @@ module Pod
# 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.
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)
#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
targets = generate_project
puts "==> Generating Xcode project and xcconfig" unless config.silent?
targets.each do |target|
target.install!
target.create_files_in(root)
end
pbxproj = File.join(root, 'Pods.xcodeproj')
......
module Pod
module Xcode
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
# A list of files relative to the project pods root.
......@@ -8,13 +18,15 @@ module Pod
@resources = resources
end
def create_in(root)
return if @resources.empty?
(root + 'PodsResources.sh').open('a') do |script|
def save_as(pathname)
pathname.open('w') do |script|
script.puts CONTENT
@resources.each do |resource|
script.puts "install_resource '#{resource}'"
end
end
# TODO use File api
system("chmod +x '#{pathname}'")
end
end
end
......
......@@ -68,7 +68,7 @@ else
(root + 'JSONKit.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
NSDictionary.dictionaryWithContentsOfFile(project_file).should == installer.xcodeproj.to_hash
......@@ -106,11 +106,10 @@ else
end
installer = SpecHelper::Installer.new(spec)
dependency_spec = installer.build_specifications.first
dependency_spec.resources = 'LICEN*', 'Readme.*'
installer.targets.first.build_specifications.first.resources = 'LICEN*', 'Readme.*'
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" \
"install_resource 'SSZipArchive/Readme.markdown'"
end
......@@ -139,8 +138,6 @@ else
installer = SpecHelper::Installer.new(spec)
installer.install!
installer = Pod::Installer.new(spec)
installer.generate_project
project = Pod::Xcode::Project.new(config.project_pods_root + 'Pods.xcodeproj')
project.source_files.should == installer.xcodeproj.source_files
end
......@@ -160,12 +157,20 @@ else
installer = Pod::Installer.new(podfile)
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 + 'Pods.xcconfig').should.exist
(root + 'Pods-debug.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
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