From d67843a852652fd52310483b1ea52d25b9266dcf Mon Sep 17 00:00:00 2001 From: Igor Makarov Date: Tue, 3 Sep 2019 11:56:53 +0300 Subject: [PATCH] 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 7e4c1a7e0..9c88bc9b1 100644 --- a/lib/cocoapods-core/podfile/dsl.rb +++ b/lib/cocoapods-core/podfile/dsl.rb @@ -262,6 +262,19 @@ def install!(installation_method, options = {}) # # 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. @@ -273,6 +286,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