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

Whitelist Pods by build configuration #154

Merged
merged 17 commits into from
Aug 12, 2014
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
20 changes: 20 additions & 0 deletions lib/cocoapods-core/podfile/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ module DSL
#
# ------
#
# ### Build configurations
#
# *IMPORTANT*: the following syntax is tentative and might change without
# notice in future. This feature is released in this state due to
# the strong demand for it. You can use it but you might need to change
# your Podfile to use future versions of CocoaPods. Anyway a clear and
# simple upgrade path will be provided.
#
# By default dependencies are installed on all the build configurations
# of the target. For debug purposes or for other reasons, they can be
# enabled only on a given list of build configuration names.
#
# pod 'PonyDebugger', :configurations => ['Release', 'App Store']
#
# Alternatively you can white-list only a single build configuration.
#
# pod 'PonyDebugger', :configuration => ['Release']
#
# ------
#
# Dependencies can be obtained also from external sources.
#
#
Expand Down
92 changes: 92 additions & 0 deletions lib/cocoapods-core/podfile/target_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,60 @@ 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 pod_whitelisted_for_configuration?(pod_name, configuration_name)
found = false
configuration_pod_whitelist.each do |configuration, pods|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use next to skip iteration.

if pods.include?(pod_name)
found = true
return true if configuration == configuration_name
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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [83/80]

# it is implicitly included in all configurations.
#
# @param [String] pod_name
# The pod that should be included in the given configuration.
#
# @param [String, Symbol] configuration_name
# The configuration that the pod should be included in
#
# @return [void]
#
def whitelist_pod_for_configuration(pod_name, configuration_name)
configuration_name = configuration_name.to_s
configuration_pod_whitelist[configuration_name] ||= []
configuration_pod_whitelist[configuration_name] << pod_name
end

# @return [Array<String>] unique list of all configurations for which
# pods have been whitelisted.
#
def all_whitelisted_configurations
configuration_pod_whitelist.keys.uniq
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 @@ -384,6 +438,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 @@ -444,6 +499,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 @@ -537,6 +593,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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [81/80]

# as value.
#
def configuration_pod_whitelist
get_hash_value('configuration_pod_whitelist', {})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

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

# Removes :configurations or :configuration from the requirements list,
# and adds the pod's name into the 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 = options.delete(:configurations)
configurations ||= options.delete(:configuration)
if configurations
Array(configurations).each do |configuration|
whitelist_pod_for_configuration(name, configuration)
end
end
requirements.pop if options.empty?
end

#-----------------------------------------------------------------------#
end
end
Expand Down
2 changes: 1 addition & 1 deletion rubocop-todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Offense count: 9
# Configuration parameters: CountComments.
ClassLength:
Max: 267
Max: 302

# Offense count: 10
CyclomaticComplexity:
Expand Down
33 changes: 32 additions & 1 deletion spec/podfile/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,37 @@ module Pod
podfile.dependencies.find { |d| d.root_name == 'SSZipArchive' }.should == Dependency.new('SSZipArchive', '>= 0.1')
end

it 'white-list dependencies on all build configuration by default' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

podfile = Podfile.new do
pod 'PonyDebugger'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

target = podfile.target_definitions['Pods']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

target.pod_whitelisted_for_configuration?('PonyDebugger', 'Release').should.be.true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [91/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

target.pod_whitelisted_for_configuration?('PonyDebugger', 'Debug').should.be.true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [89/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

it 'allows to white-list a dependency on multiple build configuration' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

podfile = Podfile.new do
pod 'PonyDebugger', :configurations => ['Release', 'App Store']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

target = podfile.target_definitions['Pods']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

target.pod_whitelisted_for_configuration?('PonyDebugger', 'Release').should.be.true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [91/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

target.pod_whitelisted_for_configuration?('PonyDebugger', 'App Store').should.be.true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [93/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

target.pod_whitelisted_for_configuration?('PonyDebugger', 'Debug').should.be.false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [90/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

it 'allows to white-list a dependency on a build configuration' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

podfile = Podfile.new do
pod 'PonyDebugger', :configuration => 'Release'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

target = podfile.target_definitions['Pods']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

target.pod_whitelisted_for_configuration?('PonyDebugger', 'Release').should.be.true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [91/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

target.pod_whitelisted_for_configuration?('PonyDebugger', 'Debug').should.be.false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [90/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

it 'raises if no name is specified for a Pod' do
lambda do
Podfile.new do
Expand Down Expand Up @@ -92,7 +123,7 @@ module Pod
end
end

it 'allows to specify the user xcode project for a Target definition' do
it 'allows to specify the user Xcode project for a Target definition' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

podfile = Podfile.new { xcodeproj 'App.xcodeproj' }
podfile.target_definitions['Pods'].user_project_path.should == 'App.xcodeproj'
end
Expand Down
37 changes: 37 additions & 0 deletions spec/podfile/target_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,43 @@ module Pod

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

it 'whitelists pods by default' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.store_pod('ObjectiveSugar')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.should.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Release')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [84/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [84/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

it 'does not enable pods for un-whitelisted configurations if it is whitelisted for another' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [101/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [101/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.store_pod('ObjectiveSugar')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.whitelist_pod_for_configuration('ObjectiveSugar', 'Release')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.should.not.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Debug')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [86/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [86/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

it 'enables pods for configurations they are whitelisted for' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.store_pod('ObjectiveSugar', :configuration => 'Release')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.should.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Release')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [84/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.should.not.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Debug')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [86/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.store_pod('AFNetworking', :configurations => ['Debug'])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.should.pod_whitelisted_for_configuration?('AFNetworking', 'Debug')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.should.not.pod_whitelisted_for_configuration?('AFNetworking', 'Release')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [86/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

it 'coerces configuration names to strings' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.store_pod('ObjectiveSugar', :configuration => :Release)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.should.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Release')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [84/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [84/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.should.not.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Debug')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [86/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end

it 'returns a unique list of all whitelisted configurations' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.all_whitelisted_configurations.should == []
@root.whitelist_pod_for_configuration('ObjectiveSugar', 'Release')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.whitelist_pod_for_configuration('AFNetworking', 'Release')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.all_whitelisted_configurations.should == ['Release']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.whitelist_pod_for_configuration('Objective-Record', 'Debug')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@root.all_whitelisted_configurations.should == %w(Release Debug)
end

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

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