Commit 06a6b77c authored by Samuel E. Giddins's avatar Samuel E. Giddins

[CopyResourcesScript] Copy only the resources required for the current build configuration.

parent dfa52754
...@@ -12,6 +12,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -12,6 +12,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
instead of `note`. instead of `note`.
[Hugo Tunius](https://github.com/K0nserv) [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 ##### Bug Fixes
* Ensure that linting fails if xcodebuild doesn't successfully build your Pod. * Ensure that linting fails if xcodebuild doesn't successfully build your Pod.
......
module Pod module Pod
module Generator module Generator
class CopyResourcesScript class CopyResourcesScript
# @return [Array<#to_s>] A list of files relative to the project pods # @return [Hash{String, Array{String}] A list of files relative to the
# root. # 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 # @return [Platform] The platform of the library for which the copy
# resources script is needed. # resources script is needed.
# #
attr_reader :platform 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 # @param [Platform] platform @see platform
# #
def initialize(resources, platform) def initialize(resources_by_config, platform)
@resources = resources @resources_by_config = resources_by_config
@platform = platform @platform = platform
end end
...@@ -68,8 +69,12 @@ module Pod ...@@ -68,8 +69,12 @@ module Pod
# #
def script def script
script = install_resources_function script = install_resources_function
resources.each do |resource| resources_by_config.each do |config, resources|
script += %( install_resource "#{resource}"\n ) 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 += RSYNC_CALL
script += XCASSETS_COMPILE script += XCASSETS_COMPILE
......
...@@ -115,13 +115,15 @@ module Pod ...@@ -115,13 +115,15 @@ module Pod
pod_target.should_build? && pod_target.requires_frameworks? pod_target.should_build? && pod_target.requires_frameworks?
end end
file_accessors = library_targets.flat_map(&:file_accessors) 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) } } resources_by_config = {}
resource_bundles = file_accessors.flat_map { |accessor| accessor.resource_bundles.keys.map { |name| "${BUILT_PRODUCTS_DIR}/#{name}.bundle" } } target.user_build_configurations.keys.each do |config|
resources = [] file_accessors = library_targets.select { |t| t.include_in_build_config?(config) }.flat_map(&:file_accessors)
resources.concat(resource_paths) resource_paths = file_accessors.flat_map { |accessor| accessor.resources.flat_map { |res| res.relative_path_from(project.path.dirname) } }
resources.concat(resource_bundles) resource_bundles = file_accessors.flat_map { |accessor| accessor.resource_bundles.keys.map { |name| "${BUILT_PRODUCTS_DIR}/#{name}.bundle" } }
resources << bridge_support_file if bridge_support_file resources_by_config[config] = resource_paths + resource_bundles
generator = Generator::CopyResourcesScript.new(resources, target.platform) 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) generator.save_as(path)
add_file_to_support_group(path) add_file_to_support_group(path)
end end
......
...@@ -179,7 +179,7 @@ module Pod ...@@ -179,7 +179,7 @@ module Pod
def add_copy_resources_script_phase def add_copy_resources_script_phase
phase_name = 'Copy Pods Resources' phase_name = 'Copy Pods Resources'
native_targets_to_integrate.each do |native_target| 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) phase ||= native_target.new_shell_script_build_phase(phase_name)
script_path = target.copy_resources_script_relative_path script_path = target.copy_resources_script_relative_path
phase.shell_script = %("#{script_path}"\n) phase.shell_script = %("#{script_path}"\n)
......
...@@ -3,14 +3,14 @@ require File.expand_path('../../../spec_helper', __FILE__) ...@@ -3,14 +3,14 @@ require File.expand_path('../../../spec_helper', __FILE__)
module Pod module Pod
describe Generator::CopyResourcesScript do describe Generator::CopyResourcesScript do
it 'returns the copy resources script' 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 = Pod::Generator::CopyResourcesScript.new(resources, Platform.new(:ios, '6.0'))
generator.send(:script).should.include 'path/to/resource.png' generator.send(:script).should.include 'path/to/resource.png'
generator.send(:script).should.include 'storyboard' generator.send(:script).should.include 'storyboard'
end end
it 'instructs ibtool to use the --reference-external-strings-file if set to do so' do 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_1 = Pod::Generator::CopyResourcesScript.new(resources, Platform.new(:ios, '4.0'))
generator_2 = Pod::Generator::CopyResourcesScript.new(resources, Platform.new(:ios, '6.0')) generator_2 = Pod::Generator::CopyResourcesScript.new(resources, Platform.new(:ios, '6.0'))
......
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