Skip to content

Commit

Permalink
Merge 296df85 into 88f665e
Browse files Browse the repository at this point in the history
  • Loading branch information
nevyn committed Dec 13, 2013
2 parents 88f665e + 296df85 commit 0c43bc7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
80 changes: 80 additions & 0 deletions lib/cocoapods-core/podfile/target_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,48 @@ def inhibit_warnings_for_pod(pod_name)

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

# Whether a specific pod should be linked to the target when building for
# a specific configuration. If a pod has not been explicitly whitelisted
# for any configuration, it is implicitly whitelisted.
#
# @param [String] pod_name
# The pod that we're querying about inclusion for in the given configuration.
# @param [String] configuration_name
# The configuration that we're querying about inclusion of the pod in
#
# @return [Bool] flag
# Whether the pod should be linked with the target
#
def is_pod_whitelisted_for_configuration?(pod_name, configuration_name)
found = false
configuration_pod_whitelist.each do |configuration, pods|
if pods.include?(pod_name)
found = true
return true if configuration.to_s == configuration_name.to_s
end
end
!found
end

# Whitelists a pod for a specific configuration. If a pod is whitelisted
# for any configuration, it will only be linked with the target in the
# configuration(s) specified. If it is not whitelisted for any configuration,
# it is implicitly included in all configurations.
#
# @param [String] pod_name
# The pod that should be included in the given configuration.
# @param [String] configuration_name
# The configuration that the pod should be included in
#
# @return [void]
#
def whitelist_pod_for_configuration(pod_name, configuration_name)
configuration_pod_whitelist[configuration_name] ||= []
configuration_pod_whitelist[configuration_name] << pod_name
end

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

# @return [Platform] the platform of the target definition.
#
# @note If no deployment target has been specified a default value is
Expand Down Expand Up @@ -386,6 +428,7 @@ def set_platform(name, target = nil)
#
def store_pod(name, *requirements)
parse_inhibit_warnings(name, requirements)
parse_configuration_whitelist(name, requirements)

if requirements && !requirements.empty?
pod = { name => requirements }
Expand Down Expand Up @@ -446,6 +489,7 @@ def store_podspec(options = nil)
build_configurations
dependencies
children
configuration_pod_whitelist
].freeze

# @return [Hash] The hash representation of the target definition.
Expand Down Expand Up @@ -539,6 +583,16 @@ def inhibit_warnings_hash
get_hash_value('inhibit_warnings', {})
end

# Returns the configuration_pod_whitelist hash
#
# @return [Hash<String, Array>] Hash with configuration name as key,
# array of pod names to be linked in builds with that configuration
# as value.
#
def configuration_pod_whitelist
get_hash_value('configuration_pod_whitelist', {})
end

# @return [Array<Dependency>] The dependencies specified by the user for
# this target definition.
#
Expand Down Expand Up @@ -621,6 +675,32 @@ def parse_inhibit_warnings(name, requirements)
requirements.pop if options.empty?
end

# Removes :configurations from the requirements list,
# and adds the pod's name into internal hash for which pods should be
# linked in which configuration only.
#
# @param [String] pod name
#
# @param [Array] requirements
# If :configurations is the only key in the hash, the hash
# should be destroyed because it confuses Gem::Dependency.
#
# @return [void]
#
def parse_configuration_whitelist(name, requirements)
options = requirements.last
return requirements unless options.is_a?(Hash)

configurations_to_whitelist_in = options.delete(:configurations)
if configurations_to_whitelist_in
configurations_to_whitelist_in.each do |configuration|
whitelist_pod_for_configuration(name, configuration)
end
end

requirements.pop if options.empty?
end

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

end
Expand Down
19 changes: 19 additions & 0 deletions spec/podfile/target_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,25 @@ module Pod

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

it "whitelists pods by default" do
@root.store_pod("ObjectiveSugar")
@root.should.is_pod_whitelisted_for_configuration?("ObjectiveSugar", "Release")
end

it "does not enable pods for un-whitelisted configurations if it is whitelisted for another" do
@root.store_pod("ObjectiveSugar")
@root.whitelist_pod_for_configuration("ObjectiveSugar", "Release")
@root.should.not.is_pod_whitelisted_for_configuration?("ObjectiveSugar", "Debug")
end

it "enables pods for configurations they are whitelisted for" do
@root.store_pod("ObjectiveSugar")
@root.whitelist_pod_for_configuration("ObjectiveSugar", "Release")
@root.should.is_pod_whitelisted_for_configuration?("ObjectiveSugar", "Release")
end

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

it "returns its platform" do
@root.platform.should == Pod::Platform.new(:ios, '6.0')
end
Expand Down

0 comments on commit 0c43bc7

Please sign in to comment.