Commit 7e26391a authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #3030 from CocoaPods/seg-resources-by-config

[CopyResourcesScript] Copy only the resources required for the current build configuration.
parents dfa52754 1b7ccc4e
......@@ -12,6 +12,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
instead of `note`.
[Hugo Tunius](https://github.com/K0nserv)
* Copy only the resources required for the current build configuration.
[Samuel Giddins](https://github.com/segiddins)
[#2391](https://github.com/CocoaPods/CocoaPods/issues/2391)
##### Bug Fixes
* Ensure that linting fails if xcodebuild doesn't successfully build your Pod.
......
module Pod
module Generator
class CopyResourcesScript
# @return [Array<#to_s>] A list of files relative to the project pods
# root.
# @return [Hash{String, Array{String}] A list of files relative to the
# project pods root, keyed by build configuration.
#
attr_reader :resources
attr_reader :resources_by_config
# @return [Platform] The platform of the library for which the copy
# resources script is needed.
#
attr_reader :platform
# @param [Array<#to_s>] resources @see resources
# @param [Hash{String, Array{String}]
# resources_by_config @see resources_by_config
# @param [Platform] platform @see platform
#
def initialize(resources, platform)
@resources = resources
def initialize(resources_by_config, platform)
@resources_by_config = resources_by_config
@platform = platform
end
......@@ -58,25 +59,35 @@ module Pod
#
def install_resources_function
if use_external_strings_file?
INSTALL_RESOURCES_FUCTION
INSTALL_RESOURCES_FUNCTION
else
INSTALL_RESOURCES_FUCTION.gsub(' --reference-external-strings-file', '')
INSTALL_RESOURCES_FUNCTION.gsub(' --reference-external-strings-file', '')
end
end
# @return [String] The contents of the copy resources script.
#
def script
# Define install function
script = install_resources_function
resources.each do |resource|
script += %( install_resource "#{resource}"\n )
# Call function for each configuration-dependent resource
resources_by_config.each do |config, resources|
unless resources.empty?
script += %(if [[ "$CONFIGURATION" == "#{config}" ]]; then\n)
resources.each do |resource|
script += " install_resource '#{resource}'\n"
end
script += "fi\n"
end
end
script += RSYNC_CALL
script += XCASSETS_COMPILE
script
end
INSTALL_RESOURCES_FUCTION = <<EOS
INSTALL_RESOURCES_FUNCTION = <<EOS
#!/bin/sh
set -e
......
......@@ -114,14 +114,15 @@ module Pod
library_targets = target.pod_targets.reject do |pod_target|
pod_target.should_build? && pod_target.requires_frameworks?
end
file_accessors = library_targets.flat_map(&:file_accessors)
resource_paths = file_accessors.flat_map { |accessor| accessor.resources.flat_map { |res| res.relative_path_from(project.path.dirname) } }
resource_bundles = file_accessors.flat_map { |accessor| accessor.resource_bundles.keys.map { |name| "${BUILT_PRODUCTS_DIR}/#{name}.bundle" } }
resources = []
resources.concat(resource_paths)
resources.concat(resource_bundles)
resources << bridge_support_file if bridge_support_file
generator = Generator::CopyResourcesScript.new(resources, target.platform)
resources_by_config = {}
target.user_build_configurations.keys.each do |config|
file_accessors = library_targets.select { |t| t.include_in_build_config?(config) }.flat_map(&:file_accessors)
resource_paths = file_accessors.flat_map { |accessor| accessor.resources.flat_map { |res| res.relative_path_from(project.path.dirname) } }
resource_bundles = file_accessors.flat_map { |accessor| accessor.resource_bundles.keys.map { |name| "${BUILT_PRODUCTS_DIR}/#{name}.bundle" } }
resources_by_config[config] = resource_paths + resource_bundles
resources_by_config[config] << bridge_support_file if bridge_support_file
end
generator = Generator::CopyResourcesScript.new(resources_by_config, target.platform)
generator.save_as(path)
add_file_to_support_group(path)
end
......
......@@ -179,7 +179,7 @@ module Pod
def add_copy_resources_script_phase
phase_name = 'Copy Pods Resources'
native_targets_to_integrate.each do |native_target|
phase = native_target.shell_script_build_phases.select { |bp| bp.name == phase_name }.first
phase = native_target.shell_script_build_phases.find { |bp| bp.name == phase_name }
phase ||= native_target.new_shell_script_build_phase(phase_name)
script_path = target.copy_resources_script_relative_path
phase.shell_script = %("#{script_path}"\n)
......
......@@ -3,19 +3,30 @@ require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Generator::CopyResourcesScript do
it 'returns the copy resources script' do
resources = ['path/to/resource.png']
resources = { 'Release' => ['path/to/resource.png'] }
generator = Pod::Generator::CopyResourcesScript.new(resources, Platform.new(:ios, '6.0'))
generator.send(:script).should.include 'path/to/resource.png'
generator.send(:script).should.include 'storyboard'
end
it 'instructs ibtool to use the --reference-external-strings-file if set to do so' do
resources = ['path/to/resource.png']
resources = { 'Release' => ['path/to/resource.png'] }
generator_1 = Pod::Generator::CopyResourcesScript.new(resources, Platform.new(:ios, '4.0'))
generator_2 = Pod::Generator::CopyResourcesScript.new(resources, Platform.new(:ios, '6.0'))
generator_1.send(:script).should.not.include '--reference-external-strings-file'
generator_2.send(:script).should.include '--reference-external-strings-file'
end
it 'adds configuration dependent resources with a call wrapped in an if statement' do
resources = { 'Debug' => %w(Lookout.framework) }
generator = Pod::Generator::CopyResourcesScript.new(resources, Platform.new(:ios, '6.0'))
script = generator.send(:script)
script.should.include <<-eos.strip_heredoc
if [[ "$CONFIGURATION" == "Debug" ]]; then
install_resource 'Lookout.framework'
fi
eos
end
end
end
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