Commit 779412f7 authored by Fabio Pelosin's avatar Fabio Pelosin

[Generator::CopyResourcesScript] Clean-up

See #1030
parent 23857165
......@@ -20,7 +20,8 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
* Inheriting `inhibit_warnings` per pod is now working
[#1032](https://github.com/CocoaPods/CocoaPods/issues/1032)
* Fix copy resources script for iOS < 6 and OS X < 10.8 by removing the `--reference-external-strings-file`
* Fix copy resources script for iOS < 6 and OS X < 10.8 by removing the
`--reference-external-strings-file`
flag. [#1030](https://github.com/CocoaPods/CocoaPods/pull/1030)
## 0.19.1
......
module Pod
module Generator
class CopyResourcesScript
require 'fileutils'
# @return [Array<#to_s>] A list of files relative to the project pods
# root.
#
attr_reader :resources
# @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 [Platform] platform @see platform
#
def initialize(resources, platform)
@resources = resources
@platform = platform
end
# Saves the resource script to the given pathname.
#
# @param [Pathname] pathname
# The path where the copy resources script should be saved.
#
# @return [void]
#
def save_as(pathname)
pathname.open('w') do |file|
file.puts(script)
end
FileUtils.chmod('+x', pathname.to_s)
end
private
# @!group Private Helpers
# @return [Hash{Symbol=>Version}] The minimum deployment target which
# supports the `--reference-external-strings-file` option for
# the `ibtool` command.
#
EXTERNAL_STRINGS_FILE_MIMINUM_DEPLOYMENT_TARGET = {
:ios => Version.new('6.0'),
:osx => Version.new('10.8')
}
# @return [Bool] Whether the external strings file is supported by the
# `ibtool` according to the deployment target of the platform.
#
def use_external_strings_file?
minimum_deployment_target = EXTERNAL_STRINGS_FILE_MIMINUM_DEPLOYMENT_TARGET[platform.name]
platform.deployment_target >= minimum_deployment_target
end
# @return [String] The install resources shell function.
#
def install_resources_function
if use_external_strings_file?
CONTENT
else
CONTENT.gsub(' --reference-external-strings-file', '')
end
end
# @return [String] The contents of the copy resources script.
#
def script
script = install_resources_function
resources.each do |resource|
script += "install_resource '#{resource}'"
end
script
end
CONTENT = <<EOS
#!/bin/sh
......@@ -31,24 +107,6 @@ install_resource()
}
EOS
attr_reader :resources
# A list of files relative to the project pods root.
def initialize(resources = [], reference_external_strings_file = false)
@resources = resources
@reference_external_strings_file = reference_external_strings_file
end
def save_as(pathname)
pathname.open('w') do |script|
script.puts @reference_external_strings_file ? CONTENT : CONTENT.gsub(' --reference-external-strings-file', '')
@resources.each do |resource|
script.puts "install_resource '#{resource}'"
end
end
# @todo use File api
system("chmod +x '#{pathname}'")
end
end
end
end
......@@ -204,10 +204,6 @@ module Pod
end
end
ENABLE_EXTERNAL_STRINGS_FILE_FLAG = {
:ios => Version.new('6'),
:osx => Version.new('10.8')
}
# Creates a script that copies the resources to the bundle of the client
# target.
#
......@@ -221,9 +217,7 @@ module Pod
UI.message "- Generating copy resources script at #{UI.path(path)}" do
resources = library.file_accessors.map { |accessor| accessor.resources.flatten.map {|res| project.relativize(res)} }.flatten
resources << bridge_support_file if bridge_support_file
platform_name = library.platform.name
reference_external_strings_file = library.platform.deployment_target >= ENABLE_EXTERNAL_STRINGS_FILE_FLAG[platform_name]
generator = Generator::CopyResourcesScript.new(resources, reference_external_strings_file)
generator = Generator::CopyResourcesScript.new(resources, library.platform)
generator.save_as(path)
add_file_to_support_group(path)
end
......
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']
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']
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
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