Skip to content

Commit

Permalink
Merge d5eaba7 into 7a3292e
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Jul 31, 2013
2 parents 7a3292e + d5eaba7 commit 278262e
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 58 deletions.
36 changes: 26 additions & 10 deletions lib/cocoapods-core/specification/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ def self.spec_attr_accessor(name)
#
spec_attr_accessor :private_header_files

# @return [Array<String>] The paths of the framework bundles shipped with
# the Pod.
#
spec_attr_accessor :framework_bundles

# @return [Array<String>] The paths of the libraries shipped with the
# Pod.
#
spec_attr_accessor :library_files

# @return [Array<String>] The paths of the resource bundles shipped with
# the Pod.
#
spec_attr_accessor :resource_bundles

# @return [Array<String>] A hash where the key represents the
# paths of the resources to copy and the values the paths of
# the resources that should be copied.
Expand Down Expand Up @@ -332,22 +347,23 @@ def _prepare_prefix_header_contents(value)
value.is_a?(Array) ? value * "\n" : value
end

# Converts the resources file patterns to a hash defaulting to the
# resource key if they are defined as an Array or a String.
# Ensures that the file patterns of the resource bundles are contained in
# an array.
#
# @param [String, Array, Hash] value.
# The value of the attribute as specified by the user.
#
# @return [Hash] the resources.
#
# def _prepare_resources_bundle(value)
# value = { :resources => value } unless value.is_a?(Hash)
# result = {}
# value.each do |key, patterns|
# result[key] = [*patterns].compact
# end
# result
# end
def _prepare_resource_bundles(value)
result = {}
if value
value.each do |key, patterns|
result[key] = [*patterns].compact
end
end
result
end

#-----------------------------------------------------------------------#

Expand Down
115 changes: 69 additions & 46 deletions lib/cocoapods-core/specification/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ module DSL
# The keys accepted by the hash of the source attribute.
#
SOURCE_KEYS = {
:git => [:tag, :branch, :commit, :submodules],
:svn => [:folder, :tag, :revision],
:hg => [:revision],
:http => nil,
:git => [:tag, :branch, :commit, :submodules],
:svn => [:folder, :tag, :revision],
:hg => [:revision],
:http => nil,
:path => nil
}.freeze

Expand Down Expand Up @@ -338,8 +338,8 @@ module DSL
# @todo This currently is not used in the Ruby DSL.
#
attribute :platforms, {
:container => Hash,
:keys => PLATFORMS,
:container => Hash,
:keys => PLATFORMS,
:multi_platform => false,
:inherited => true,
}
Expand Down Expand Up @@ -473,7 +473,8 @@ def dependency(*args)

# @!method frameworks=(*frameworks)
#
# A list of frameworks that the user’s target needs to link against.
# A list of system frameworks that the user’s target needs to link
# against.
#
# @example
#
Expand Down Expand Up @@ -809,75 +810,97 @@ def dependency(*args)

#------------------#

# @!method resources=(resources)
# @!method framework_bundles=(*frameworks)
#
# A list of resources that should be copied into the target bundle.
# The paths of the framework bundles that come shipped with the Pod.
#
# @example
#
# spec.resource = "Resources/HockeySDK.bundle"
# spec.ios.framework_bundles = 'Frameworks/MyFramework.framework'
#
# @example
#
# spec.resources = ["Images/*.png", "Sounds/*"]
# spec.framework_bundles = 'MyFramework.framework', 'TheirFramework.framework'
#
# @param [String, Array<String>] resources the resources of the Pod.
# @param [String, Array<String>] framework_bundles
# A list of framework bundles paths.
#
attribute :resources, {
:container => Array,
attribute :framework_bundles, {
:container => Array,
:file_patterns => true,
:singularize => true,
:singularize => true,
}

#------------------#

# The possible destinations for the `resources` attribute. Extracted form
# `Xcodeproj::Constants.COPY_FILES_BUILD_PHASE_DESTINATIONS`.
# @!method library_files=(*frameworks)
#
# The paths of the libraries that come shipped with the Pod.
#
RESOURCES_DESTINATIONS = [
:products_directory,
:wrapper,
:resources,
:executables,
:java_resources,
:frameworks,
:shared_frameworks,
:shared_support,
:plug_ins,
].freeze
# @example
#
# spec.ios.library_file = 'Libraries/libProj4.a'
#
# @example
#
# spec.library_files = 'libProj4.a', 'libJavaScriptCore.a'
#
# @param [String, Array<String>] library_files
# A list of library paths.
#
attribute :library_files, {
:container => Array,
:file_patterns => true,
:singularize => true,
}

#------------------#

# @todo Implement in CP 0.18
# method resources_bundle=(resources)
# @!method resource_bundles=(*frameworks)
#
# A list of resources that should be copied into the target bundle.
# This attribute allows to define the name and the file of the resource
# bundles which should be built for the Pod.
#
# ---
# @example
#
# It is possible to specify a destination, if not specified the files
# are copied to the `resources` folder of the bundle.
# spec.ios.resource_bundle = { 'MapBox' => 'MapView/Map/Resources/*.png' }
#
# @example
#
# spec.resource = "Resources/HockeySDK.bundle"
# spec.resource_bundles = { 'MapBox' => ['MapView/Map/Resources/*.png'], 'OtherResources' => ['MapView/Map/OtherResources/*.png'] }
#
# @param [Hash] resource_bundles
# A list of resource bundles paths.
#
attribute :resource_bundles, {
:types => [String, Array],
:container => Hash,
:file_patterns => true,
:singularize => true,
}

#------------------#

# @!method resources=(resources)
#
# A list of resources that should be copied into the target bundle.
#
# @example
#
# spec.resources = "Resources/*.png"
# spec.resource = "Resources/HockeySDK.bundle"
#
# @example
#
# spec.resources = { :frameworks => 'frameworks/CrashReporter.framework' }
# spec.resources = ["Images/*.png", "Sounds/*"]
#
# @param [Hash, String, Array<String>] resources
# the resources of the Pod.
# @param [String, Array<String>] resources
# The resources shipped with the Pod.
#
# attribute :resources_bundle, {
# :types => [String, Array],
# :file_patterns => true,
# :container => Hash,
# :keys => RESOURCES_DESTINATIONS,
# :singularize => true,
# }
attribute :resources, {
:container => Array,
:file_patterns => true,
:singularize => true,
}

#------------------#

Expand Down
47 changes: 47 additions & 0 deletions spec/specification/consumer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,53 @@ module Pod

#------------------#

it "returns the frameworks bundles" do
@spec.framework_bundles = [ "MyFramework.framework", "MyOtherFramework.framework" ]
@consumer.framework_bundles.should == [ "MyFramework.framework", "MyOtherFramework.framework" ]
end

#------------------#

it "returns the library files" do
@spec.library_files = ['libProj4.a', 'libJavaScriptCore.a']
@consumer.library_files.should == ['libProj4.a', 'libJavaScriptCore.a']
end

#------------------#

it "returns the resource bundles" do
@spec.resource_bundles = { 'MapBox' => 'MapView/Map/Resources/*.png' }
@consumer.resource_bundles.should == { 'MapBox' => ['MapView/Map/Resources/*.png'] }
end

it "handles multi-platform resource bundles" do
@spec.ios.resource_bundles = { 'MapBox' => 'MapView/Map/Resources/*.png' }
@consumer.resource_bundles.should == { 'MapBox' => ['MapView/Map/Resources/*.png'] }
end

it "merges multi platform resource bundles if needed" do
@spec.resource_bundles = { 'MapBox' => 'MapView/Map/Resources/*.png' }
@spec.ios.resource_bundles = { 'MapBox-iOS' => ['MapView/Map/iOS/Resources/*.png'] }
@consumer.resource_bundles.should == {
'MapBox' => ['MapView/Map/Resources/*.png'],
'MapBox-iOS' => ['MapView/Map/iOS/Resources/*.png'],
}
end

it "merges the file patterns of multi platform resource bundles if needed" do
@spec.resource_bundles = { 'MapBox' => 'MapView/Map/Resources/*.png' }
@spec.ios.resource_bundles = { 'MapBox' => ['MapView/Map/iOS/Resources/*.png'] }
@consumer.resource_bundles.should == {
'MapBox' => ['MapView/Map/Resources/*.png', 'MapView/Map/iOS/Resources/*.png'],
}
end

it "returns the empty hash if no resource bundles have been specified" do
@consumer.resource_bundles.should == {}
end

#------------------#

it "returns the resources files" do
@spec.resources = ['frameworks/CrashReporter.framework']
@consumer.resources.should == ['frameworks/CrashReporter.framework']
Expand Down
21 changes: 19 additions & 2 deletions spec/specification/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,22 @@ module Pod
@spec.attributes_hash["private_header_files"].should == [ "private/**/*" ]
end

it "allows to specify the frameworks bundles shipped with the Pod" do
@spec.framework_bundles = [ "Parse.framework" ]
@spec.attributes_hash["framework_bundles"].should == [ "Parse.framework" ]
end


it "allows to specify the libraries shipped with the Pod" do
@spec.library_files = [ "libProj4.a" ]
@spec.attributes_hash["library_files"].should == [ "libProj4.a" ]
end

it "allows to specify the resources bundles shipped with the Pod" do
@spec.resource_bundles = { 'MapBox' => 'MapView/Map/Resources/*.png' }
@spec.attributes_hash["resource_bundles"].should == { 'MapBox' => 'MapView/Map/Resources/*.png' }
end

it "allows to specify the resources files" do
@spec.resources = ['frameworks/CrashReporter.framework']
@spec.attributes_hash["resources"].should == ['frameworks/CrashReporter.framework']
Expand Down Expand Up @@ -343,8 +359,9 @@ module Pod
spec.should.respond_to(attr.writer_name)
end
singularized.map{ |attr| attr.name.to_s }.sort.should == %w[
authors compiler_flags frameworks libraries
preserve_paths resources screenshots weak_frameworks
authors compiler_flags framework_bundles frameworks libraries
library_files preserve_paths resource_bundles resources screenshots
weak_frameworks
]
end
end
Expand Down

0 comments on commit 278262e

Please sign in to comment.