Commit ecd9229e authored by Samuel E. Giddins's avatar Samuel E. Giddins

[Analyzer] Improve handling of different types of duplicate dependencies

parent 6ea048ac
...@@ -60,6 +60,18 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides ...@@ -60,6 +60,18 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
[Eloy Durán](https://github.com/alloy) [Eloy Durán](https://github.com/alloy)
[#2722](https://github.com/CocoaPods/CocoaPods/pull/2722) [#2722](https://github.com/CocoaPods/CocoaPods/pull/2722)
* Analysis is now halted and the user informed when there are multiple different
external sources for dependencies with the same root name.
The user is also now warned when there are duplicate dependencies in the
Podfile.
[Samuel Giddins](https://github.com/segiddins)
[#2738](https://github.com/CocoaPods/CocoaPods/issues/2738)
* Multiple subspecs that point to the same external dependency will now only
cause that external source to be fetched once.
[Samuel Giddins](https://github.com/segiddins)
[#2743](https://github.com/CocoaPods/CocoaPods/issues/2743)
##### Bug Fixes ##### Bug Fixes
* Do not try to clone spec-repos in `/`. * Do not try to clone spec-repos in `/`.
......
...@@ -268,6 +268,11 @@ module Pod ...@@ -268,6 +268,11 @@ module Pod
deps_to_fetch_if_needed = [] deps_to_fetch_if_needed = []
deps_with_external_source = podfile.dependencies.select(&:external_source) deps_with_external_source = podfile.dependencies.select(&:external_source)
deps_with_different_sources = podfile.dependencies.group_by(&:root_name).select { |_root_name, dependencies| dependencies.map(&:external_source).uniq.count > 1 }
deps_with_different_sources.each do |root_name, dependencies|
raise Informative, "There are multiple dependencies with different sources for `#{root_name}` in #{UI.path podfile.defined_in_file}:\n\n- #{dependencies.map(&:to_s).join("\n- ")}"
end
if update_mode == :all if update_mode == :all
deps_to_fetch = deps_with_external_source deps_to_fetch = deps_with_external_source
else else
...@@ -282,7 +287,7 @@ module Pod ...@@ -282,7 +287,7 @@ module Pod
unless deps_to_fetch.empty? unless deps_to_fetch.empty?
UI.section 'Fetching external sources' do UI.section 'Fetching external sources' do
deps_to_fetch.uniq.sort.each do |dependency| deps_to_fetch.uniq(&:root_name).sort.each do |dependency|
source = ExternalSources.from_dependency(dependency, podfile.defined_in_file) source = ExternalSources.from_dependency(dependency, podfile.defined_in_file)
source.fetch(sandbox) source.fetch(sandbox)
end end
...@@ -310,6 +315,13 @@ module Pod ...@@ -310,6 +315,13 @@ module Pod
# grouped by target. # grouped by target.
# #
def resolve_dependencies def resolve_dependencies
duplicate_dependencies = podfile.dependencies.group_by(&:name).
select { |_name, dependencies| dependencies.count > 1 }
duplicate_dependencies.each do |name, dependencies|
UI.warn "There are duplicate dependencies on `#{name}` in #{UI.path podfile.defined_in_file}:\n\n" \
"- #{dependencies.map(&:to_s).join("\n- ")}"
end
specs_by_target = nil specs_by_target = nil
UI.section "Resolving dependencies of #{UI.path podfile.defined_in_file}" do UI.section "Resolving dependencies of #{UI.path podfile.defined_in_file}" do
resolver = Resolver.new(sandbox, podfile, locked_dependencies, sources) resolver = Resolver.new(sandbox, podfile, locked_dependencies, sources)
......
...@@ -173,6 +173,69 @@ module Pod ...@@ -173,6 +173,69 @@ module Pod
@analyzer.send(:fetch_external_sources) @analyzer.send(:fetch_external_sources)
end end
it 'does not download the same source multiple times for different subspecs' do
podfile_state = Installer::Analyzer::SpecsState.new
podfile_state.added << 'ARAnalytics/Mixpanel' << 'ARAnalytics/HockeyApp'
@analyzer.stubs(:result).returns(stub(:podfile_state => podfile_state))
@podfile.stubs(:dependencies).returns([
Dependency.new('ARAnalytics/Mixpanel', :git => 'https://github.com/orta/ARAnalytics', :commit => '6f1a1c314894437e7e5c09572c276e644dbfb64b'),
Dependency.new('ARAnalytics/HockeyApp', :git => 'https://github.com/orta/ARAnalytics', :commit => '6f1a1c314894437e7e5c09572c276e644dbfb64b'),
])
ExternalSources::DownloaderSource.any_instance.expects(:fetch).once
@analyzer.send(:fetch_external_sources)
end
it 'raises when dependencies with the same name have different ' \
'external sources' do
podfile = Podfile.new do
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'SampleProject/SampleProject'
platform :ios
pod 'SEGModules', :git => 'https://github.com/segiddins/SEGModules.git'
pod 'SEGModules', :git => 'https://github.com/segiddins/Modules.git'
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile, nil)
e = should.raise(Informative) { analyzer.analyze }
e.message.should.match /different sources for `SEGModules`/
e.message.should.match %r{SEGModules \(from `https://github.com/segiddins/SEGModules.git`\)}
e.message.should.match %r{SEGModules \(from `https://github.com/segiddins/Modules.git`\)}
end
it 'raises when dependencies with the same root name have different ' \
'external sources' do
podfile = Podfile.new do
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'SampleProject/SampleProject'
platform :ios
pod 'RestKit/Core', :git => 'https://github.com/RestKit/RestKit.git'
pod 'RestKit', :git => 'https://github.com/segiddins/RestKit.git'
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile, nil)
e = should.raise(Informative) { analyzer.analyze }
e.message.should.match /different sources for `RestKit`/
e.message.should.match %r{RestKit/Core \(from `https://github.com/RestKit/RestKit.git`\)}
e.message.should.match %r{RestKit \(from `https://github.com/segiddins/RestKit.git`\)}
end
it 'raises when dependencies with the same name have different ' \
'external sources with one being nil' do
podfile = Podfile.new do
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'SampleProject/SampleProject'
platform :ios
pod 'RestKit', :git => 'https://github.com/RestKit/RestKit.git'
pod 'RestKit', '~> 0.23.0'
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile, nil)
e = should.raise(Informative) { analyzer.analyze }
e.message.should.match /different sources for `RestKit`/
e.message.should.match %r{RestKit \(from `https://github.com/RestKit/RestKit.git`\)}
e.message.should.match %r{RestKit \(~> 0.23.0\)}
end
xit 'it fetches the specification from either the sandbox or from the remote be default' do xit 'it fetches the specification from either the sandbox or from the remote be default' do
dependency = Dependency.new('Name', :git => 'www.example.com') dependency = Dependency.new('Name', :git => 'www.example.com')
ExternalSources::DownloaderSource.any_instance.expects(:specification_from_external).returns(Specification.new).once ExternalSources::DownloaderSource.any_instance.expects(:specification_from_external).returns(Specification.new).once
...@@ -224,6 +287,24 @@ module Pod ...@@ -224,6 +287,24 @@ module Pod
#--------------------------------------# #--------------------------------------#
it 'warns when a dependency is duplicated' do
podfile = Podfile.new do
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'SampleProject/SampleProject'
platform :ios, '8.0'
pod 'RestKit', '~> 0.23.0'
pod 'RestKit', '<= 0.23.2'
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile, nil)
analyzer.analyze
UI.warnings.should.match /duplicate dependencies on `RestKit`/
UI.warnings.should.match %r{RestKit \(~> 0.23.0\)}
UI.warnings.should.match %r{RestKit \(<= 0.23.2\)}
end
#--------------------------------------#
it 'computes the state of the Sandbox respect to the resolved dependencies' do it 'computes the state of the Sandbox respect to the resolved dependencies' do
@analyzer.stubs(:lockfile).returns(nil) @analyzer.stubs(:lockfile).returns(nil)
state = @analyzer.analyze.sandbox_state state = @analyzer.analyze.sandbox_state
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment