Skip to content

Commit

Permalink
Add ability to specify an explicit source for a given dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
efirestone committed Nov 3, 2015
1 parent ce26e1e commit 5bbf929
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 42 additions & 9 deletions lib/cocoapods-core/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

#--------------------------------------#
Expand Down
8 changes: 4 additions & 4 deletions lib/cocoapods-core/podfile/target_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
#
Expand Down Expand Up @@ -657,8 +657,8 @@ def pod_dependencies

# @return [Array<Dependency>] 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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cocoapods-core/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cocoapods-core/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
12 changes: 12 additions & 0 deletions spec/dependency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5bbf929

Please sign in to comment.