From affbeae85bd179c5e9a9a927a80f2aacc4d7cf7c Mon Sep 17 00:00:00 2001 From: Joachim Bengtsson Date: Thu, 12 Dec 2013 14:28:23 +0100 Subject: [PATCH 01/15] [pod] Whitelist pods for configurations An option to only link a specific pod to the target when building in a specific configuration. The exact syntax is still TBD, pending discussion in https://github.com/CocoaPods/CocoaPods/pull/1668 which implements the corresponding functionality. --- .../podfile/target_definition.rb | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index 938470dc1..101aa5ab0 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -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 { |configuration, pods| + if pods.include?(pod_name) + found = true + return true if configuration.to_s == configuration_name.to_s + end + } + return !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 @@ -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 } @@ -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. @@ -539,6 +583,16 @@ def inhibit_warnings_hash get_hash_value('inhibit_warnings', {}) end + # Returns the configuration_pod_whitelist hash + # + # @return [Hash] 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] The dependencies specified by the user for # this target definition. # @@ -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{ |configuration| + whitelist_pod_for_configuration(name, configuration) + } + end + + requirements.pop if options.empty? + end + #-----------------------------------------------------------------------# end From 296df85207e8591b498f8da08c1b2f2ec5a6bd70 Mon Sep 17 00:00:00 2001 From: Joachim Bengtsson Date: Fri, 13 Dec 2013 14:08:12 +0100 Subject: [PATCH 02/15] [pod] whitelisting: code style and specs --- .../podfile/target_definition.rb | 10 +++++----- spec/podfile/target_definition_spec.rb | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index 101aa5ab0..8287b2337 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -332,13 +332,13 @@ def inhibit_warnings_for_pod(pod_name) # def is_pod_whitelisted_for_configuration?(pod_name, configuration_name) found = false - configuration_pod_whitelist.each { |configuration, pods| + 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 - } - return !found + end + !found end # Whitelists a pod for a specific configuration. If a pod is whitelisted @@ -693,9 +693,9 @@ def parse_configuration_whitelist(name, requirements) configurations_to_whitelist_in = options.delete(:configurations) if configurations_to_whitelist_in - configurations_to_whitelist_in.each{ |configuration| + configurations_to_whitelist_in.each do |configuration| whitelist_pod_for_configuration(name, configuration) - } + end end requirements.pop if options.empty? diff --git a/spec/podfile/target_definition_spec.rb b/spec/podfile/target_definition_spec.rb index e793b989b..a439bcab0 100644 --- a/spec/podfile/target_definition_spec.rb +++ b/spec/podfile/target_definition_spec.rb @@ -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 From cff8c54d91a92b6ee2977dbdbd5cb282fa991997 Mon Sep 17 00:00:00 2001 From: Joachim Bengtsson Date: Thu, 12 Dec 2013 14:28:23 +0100 Subject: [PATCH 03/15] [pod] Whitelist pods for configurations An option to only link a specific pod to the target when building in a specific configuration. The exact syntax is still TBD, pending discussion in https://github.com/CocoaPods/CocoaPods/pull/1668 which implements the corresponding functionality. --- .../podfile/target_definition.rb | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index 938470dc1..101aa5ab0 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -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 { |configuration, pods| + if pods.include?(pod_name) + found = true + return true if configuration.to_s == configuration_name.to_s + end + } + return !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 @@ -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 } @@ -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. @@ -539,6 +583,16 @@ def inhibit_warnings_hash get_hash_value('inhibit_warnings', {}) end + # Returns the configuration_pod_whitelist hash + # + # @return [Hash] 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] The dependencies specified by the user for # this target definition. # @@ -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{ |configuration| + whitelist_pod_for_configuration(name, configuration) + } + end + + requirements.pop if options.empty? + end + #-----------------------------------------------------------------------# end From 73c5a6b0c6331c4bfdc0d58360abf0f3f13beb56 Mon Sep 17 00:00:00 2001 From: Joachim Bengtsson Date: Fri, 13 Dec 2013 14:08:12 +0100 Subject: [PATCH 04/15] [pod] whitelisting: code style and specs --- .../podfile/target_definition.rb | 10 +++++----- spec/podfile/target_definition_spec.rb | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index 101aa5ab0..8287b2337 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -332,13 +332,13 @@ def inhibit_warnings_for_pod(pod_name) # def is_pod_whitelisted_for_configuration?(pod_name, configuration_name) found = false - configuration_pod_whitelist.each { |configuration, pods| + 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 - } - return !found + end + !found end # Whitelists a pod for a specific configuration. If a pod is whitelisted @@ -693,9 +693,9 @@ def parse_configuration_whitelist(name, requirements) configurations_to_whitelist_in = options.delete(:configurations) if configurations_to_whitelist_in - configurations_to_whitelist_in.each{ |configuration| + configurations_to_whitelist_in.each do |configuration| whitelist_pod_for_configuration(name, configuration) - } + end end requirements.pop if options.empty? diff --git a/spec/podfile/target_definition_spec.rb b/spec/podfile/target_definition_spec.rb index e793b989b..a439bcab0 100644 --- a/spec/podfile/target_definition_spec.rb +++ b/spec/podfile/target_definition_spec.rb @@ -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 From 421acb91f4ecadbfd89684d8d1430ddfb1e783fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Sun, 2 Feb 2014 22:04:19 +0100 Subject: [PATCH 05/15] [TargetDefinition] Coerce configuration names from user input to strings. --- lib/cocoapods-core/podfile/target_definition.rb | 5 +++-- spec/podfile/target_definition_spec.rb | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index 8287b2337..53c8c2a0d 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -335,7 +335,7 @@ def is_pod_whitelisted_for_configuration?(pod_name, configuration_name) configuration_pod_whitelist.each do |configuration, pods| if pods.include?(pod_name) found = true - return true if configuration.to_s == configuration_name.to_s + return true if configuration == configuration_name end end !found @@ -348,12 +348,13 @@ def is_pod_whitelisted_for_configuration?(pod_name, configuration_name) # # @param [String] pod_name # The pod that should be included in the given configuration. - # @param [String] configuration_name + # @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 diff --git a/spec/podfile/target_definition_spec.rb b/spec/podfile/target_definition_spec.rb index a439bcab0..dae27afc0 100644 --- a/spec/podfile/target_definition_spec.rb +++ b/spec/podfile/target_definition_spec.rb @@ -247,6 +247,11 @@ module Pod @root.should.is_pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") end + it "coerces configuration names to strings" do + @root.whitelist_pod_for_configuration("ObjectiveSugar", :Release) + @root.should.is_pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") + end + #--------------------------------------# it "returns its platform" do From 1f685c042636fe24691e6b90854404acbb17362b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Sun, 2 Feb 2014 22:04:50 +0100 Subject: [PATCH 06/15] [TargetDefinition] Return list of all configurations for which pods have been whitelisted. --- lib/cocoapods-core/podfile/target_definition.rb | 7 +++++++ spec/podfile/target_definition_spec.rb | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index 53c8c2a0d..c3a2ac0d9 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -359,6 +359,13 @@ def whitelist_pod_for_configuration(pod_name, configuration_name) configuration_pod_whitelist[configuration_name] << pod_name end + # @return [Array] 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. diff --git a/spec/podfile/target_definition_spec.rb b/spec/podfile/target_definition_spec.rb index dae27afc0..8ca6086dc 100644 --- a/spec/podfile/target_definition_spec.rb +++ b/spec/podfile/target_definition_spec.rb @@ -252,6 +252,13 @@ module Pod @root.should.is_pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") end + it "returns a unique list of all whitelisted configurations" do + @root.all_whitelisted_configurations.should == [] + @root.whitelist_pod_for_configuration("ObjectiveSugar", "Release") + @root.whitelist_pod_for_configuration("AFNetworking", "Release") + @root.all_whitelisted_configurations.should == ["Release"] + end + #--------------------------------------# it "returns its platform" do From c53a14e82afa7bf03bcc6175c747a173d00c69b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Sun, 2 Feb 2014 22:07:15 +0100 Subject: [PATCH 07/15] [TargetDefinition] Make predicate method more Ruby-ish. --- lib/cocoapods-core/podfile/target_definition.rb | 2 +- spec/podfile/target_definition_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index c3a2ac0d9..424be56a6 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -330,7 +330,7 @@ def inhibit_warnings_for_pod(pod_name) # @return [Bool] flag # Whether the pod should be linked with the target # - def is_pod_whitelisted_for_configuration?(pod_name, configuration_name) + def pod_whitelisted_for_configuration?(pod_name, configuration_name) found = false configuration_pod_whitelist.each do |configuration, pods| if pods.include?(pod_name) diff --git a/spec/podfile/target_definition_spec.rb b/spec/podfile/target_definition_spec.rb index 8ca6086dc..b6202e113 100644 --- a/spec/podfile/target_definition_spec.rb +++ b/spec/podfile/target_definition_spec.rb @@ -232,24 +232,24 @@ module Pod it "whitelists pods by default" do @root.store_pod("ObjectiveSugar") - @root.should.is_pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") + @root.should.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") + @root.should.not.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") + @root.should.pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") end it "coerces configuration names to strings" do @root.whitelist_pod_for_configuration("ObjectiveSugar", :Release) - @root.should.is_pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") + @root.should.pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") end it "returns a unique list of all whitelisted configurations" do From 9b1567fcb58f17e98e349ec9dcaa941fa9ec0b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Tue, 4 Feb 2014 23:28:25 +0100 Subject: [PATCH 08/15] [TargetDefinition] Also take singular :configuration for whitelisting. --- lib/cocoapods-core/podfile/target_definition.rb | 11 ++++++----- spec/podfile/target_definition_spec.rb | 12 +++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index 424be56a6..5002c506e 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -683,8 +683,8 @@ 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 + # 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 @@ -699,9 +699,10 @@ 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| + configurations = options.delete(:configurations) + configurations ||= options.delete(:configuration) + if configurations + Array(configurations).each do |configuration| whitelist_pod_for_configuration(name, configuration) end end diff --git a/spec/podfile/target_definition_spec.rb b/spec/podfile/target_definition_spec.rb index b6202e113..a080ac390 100644 --- a/spec/podfile/target_definition_spec.rb +++ b/spec/podfile/target_definition_spec.rb @@ -242,14 +242,18 @@ module Pod end it "enables pods for configurations they are whitelisted for" do - @root.store_pod("ObjectiveSugar") - @root.whitelist_pod_for_configuration("ObjectiveSugar", "Release") + @root.store_pod("ObjectiveSugar", :configuration => "Release") @root.should.pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") + @root.should.not.pod_whitelisted_for_configuration?("ObjectiveSugar", "Debug") + @root.store_pod("AFNetworking", :configurations => ["Debug"]) + @root.should.pod_whitelisted_for_configuration?("AFNetworking", "Debug") + @root.should.not.pod_whitelisted_for_configuration?("AFNetworking", "Release") end it "coerces configuration names to strings" do - @root.whitelist_pod_for_configuration("ObjectiveSugar", :Release) + @root.store_pod("ObjectiveSugar", :configuration => :Release) @root.should.pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") + @root.should.not.pod_whitelisted_for_configuration?("ObjectiveSugar", "Debug") end it "returns a unique list of all whitelisted configurations" do @@ -257,6 +261,8 @@ module Pod @root.whitelist_pod_for_configuration("ObjectiveSugar", "Release") @root.whitelist_pod_for_configuration("AFNetworking", "Release") @root.all_whitelisted_configurations.should == ["Release"] + @root.whitelist_pod_for_configuration("Objective-Record", "Debug") + @root.all_whitelisted_configurations.should == ["Release", "Debug"] end #--------------------------------------# From 6d775a30b10246ee0f87dc241788ab0b5fe89447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Wed, 5 Feb 2014 16:05:11 +0100 Subject: [PATCH 09/15] [TargetDefinition] Cleanup docs. --- lib/cocoapods-core/podfile/target_definition.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index 5002c506e..18e73963c 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -323,9 +323,12 @@ def inhibit_warnings_for_pod(pod_name) # for any configuration, it is implicitly whitelisted. # # @param [String] pod_name - # The pod that we're querying about inclusion for in the given configuration. + # 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 + # The configuration that we're querying about inclusion of the + # pod in. # # @return [Bool] flag # Whether the pod should be linked with the target @@ -348,6 +351,7 @@ def pod_whitelisted_for_configuration?(pod_name, configuration_name) # # @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 # From d793bc082f5ffc75ebb33017413919ba110e0348 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Fri, 25 Jul 2014 16:08:43 +0200 Subject: [PATCH 10/15] Style: adjustements --- .../podfile/target_definition.rb | 2 +- rubocop-todo.yml | 2 +- spec/podfile/target_definition_spec.rb | 22 +++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index a937a2050..915dba6c0 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -328,7 +328,7 @@ def inhibit_warnings_for_pod(pod_name) # @return [Bool] flag # Whether the pod should be linked with the target # - def is_pod_whitelisted_for_configuration?(pod_name, configuration_name) + def pod_whitelisted_for_configuration?(pod_name, configuration_name) found = false configuration_pod_whitelist.each do |configuration, pods| if pods.include?(pod_name) diff --git a/rubocop-todo.yml b/rubocop-todo.yml index 516409151..2d68cbe06 100644 --- a/rubocop-todo.yml +++ b/rubocop-todo.yml @@ -8,7 +8,7 @@ # Offense count: 9 # Configuration parameters: CountComments. ClassLength: - Max: 267 + Max: 300 # Offense count: 10 CyclomaticComplexity: diff --git a/spec/podfile/target_definition_spec.rb b/spec/podfile/target_definition_spec.rb index 008222fe9..e7f608567 100644 --- a/spec/podfile/target_definition_spec.rb +++ b/spec/podfile/target_definition_spec.rb @@ -230,21 +230,21 @@ module Pod #--------------------------------------# - it "whitelists pods by default" do - @root.store_pod("ObjectiveSugar") - @root.should.is_pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") + it 'whitelists pods by default' do + @root.store_pod('ObjectiveSugar') + @root.should.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") + 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.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") + it 'enables pods for configurations they are whitelisted for' do + @root.store_pod('ObjectiveSugar') + @root.whitelist_pod_for_configuration('ObjectiveSugar', 'Release') + @root.should.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Release') end #--------------------------------------# From 70272e1b0a2072be2e0585a3f3b013563b905e66 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Fri, 25 Jul 2014 16:31:50 +0200 Subject: [PATCH 11/15] Podfile: document build configuration whitelisting --- lib/cocoapods-core/podfile/dsl.rb | 20 +++++++++++++++++++ spec/podfile/dsl_spec.rb | 33 ++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lib/cocoapods-core/podfile/dsl.rb b/lib/cocoapods-core/podfile/dsl.rb index 1907fa809..801a2f018 100644 --- a/lib/cocoapods-core/podfile/dsl.rb +++ b/lib/cocoapods-core/podfile/dsl.rb @@ -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', :configurations => ['Release'] + # + # ------ + # # Dependencies can be obtained also from external sources. # # diff --git a/spec/podfile/dsl_spec.rb b/spec/podfile/dsl_spec.rb index 3e03db410..1c0c6ffd2 100644 --- a/spec/podfile/dsl_spec.rb +++ b/spec/podfile/dsl_spec.rb @@ -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 + podfile = Podfile.new do + pod 'PonyDebugger' + end + + target = podfile.target_definitions['Pods'] + target.pod_whitelisted_for_configuration?('PonyDebugger', 'Release').should.be.true + target.pod_whitelisted_for_configuration?('PonyDebugger', 'Debug').should.be.true + end + + it 'allows to white-list a dependency on multiple build configuration' do + podfile = Podfile.new do + pod 'PonyDebugger', :configurations => ['Release', 'App Store'] + end + + target = podfile.target_definitions['Pods'] + target.pod_whitelisted_for_configuration?('PonyDebugger', 'Release').should.be.true + target.pod_whitelisted_for_configuration?('PonyDebugger', 'App Store').should.be.true + target.pod_whitelisted_for_configuration?('PonyDebugger', 'Debug').should.be.false + end + + it 'allows to white-list a dependency on a build configuration' do + podfile = Podfile.new do + pod 'PonyDebugger', :configurations => ['Release'] + end + + target = podfile.target_definitions['Pods'] + target.pod_whitelisted_for_configuration?('PonyDebugger', 'Release').should.be.true + target.pod_whitelisted_for_configuration?('PonyDebugger', 'Debug').should.be.false + end + it 'raises if no name is specified for a Pod' do lambda do Podfile.new do @@ -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 podfile = Podfile.new { xcodeproj 'App.xcodeproj' } podfile.target_definitions['Pods'].user_project_path.should == 'App.xcodeproj' end From 1f6273aeb346b9d21008438b37594106fca4b7f6 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Fri, 25 Jul 2014 16:34:19 +0200 Subject: [PATCH 12/15] Podfile|: allow to whitelist a single build configuration --- lib/cocoapods-core/podfile/target_definition.rb | 6 +++--- spec/podfile/dsl_spec.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index 915dba6c0..601cfea46 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -689,9 +689,9 @@ 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| + configurations = options.delete(:configurations) + if configurations + Array(configurations).each do |configuration| whitelist_pod_for_configuration(name, configuration) end end diff --git a/spec/podfile/dsl_spec.rb b/spec/podfile/dsl_spec.rb index 1c0c6ffd2..7d7c06e44 100644 --- a/spec/podfile/dsl_spec.rb +++ b/spec/podfile/dsl_spec.rb @@ -37,7 +37,7 @@ module Pod it 'allows to white-list a dependency on a build configuration' do podfile = Podfile.new do - pod 'PonyDebugger', :configurations => ['Release'] + pod 'PonyDebugger', :configurations => 'Release' end target = podfile.target_definitions['Pods'] From fd906f719033e3ede1c4e351a7e8cd04c89a2bf8 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Fri, 25 Jul 2014 17:14:26 +0200 Subject: [PATCH 13/15] Style: fix --- rubocop-todo.yml | 2 +- spec/podfile/target_definition_spec.rb | 48 +++++++++++++------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/rubocop-todo.yml b/rubocop-todo.yml index 2d68cbe06..9e8a25d2f 100644 --- a/rubocop-todo.yml +++ b/rubocop-todo.yml @@ -8,7 +8,7 @@ # Offense count: 9 # Configuration parameters: CountComments. ClassLength: - Max: 300 + Max: 302 # Offense count: 10 CyclomaticComplexity: diff --git a/spec/podfile/target_definition_spec.rb b/spec/podfile/target_definition_spec.rb index 7f6a34d9b..ca19b3b8f 100644 --- a/spec/podfile/target_definition_spec.rb +++ b/spec/podfile/target_definition_spec.rb @@ -230,39 +230,39 @@ module Pod #--------------------------------------# - it "whitelists pods by default" do - @root.store_pod("ObjectiveSugar") - @root.should.pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") + it 'whitelists pods by default' do + @root.store_pod('ObjectiveSugar') + @root.should.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.pod_whitelisted_for_configuration?("ObjectiveSugar", "Debug") + 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.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Debug') end - it "enables pods for configurations they are whitelisted for" do - @root.store_pod("ObjectiveSugar", :configuration => "Release") - @root.should.pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") - @root.should.not.pod_whitelisted_for_configuration?("ObjectiveSugar", "Debug") - @root.store_pod("AFNetworking", :configurations => ["Debug"]) - @root.should.pod_whitelisted_for_configuration?("AFNetworking", "Debug") - @root.should.not.pod_whitelisted_for_configuration?("AFNetworking", "Release") + it 'enables pods for configurations they are whitelisted for' do + @root.store_pod('ObjectiveSugar', :configuration => 'Release') + @root.should.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Release') + @root.should.not.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Debug') + @root.store_pod('AFNetworking', :configurations => ['Debug']) + @root.should.pod_whitelisted_for_configuration?('AFNetworking', 'Debug') + @root.should.not.pod_whitelisted_for_configuration?('AFNetworking', 'Release') end - it "coerces configuration names to strings" do - @root.store_pod("ObjectiveSugar", :configuration => :Release) - @root.should.pod_whitelisted_for_configuration?("ObjectiveSugar", "Release") - @root.should.not.pod_whitelisted_for_configuration?("ObjectiveSugar", "Debug") + it 'coerces configuration names to strings' do + @root.store_pod('ObjectiveSugar', :configuration => :Release) + @root.should.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Release') + @root.should.not.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Debug') end - it "returns a unique list of all whitelisted configurations" do + it 'returns a unique list of all whitelisted configurations' do @root.all_whitelisted_configurations.should == [] - @root.whitelist_pod_for_configuration("ObjectiveSugar", "Release") - @root.whitelist_pod_for_configuration("AFNetworking", "Release") - @root.all_whitelisted_configurations.should == ["Release"] - @root.whitelist_pod_for_configuration("Objective-Record", "Debug") - @root.all_whitelisted_configurations.should == ["Release", "Debug"] + @root.whitelist_pod_for_configuration('ObjectiveSugar', 'Release') + @root.whitelist_pod_for_configuration('AFNetworking', 'Release') + @root.all_whitelisted_configurations.should == ['Release'] + @root.whitelist_pod_for_configuration('Objective-Record', 'Debug') + @root.all_whitelisted_configurations.should == %w(Release Debug) end #--------------------------------------# From cda7ff3144a8b2db46a5bfd1a627af3b34835f41 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Fri, 25 Jul 2014 17:22:34 +0200 Subject: [PATCH 14/15] Podfile: allow to whitelist a single build configuration 2 --- lib/cocoapods-core/podfile/dsl.rb | 2 +- spec/podfile/dsl_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-core/podfile/dsl.rb b/lib/cocoapods-core/podfile/dsl.rb index 801a2f018..8758a8adf 100644 --- a/lib/cocoapods-core/podfile/dsl.rb +++ b/lib/cocoapods-core/podfile/dsl.rb @@ -105,7 +105,7 @@ module DSL # # Alternatively you can white-list only a single build configuration. # - # pod 'PonyDebugger', :configurations => ['Release'] + # pod 'PonyDebugger', :configuration => ['Release'] # # ------ # diff --git a/spec/podfile/dsl_spec.rb b/spec/podfile/dsl_spec.rb index 7d7c06e44..7bbb53385 100644 --- a/spec/podfile/dsl_spec.rb +++ b/spec/podfile/dsl_spec.rb @@ -37,7 +37,7 @@ module Pod it 'allows to white-list a dependency on a build configuration' do podfile = Podfile.new do - pod 'PonyDebugger', :configurations => 'Release' + pod 'PonyDebugger', :configuration => 'Release' end target = podfile.target_definitions['Pods'] From a2f2d2405323a478ea2c91776220b82fbf6ec987 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Tue, 29 Jul 2014 19:37:11 +0200 Subject: [PATCH 15/15] [TargetDefinition] Handle build configurations case insensitively --- lib/cocoapods-core/podfile/target_definition.rb | 13 ++++++++++--- rubocop-todo.yml | 2 +- spec/podfile/target_definition_spec.rb | 8 +++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index f29bba1be..fe1700e7f 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -328,6 +328,9 @@ def inhibit_warnings_for_pod(pod_name) # The configuration that we're querying about inclusion of the # pod in. # + # @note Build configurations are case compared case-insensitively in + # CocoaPods. + # # @return [Bool] flag # Whether the pod should be linked with the target # @@ -336,7 +339,9 @@ def pod_whitelisted_for_configuration?(pod_name, configuration_name) configuration_pod_whitelist.each do |configuration, pods| if pods.include?(pod_name) found = true - return true if configuration == configuration_name + if configuration.downcase == configuration_name.to_s.downcase + return true + end end end !found @@ -344,8 +349,8 @@ def pod_whitelisted_for_configuration?(pod_name, configuration_name) # 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. + # 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. @@ -353,6 +358,8 @@ def pod_whitelisted_for_configuration?(pod_name, configuration_name) # @param [String, Symbol] configuration_name # The configuration that the pod should be included in # + # @note Build configurations are stored as a String. + # # @return [void] # def whitelist_pod_for_configuration(pod_name, configuration_name) diff --git a/rubocop-todo.yml b/rubocop-todo.yml index 9e8a25d2f..15ae3d9dc 100644 --- a/rubocop-todo.yml +++ b/rubocop-todo.yml @@ -8,7 +8,7 @@ # Offense count: 9 # Configuration parameters: CountComments. ClassLength: - Max: 302 + Max: 304 # Offense count: 10 CyclomaticComplexity: diff --git a/spec/podfile/target_definition_spec.rb b/spec/podfile/target_definition_spec.rb index ca19b3b8f..34c5b3b2e 100644 --- a/spec/podfile/target_definition_spec.rb +++ b/spec/podfile/target_definition_spec.rb @@ -256,13 +256,19 @@ module Pod @root.should.not.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Debug') end + it 'compares build configurations case-insensitively' do + @root.store_pod('ObjectiveSugar', :configuration => :Release) + @root.should.pod_whitelisted_for_configuration?('ObjectiveSugar', 'Release') + @root.should.pod_whitelisted_for_configuration?('objectivesugar', 'Release') + end + it 'returns a unique list of all whitelisted configurations' do @root.all_whitelisted_configurations.should == [] @root.whitelist_pod_for_configuration('ObjectiveSugar', 'Release') @root.whitelist_pod_for_configuration('AFNetworking', 'Release') @root.all_whitelisted_configurations.should == ['Release'] @root.whitelist_pod_for_configuration('Objective-Record', 'Debug') - @root.all_whitelisted_configurations.should == %w(Release Debug) + @root.all_whitelisted_configurations.sort.should == %w(Debug Release) end #--------------------------------------#