Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sources priorities taken into account #11324

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`

##### Bug Fixes

* Sources priority in Podfile works as stated in documentation.
[Ilya Myakotin](https://github.com/rehsals)
[#8679](https://github.com/CocoaPods/CocoaPods/issues/8679)

* Fix incremental installation when a development pod is deleted.
[John Szumski](https://github.com/jszumski)
[#11438](https://github.com/CocoaPods/CocoaPods/pull/11681)
Expand Down
12 changes: 7 additions & 5 deletions lib/cocoapods/resolver/lazy_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ def all_specifications(warn_for_multiple_pod_sources, requirement)
@all_specifications ||= {}
@all_specifications[requirement] ||= begin
sources_by_version = {}
satisfactory_versions_by_source = {}
versions_by_source.each do |source, versions|
versions.each do |v|
next unless requirement.satisfied_by?(v)

(satisfactory_versions_by_source[source] ||= []) << v
(sources_by_version[v] ||= []) << source
end
end
Expand All @@ -75,11 +77,11 @@ def all_specifications(warn_for_multiple_pod_sources, requirement)
end
end

# sort versions from high to low
sources_by_version.sort_by(&:first).flat_map do |version, sources|
# within each version, we want the prefered (first-specified) source
# to be the _last_ one
sources.reverse_each.map { |source| LazySpecification.new(name, version, source) }
# we want the prefered (first-specified) source
# to be the _last_ one
satisfactory_versions_by_source.reverse_each.flat_map do |source, versions|
# sort versions from low to high within each source
versions.sort.each.map { |v| LazySpecification.new(name, v, source) }
end
end
end
Expand Down
98 changes: 96 additions & 2 deletions spec/unit/resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,13 @@ def create_resolver(podfile = @podfile, locked_deps = empty_graph, specs_updated
platform :ios
pod 'JSONKit', '<= 1.5pre'
end
resolver = create_resolver(podfile)
sources = config.sources_manager.sources(%w(trunk))
resolver = Resolver.new(config.sandbox, podfile, empty_graph, sources, false)
version = resolver.resolve.values.flatten.first.spec.version
version.to_s.should == '1.5pre'

locked_deps = dependency_graph_from_array([Dependency.new('JSONKit', '= 1.4')])
resolver = create_resolver(podfile, locked_deps)
resolver = Resolver.new(config.sandbox, podfile, locked_deps, sources, false)
version = resolver.resolve.values.flatten.first.spec.version
version.to_s.should == '1.4'
end
Expand Down Expand Up @@ -965,6 +966,99 @@ def create_resolver(podfile = @podfile, locked_deps = empty_graph, specs_updated
UI.warnings.should.match /multiple specifications/
end

it 'chooses the first source despite having newer version in another source' do
test_repo1 = MockSource.new('test_repo1') do
pod 'Core', '1.0.0' do
test_spec
end
pod 'Core', '1.0.1' do
test_spec
end
pod 'Data', '1.0.0' do |s|
s.dependency 'Core', '~> 1.0'
test_spec { |ts| ts.dependency 'Testing', '~> 1.0' }
end
pod 'Data', '1.0.1' do |s|
s.dependency 'Core', '~> 1.0'
test_spec { |ts| ts.dependency 'Testing', '~> 1.0' }
end
end

test_repo2 = MockSource.new('test_repo2') do
pod 'Core', '1.0.2' do
test_spec
end
pod 'Data', '1.0.2' do |s|
s.dependency 'Core', '~> 1.0'
test_spec { |ts| ts.dependency 'Testing', '~> 1.0' }
end
end
podfile = Podfile.new do
platform :ios, '9.0'
pod 'Data', '~> 1.0'
end

sources = [test_repo1, test_repo2]
resolver = Resolver.new(config.sandbox, podfile, empty_graph, sources, false)
resolver.resolve.values.flatten.map { |rs| rs.spec.to_s }.sort.
should == ['Core (1.0.1)', 'Data (1.0.1)']

sources = [test_repo2, test_repo1]
resolver = Resolver.new(config.sandbox, podfile, empty_graph, sources, false)
resolver.resolve.values.flatten.map { |rs| rs.spec.to_s }.sort.
should == ['Core (1.0.2)', 'Data (1.0.2)']
end

it 'chooses the first source while having same versions in another' do
test_repo1 = MockSource.new('test_repo1') do
pod 'Core', '1.0.0' do
test_spec
end
pod 'Core', '1.0.1' do
test_spec
end
pod 'Data', '1.0.0' do |s|
s.dependency 'Core', '~> 1.0'
test_spec { |ts| ts.dependency 'Testing', '~> 1.0' }
end
pod 'Data', '1.0.1' do |s|
s.dependency 'Core', '~> 1.0'
test_spec { |ts| ts.dependency 'Testing', '~> 1.0' }
end
end

test_repo2 = MockSource.new('test_repo2') do
pod 'Core', '1.0.0' do
test_spec
end
pod 'Core', '1.0.1' do
test_spec
end
pod 'Data', '1.0.0' do |s|
s.dependency 'Core', '~> 1.0'
test_spec { |ts| ts.dependency 'Testing', '~> 1.0' }
end
pod 'Data', '1.0.1' do |s|
s.dependency 'Core', '~> 1.0'
test_spec { |ts| ts.dependency 'Testing', '~> 1.0' }
end
end
podfile = Podfile.new do
platform :ios, '9.0'
pod 'Data', '~> 1.0'
end

sources = [test_repo1, test_repo2]
resolver = Resolver.new(config.sandbox, podfile, empty_graph, sources, false)
resolver.resolve.values.flatten.map { |rs| "#{rs.spec} #{rs.spec.spec_source.name}" }.sort.
should == ['Core (1.0.1) test_repo1', 'Data (1.0.1) test_repo1']

sources = [test_repo2, test_repo1]
resolver = Resolver.new(config.sandbox, podfile, empty_graph, sources, false)
resolver.resolve.values.flatten.map { |rs| "#{rs.spec} #{rs.spec.spec_source.name}" }.sort.
should == ['Core (1.0.1) test_repo2', 'Data (1.0.1) test_repo2']
end

it 'chooses the first source in a complicated scenario' do
test_repo1 = MockSource.new('test_repo1') do
pod 'Core', '1.0.0' do
Expand Down