Commit 19029672 authored by Eloy Duran's avatar Eloy Duran

Add an Xcode post build script which copies pod resources into the app bundle.

parent ee704471
...@@ -257,6 +257,7 @@ ...@@ -257,6 +257,7 @@
1D60588D0D05DD3D006BFB54 /* Resources */, 1D60588D0D05DD3D006BFB54 /* Resources */,
1D60588E0D05DD3D006BFB54 /* Sources */, 1D60588E0D05DD3D006BFB54 /* Sources */,
1D60588F0D05DD3D006BFB54 /* Frameworks */, 1D60588F0D05DD3D006BFB54 /* Frameworks */,
513D6140144F6D3600A8A360 /* ShellScript */,
); );
buildRules = ( buildRules = (
); );
...@@ -317,6 +318,23 @@ ...@@ -317,6 +318,23 @@
}; };
/* End PBXResourcesBuildPhase section */ /* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
513D6140144F6D3600A8A360 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "${SRCROOT}/Pods/PodsResources.sh";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */
1D60588E0D05DD3D006BFB54 /* Sources */ = { 1D60588E0D05DD3D006BFB54 /* Sources */ = {
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
......
...@@ -19,6 +19,7 @@ module Pod ...@@ -19,6 +19,7 @@ module Pod
module Xcode module Xcode
autoload :Config, 'cocoapods/xcode/config' autoload :Config, 'cocoapods/xcode/config'
autoload :CopyResourcesScript, 'cocoapods/xcode/copy_resources_script'
autoload :Project, 'cocoapods/xcode/project' autoload :Project, 'cocoapods/xcode/project'
end end
......
...@@ -32,6 +32,7 @@ module Pod ...@@ -32,6 +32,7 @@ module Pod
@xcodeproj ||= Xcode::Project.static_library(@specification.platform) @xcodeproj ||= Xcode::Project.static_library(@specification.platform)
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?
user_header_search_paths = [] user_header_search_paths = []
...@@ -59,6 +60,10 @@ module Pod ...@@ -59,6 +60,10 @@ module Pod
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 end
def copy_resources_script
Xcode::CopyResourcesScript.new(build_specifications.map { |spec| spec.expanded_resources }.flatten)
end
def bridge_support_generator def bridge_support_generator
BridgeSupportGenerator.new(build_specifications.map do |spec| BridgeSupportGenerator.new(build_specifications.map do |spec|
spec.header_files.map do |header| spec.header_files.map do |header|
...@@ -71,10 +76,13 @@ module Pod ...@@ -71,10 +76,13 @@ module Pod
puts "Installing dependencies of: #{@specification.defined_in_file}" unless config.silent? puts "Installing dependencies of: #{@specification.defined_in_file}" unless config.silent?
build_specifications.each(&:install!) build_specifications.each(&:install!)
generate_project generate_project
root = config.project_pods_root root = config.project_pods_root
xcodeproj.create_in(root) xcodeproj.create_in(root)
xcconfig.create_in(root) xcconfig.create_in(root)
copy_resources_script.create_in(root)
bridge_support_generator.create_in(root) if @specification.generate_bridge_support bridge_support_generator.create_in(root) if @specification.generate_bridge_support
build_specifications.each(&:post_install) build_specifications.each(&:post_install)
end end
end end
......
...@@ -68,6 +68,12 @@ module Pod ...@@ -68,6 +68,12 @@ module Pod
end end
attr_reader :source_files attr_reader :source_files
def resources=(*patterns)
@resources = patterns.flatten
end
attr_reader :resources
alias_method :resource=, :resources=
def clean_paths=(*patterns) def clean_paths=(*patterns)
@clean_paths = patterns.flatten.map { |p| Pathname.new(p) } @clean_paths = patterns.flatten.map { |p| Pathname.new(p) }
end end
...@@ -169,7 +175,22 @@ module Pod ...@@ -169,7 +175,22 @@ module Pod
platform.nil? platform.nil?
end end
# Returns all source files of this pod including header files. # Returns all resource files of this pod, but relative to the
# project pods root.
def expanded_resources
files = []
[*resources].each do |pattern|
pattern = pod_destroot + pattern
pattern = pattern + '*' if pattern.directory?
pattern.glob.each do |file|
files << file.relative_path_from(config.project_pods_root)
end
end
files
end
# Returns all source files of this pod including header files,
# but relative to the project pods root.
def expanded_source_files def expanded_source_files
files = [] files = []
[*source_files].each do |pattern| [*source_files].each do |pattern|
......
...@@ -32,6 +32,7 @@ module Pod ...@@ -32,6 +32,7 @@ module Pod
"but already activated version `#{required_version}' " \ "but already activated version `#{required_version}' " \
"by #{@required_by.join(', ')}." "by #{@required_by.join(', ')}."
end end
@specification = nil
@required_by << specification @required_by << specification
end end
...@@ -54,7 +55,7 @@ module Pod ...@@ -54,7 +55,7 @@ module Pod
end end
def specification def specification
Specification.from_file(specification_path) @specification ||= Specification.from_file(specification_path)
end end
# Return the first version that matches the current dependency. # Return the first version that matches the current dependency.
......
module Pod
module Xcode
class CopyResourcesScript
# A list of files relative to the project pods root.
def initialize(resources)
@resources = resources
end
def create_in(root)
return if @resources.empty?
(root + 'PodsResources.sh').open('a') do |script|
@resources.each do |resource|
script.puts "install_resource '#{resource}'"
end
end
end
end
end
end
...@@ -35,11 +35,6 @@ else ...@@ -35,11 +35,6 @@ else
config.repos_dir = fixture('spec-repos') config.repos_dir = fixture('spec-repos')
config.project_pods_root = temporary_directory + 'Pods' config.project_pods_root = temporary_directory + 'Pods'
FileUtils.cp_r(fixture('integration/.'), config.project_pods_root) FileUtils.cp_r(fixture('integration/.'), config.project_pods_root)
Dir.chdir(config.project_pods_root.to_s) do
FileUtils.mv('ASIHTTPRequest', 'ASIHTTPRequest-1.8.1')
FileUtils.mv('JSONKit', 'JSONKit-1.4')
FileUtils.mv('SSZipArchive', 'SSZipArchive-1.0')
end
end end
after do after do
...@@ -91,6 +86,22 @@ else ...@@ -91,6 +86,22 @@ else
(config.project_pods_root + 'ASIHTTPRequest.podspec').should.not.exist (config.project_pods_root + 'ASIHTTPRequest.podspec').should.not.exist
end end
it "adds resources to the xcode copy script" do
spec = Pod::File.new do |s|
s.platform = platform
s.dependency 'SSZipArchive'
end
installer = SpecHelper::Installer.new(spec)
dependency_spec = installer.build_specifications.first
dependency_spec.resources = 'LICEN*', 'Readme.*'
installer.install!
contents = (config.project_pods_root + 'PodsResources.sh').read
contents.should.include "install_resource 'SSZipArchive/LICENSE'\n" \
"install_resource 'SSZipArchive/Readme.markdown'"
end
# TODO we need to do more cleaning and/or add a --prune task # TODO we need to do more cleaning and/or add a --prune task
it "overwrites an existing project.pbxproj file" do it "overwrites an existing project.pbxproj file" do
spec = Pod::File.new do |s| spec = Pod::File.new do |s|
......
...@@ -174,7 +174,7 @@ describe "A Pod::Specification, with installed source," do ...@@ -174,7 +174,7 @@ describe "A Pod::Specification, with installed source," do
config.project_pods_root = nil config.project_pods_root = nil
end end
it "returns the list of files that the source_files pattern expands to" do it "returns the list of files that the source_files pattern expand to" do
files = @destroot.glob('**/*.{h,c,m}') files = @destroot.glob('**/*.{h,c,m}')
files = files.map { |file| file.relative_path_from(config.project_pods_root) } files = files.map { |file| file.relative_path_from(config.project_pods_root) }
@spec.expanded_source_files.sort.should == files.sort @spec.expanded_source_files.sort.should == files.sort
...@@ -251,6 +251,14 @@ describe "A Pod::Specification, with installed source," do ...@@ -251,6 +251,14 @@ describe "A Pod::Specification, with installed source," do
"$(BUILT_PRODUCTS_DIR)/Pods/AnotherRoot/ns" "$(BUILT_PRODUCTS_DIR)/Pods/AnotherRoot/ns"
} }
end end
it "returns the list of files that the resources pattern expand to" do
@spec.expanded_resources.should == []
@spec.resource = 'LICEN*'
@spec.expanded_resources.map(&:to_s).should == %w{ SSZipArchive/LICENSE }
@spec.resources = 'LICEN*', 'Readme.*'
@spec.expanded_resources.map(&:to_s).should == %w{ SSZipArchive/LICENSE SSZipArchive/Readme.markdown }
end
end end
describe "A Pod::Specification, in general," do describe "A Pod::Specification, in general," do
......
#!/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