From 9d3740f44efea3cd1d72d0a7f826560120179198 Mon Sep 17 00:00:00 2001 From: Igor Makarov Date: Tue, 3 Sep 2019 11:56:53 +0300 Subject: [PATCH 1/3] allow to reuse external source specification in Podifle --- lib/cocoapods-core/podfile/dsl.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/cocoapods-core/podfile/dsl.rb b/lib/cocoapods-core/podfile/dsl.rb index 5bdfe4ae4..df732ab0a 100644 --- a/lib/cocoapods-core/podfile/dsl.rb +++ b/lib/cocoapods-core/podfile/dsl.rb @@ -292,6 +292,19 @@ def ensure_bundler!(version = nil) # # pod 'JSONKit', :podspec => 'https://example.com/JSONKit.podspec' # + # ### Use a previously defined external source. + # + # If a dependency was already defined using an external source, reuse that definition: + # + # target 'TargetA' do + # # define an external source for `JSONKit` + # pod 'JSONKit', :podspec => 'https://example.com/JSONKit.podspec' + # end + # + # target 'TargetB' do + # # reuse the previous external source for `JSONKit` + # pod 'JSONKit' + # end # # @note This method allow a nil name and the raises to be more # informative. @@ -303,6 +316,18 @@ def pod(name = nil, *requirements) raise StandardError, 'A dependency requires a name.' end + if requirements.empty? || requirements.last.is_a?(Hash) + theoretical_dependency = Dependency.new(name, requirements.last) + if theoretical_dependency.external_source.nil? + previously_defined_dependency = dependencies.find do |dependency| + dependency.root_name == theoretical_dependency.root_name && dependency.external_source + end + if previously_defined_dependency + requirements = [previously_defined_dependency.external_source] + end + end + end + current_target_definition.store_pod(name, *requirements) end From 2eac0be5e40b16b9bba566059af2ef751bf564f7 Mon Sep 17 00:00:00 2001 From: Igor Makarov Date: Sat, 7 Dec 2019 13:14:30 +0200 Subject: [PATCH 2/3] test for external source reuse --- spec/podfile/dsl_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/podfile/dsl_spec.rb b/spec/podfile/dsl_spec.rb index 806aba659..427ffec5e 100644 --- a/spec/podfile/dsl_spec.rb +++ b/spec/podfile/dsl_spec.rb @@ -411,6 +411,24 @@ module Pod target.dependencies.sort_by(&:name).should == expected_dependencies end + it 'implicitly reuses an external source' do + podfile = Podfile.new do + target 'A' do + pod 'RestKit', :git => 'https://github.com/RestKit/RestKit.git' + end + + target 'B' do + pod 'RestKit' + end + end + + expected_dependencies = [ + Dependency.new('RestKit', :git => 'https://github.com/RestKit/RestKit.git'), + ] + podfile.target_definitions['A'].dependencies.sort_by(&:name).should == expected_dependencies + podfile.target_definitions['B'].dependencies.sort_by(&:name).should == expected_dependencies + end + it 'raises if no name is specified for a Pod' do lambda do Podfile.new do From b64674c6e81be8060c57fa1810c7ae09ad814ef3 Mon Sep 17 00:00:00 2001 From: Igor Makarov Date: Sat, 7 Dec 2019 15:12:25 +0200 Subject: [PATCH 3/3] rewrite some getters that were unnecessarily mutating the internal hash --- lib/cocoapods-core/podfile/target_definition.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index 9d0307322..9a9e2fc8e 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -174,7 +174,7 @@ def abstract=(abstract) # @return [String] the inheritance mode for this target definition. # def inheritance - get_hash_value('inheritance', 'complete') + get_hash_value('inheritance') || 'complete' end # Sets the inheritance mode for this target definition. @@ -907,7 +907,7 @@ def get_hash_value(key, base_value = nil) unless HASH_KEYS.include?(key) raise StandardError, "Unsupported hash key `#{key}`" end - internal_hash[key] = base_value if internal_hash[key].nil? + internal_hash[key] ||= base_value unless base_value.nil? internal_hash[key] end