Skip to content

Commit

Permalink
[Specification] Add support for library_files & resource_bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Jul 31, 2013
1 parent 36822bf commit d8a57fc
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 61 deletions.
34 changes: 23 additions & 11 deletions lib/cocoapods-core/specification/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,21 @@ def self.spec_attr_accessor(name)
#
spec_attr_accessor :private_header_files

# @return [Array<String>] The paths of the framework bundles of the Pod.
# @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 @@ -336,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
93 changes: 45 additions & 48 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 @@ -826,82 +826,79 @@ def dependency(*args)
# A list of framework bundles paths.
#
attribute :framework_bundles, {
:container => Array,
:container => Array,
:file_patterns => true,
:singularize => true,
}

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

# @!method resources=(resources)
# @!method library_files=(*frameworks)
#
# A list of resources that should be copied into the target bundle.
# The paths of the libraries that come shipped with the Pod.
#
# @example
#
# spec.resource = "Resources/HockeySDK.bundle"
# spec.ios.library_file = 'Libraries/libProj4.a'
#
# @example
#
# spec.resources = ["Images/*.png", "Sounds/*"]
# spec.library_files = 'libProj4.a', 'libJavaScriptCore.a'
#
# @param [String, Array<String>] resources the resources of the Pod.
# @param [String, Array<String>] library_files
# A list of library paths.
#
attribute :resources, {
:container => Array,
attribute :library_files, {
: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`.
#
RESOURCES_DESTINATIONS = [
:products_directory,
:wrapper,
:resources,
:executables,
:java_resources,
:frameworks,
:shared_frameworks,
:shared_support,
:plug_ins,
].freeze

# @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.
# The paths of the resources bundles that come shipped with 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_bundle = { 'MapBox' => ['MapView/Map/Resources/*.png'], 'OtherResources' => ['MapView/Map/OtherResources/*.png'] }
#
# @param [String, Array<String>] 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 of 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
40 changes: 40 additions & 0 deletions spec/specification/consumer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,46 @@ module Pod

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

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
16 changes: 14 additions & 2 deletions spec/specification/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,22 @@ module Pod
@spec.attributes_hash["private_header_files"].should == [ "private/**/*" ]
end

it "allows to specify the frameworks bundles of the Pod" do
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 @@ -349,7 +360,8 @@ module Pod
end
singularized.map{ |attr| attr.name.to_s }.sort.should == %w[
authors compiler_flags framework_bundles frameworks libraries
preserve_paths resources screenshots weak_frameworks
library_files preserve_paths resource_bundles resources screenshots
weak_frameworks
]
end
end
Expand Down

0 comments on commit d8a57fc

Please sign in to comment.