Skip to content

Commit

Permalink
Merge 1e26ac7 into b2c3f33
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Aug 1, 2013
2 parents b2c3f33 + 1e26ac7 commit fc211b2
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 58 deletions.
37 changes: 27 additions & 10 deletions lib/cocoapods-core/specification/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ 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 :vendored_frameworks

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

# @return [Hash{String=>String}]] hash where the keys are the names of
# the resource bundles and the values are their relative file
# patterns.
#
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 +348,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
134 changes: 88 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 @@ -319,8 +319,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 @@ -454,7 +454,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 @@ -790,75 +791,116 @@ def dependency(*args)

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

# @!method resources=(resources)
# @!method vendored_frameworks=(*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.vendored_frameworks = 'Frameworks/MyFramework.framework'
#
# @example
#
# spec.resources = ["Images/*.png", "Sounds/*"]
# spec.vendored_frameworks = 'MyFramework.framework', 'TheirFramework.framework'
#
# @param [String, Array<String>] resources the resources of the Pod.
# @param [String, Array<String>] vendored_frameworks
# A list of framework bundles paths.
#
attribute :resources, {
:container => Array,
attribute :vendored_frameworks, {
: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 vendored_libraries=(*frameworks)
#
# The paths of the libraries that come shipped with the Pod.
#
# @example
#
# spec.ios.vendored_library = 'Libraries/libProj4.a'
#
# @example
#
RESOURCES_DESTINATIONS = [
:products_directory,
:wrapper,
:resources,
:executables,
:java_resources,
:frameworks,
:shared_frameworks,
:shared_support,
:plug_ins,
].freeze
# spec.vendored_libraries = 'libProj4.a', 'libJavaScriptCore.a'
#
# @param [String, Array<String>] vendored_libraries
# A list of library paths.
#
attribute :vendored_libraries, {
: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. They are specified as a
# hash where the keys represent the name of the bundles and the values
# the file patterns that they should include.
#
# ---
# We strongly **recommend** library developers to adopt resource
# bundles as there can be name collisions using the resources
# attribute.
#
# The names of the bundles should at least include the name of the Pod
# to minimize the change of name collisions.
#
# It is possible to specify a destination, if not specified the files
# are copied to the `resources` folder of the bundle.
# To provide different resources per platform namespaced bundles *must*
# be used.
#
# @example
#
# spec.resource = "Resources/HockeySDK.bundle"
# spec.ios.resource_bundle = { 'MapBox' => 'MapView/Map/Resources/*.png' }
#
# @example
#
# spec.resource_bundles = { 'MapBox' => ['MapView/Map/Resources/*.png'], 'OtherResources' => ['MapView/Map/OtherResources/*.png'] }
#
# @param [Hash{String=>String}] resource_bundles
# A hash where the keys are the names of the resource bundles
# and the values are their relative file patterns.
#
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.
#
# We strongly **recommend** library developers to adopt [resource
# bundles](http://docs.cocoapods.org/specification.html#resources) as
# there can be name collisions using the resources attribute. Moreover
# resources specified with this attribute are copied directly to the
# client target and therefore they are not optimized by Xcode.
#
# @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.vendored_frameworks = [ "MyFramework.framework", "MyOtherFramework.framework" ]
@consumer.vendored_frameworks.should == [ "MyFramework.framework", "MyOtherFramework.framework" ]
end

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

it "returns the library files" do
@spec.vendored_libraries = ['libProj4.a', 'libJavaScriptCore.a']
@consumer.vendored_libraries.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 @@ -223,6 +223,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.vendored_frameworks = [ "Parse.framework" ]
@spec.attributes_hash["vendored_frameworks"].should == [ "Parse.framework" ]
end


it "allows to specify the libraries shipped with the Pod" do
@spec.vendored_libraries = [ "libProj4.a" ]
@spec.attributes_hash["vendored_libraries"].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 @@ -337,8 +353,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 frameworks libraries preserve_paths
resource_bundles resources screenshots vendored_frameworks
vendored_libraries weak_frameworks
]
end
end
Expand Down

0 comments on commit fc211b2

Please sign in to comment.