From 5bbf929faae06066d8ed1ccc78204ae399ca0839 Mon Sep 17 00:00:00 2001 From: Eric Firestone Date: Mon, 2 Nov 2015 13:55:33 -0800 Subject: [PATCH] Add ability to specify an explicit source for a given dependency --- CHANGELOG.md | 4 ++ lib/cocoapods-core/dependency.rb | 51 +++++++++++++++---- .../podfile/target_definition.rb | 8 +-- lib/cocoapods-core/source.rb | 2 +- lib/cocoapods-core/specification.rb | 2 +- spec/dependency_spec.rb | 12 +++++ 6 files changed, 64 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84d896981..4ab837f4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ##### Enhancements +* Add support for specifying :source with a pod dependency + [Eric Firestone](https://github.com/efirestone) + [#278](https://github.com/CocoaPods/Core/pull/278) + * Add ability to get all platforms. [Muhammed Yavuz Nuzumlalı](https://github.com/manuyavuz) [cocoapods-search#11](https://github.com/CocoaPods/cocoapods-search/issues/11) diff --git a/lib/cocoapods-core/dependency.rb b/lib/cocoapods-core/dependency.rb index e78207c93..12bdddeb7 100644 --- a/lib/cocoapods-core/dependency.rb +++ b/lib/cocoapods-core/dependency.rb @@ -19,6 +19,11 @@ class Dependency # attr_accessor :external_source + # @return [String] The souce URL of the podspec repo to use to resolve + # this dependency. If not set then the standard source list + # should be used to resolve the dependency. + attr_accessor :podspec_repo + # @return [Bool] whether the dependency should use the podspec with the # highest know version but force the downloader to checkout the # `head` of the source repository. @@ -55,6 +60,22 @@ class Dependency # Dependency.new('libPusher', {:path => 'path/to/folder'}) # Dependency.new('libPusher', {:podspec => 'example.com/libPusher.podspec'}) # + # @overload initialize(name, requirements, podspec_repo) + # + # @param [String] name + # the name of the Pod. + # + # @param [Array, Version, String, Requirement] requirements + # an array specifying the version requirements of the + # dependency. + # + # @param [Hash] podspec_repo + # The URL of the specific podspec repo to resolve this dependency from. + # + # @example Initialization with a specific podspec repo + # + # Dependency.new('Artsy+UILabels', '~> 1.0', :source => 'https://github.com/Artsy/Specs.git') + # # @overload initialize(name, is_head) # # @param [String] name @@ -69,11 +90,23 @@ class Dependency # def initialize(name = nil, *requirements) if requirements.last.is_a?(Hash) - external_source = requirements.pop.select { |_, v| !v.nil? } - @external_source = external_source unless external_source.empty? - unless requirements.empty? - raise Informative, 'A dependency with an external source may not ' \ - "specify version requirements (#{name})." + additional_params = requirements.pop.select { |_, v| !v.nil? } + additional_params = nil if additional_params.empty? + + if additional_params && additional_params[:source] + # This dependency specifies the exact source podspec repo to use. + @podspec_repo = additional_params[:source] + additional_params.delete(:source) + unless additional_params.empty? + raise Informative, 'A dependency with a specified podspec repo may ' \ + "not include other source parameters (#{name})." + end + else + @external_source = additional_params + unless requirements.empty? + raise Informative, 'A dependency with an external source may not ' \ + "specify version requirements (#{name})." + end end elsif requirements.last == :head @@ -217,11 +250,11 @@ def <=>(other) # @param [Dependency] other # the other dependency to merge with. # - # @note If one of the decencies specifies an external source or is head, + # @note If one of the dependencies specifies an external source or is head, # the resulting dependency preserves this attributes. # - # @return [Dependency] a dependency (not necessary a new instance) that - # includes also the version requirements of the given one. + # @return [Dependency] a dependency (not necessarily a new instance) that + # also includes the version requirements of the given one. # def merge(other) unless name == other.name @@ -344,7 +377,7 @@ def self.from_string(string) # def inspect "<#{self.class} name=#{name} requirements=#{requirement} " \ - "external_source=#{external_source || 'nil'}>" + "source=#{podspec_repo || 'nil'} external_source=#{external_source || 'nil'}>" end #--------------------------------------# diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index 6724e0401..0b68b8e18 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -497,7 +497,7 @@ def store_pod(name, *requirements) # @note The storage of this information is optimized for YAML # readability. # - # @todo This needs urgently a rename. + # @todo This urgently needs a rename. # # @return [void] # @@ -657,8 +657,8 @@ def pod_dependencies # @return [Array] The dependencies inherited by the podspecs. # - # @note The podspec directive is intended include the dependencies of a - # spec in the project where it is developed. For this reason the + # @note The podspec directive is intended to include the dependencies of + # a spec in the project where it is developed. For this reason the # spec, or any of it subspecs, cannot be included in the # dependencies. Otherwise it would generate a chicken-and-egg # problem. @@ -753,7 +753,7 @@ def parse_configuration_whitelist(name, requirements) requirements.pop if options.empty? end - # Removes :subspecs form the requirements list, and stores the pods + # Removes :subspecs from the requirements list, and stores the pods # with the given subspecs as dependencies. # # @param [String] name diff --git a/lib/cocoapods-core/source.rb b/lib/cocoapods-core/source.rb index cc049dad8..0a6cc140f 100644 --- a/lib/cocoapods-core/source.rb +++ b/lib/cocoapods-core/source.rb @@ -348,7 +348,7 @@ def load_spec_gracefully(name) # # @note In previous versions of CocoaPods they used to be stored in # the root of the repo. This lead to issues, especially with - # the GitHub interface and now the are stored in a dedicated + # the GitHub interface and now they are stored in a dedicated # folder. # def specs_dir diff --git a/lib/cocoapods-core/specification.rb b/lib/cocoapods-core/specification.rb index 39615e917..8a8249177 100644 --- a/lib/cocoapods-core/specification.rb +++ b/lib/cocoapods-core/specification.rb @@ -326,7 +326,7 @@ def consumer(platform) # @!group DSL helpers - # @return [Bool] whether the specification should use a directory as it + # @return [Bool] whether the specification should use a directory as its # source. # def local? diff --git a/spec/dependency_spec.rb b/spec/dependency_spec.rb index 5dbe6a304..2950d2b8f 100644 --- a/spec/dependency_spec.rb +++ b/spec/dependency_spec.rb @@ -18,6 +18,18 @@ module Pod dependency.requirement.to_s.should == '> 1.0-pre' end + it 'can be initialized with multiple requirements and a podspec source' do + dependency = Dependency.new('bananas', '> 1.0', '< 2.0', :source => 'https://github.com/CocoaPods/CocoaPods.git') + dependency.requirement.to_s.should == '< 2.0, > 1.0' + dependency.podspec_repo.should == 'https://github.com/CocoaPods/CocoaPods.git' + end + + it 'can be initialized with a requirement on a pre-release version and a podspec source' do + dependency = Dependency.new('bananas', '> 1.0-pre', :source => 'https://github.com/CocoaPods/CocoaPods.git') + dependency.requirement.to_s.should == '> 1.0-pre' + dependency.podspec_repo.should == 'https://github.com/CocoaPods/CocoaPods.git' + end + it 'can be initialized with an external source' do dep = Dependency.new('cocoapods', :git => 'git://github.com/cocoapods/cocoapods') dep.should.be.external