Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the specification of dependencies by configuration #52

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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