Commit 6d3821be authored by Fabio Pelosin's avatar Fabio Pelosin

[Resolver] Use the given sources

parent d5cb0bbd
...@@ -165,21 +165,10 @@ module Pod ...@@ -165,21 +165,10 @@ module Pod
# Updates the source repositories unless the config indicates to skip it. # Updates the source repositories unless the config indicates to skip it.
# #
# @return [void]
#
def update_repositories_if_needed def update_repositories_if_needed
unless config.skip_repo_update? unless config.skip_repo_update?
sources = SourcesManager.podfile_sources UI.section 'Updating spec repositories' do
if sources.empty? SourcesManager.update
UI.section 'Updating spec repositories' do
SourcesManager.update
end
else
sources.each do |source|
UI.section "Updating spec repository #{source}" do
SourcesManager.update(source)
end
end
end end
end end
end end
...@@ -328,7 +317,13 @@ module Pod ...@@ -328,7 +317,13 @@ module Pod
def resolve_dependencies def resolve_dependencies
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) if podfile.sources.empty?
sources = SourcesManager.master
else
sources = SourcesManager.sources(podfile.sources)
end
resolver = Resolver.new(sandbox, podfile, locked_dependencies, sources)
specs_by_target = resolver.resolve specs_by_target = resolver.resolve
end end
specs_by_target specs_by_target
......
...@@ -28,14 +28,21 @@ module Pod ...@@ -28,14 +28,21 @@ module Pod
# #
attr_reader :locked_dependencies attr_reader :locked_dependencies
# @return [Array<Source>] The list of the sources which will be used for
# the resolution.
#
attr_accessor :sources
# @param [Sandbox] sandbox @see sandbox # @param [Sandbox] sandbox @see sandbox
# @param [Podfile] podfile @see podfile # @param [Podfile] podfile @see podfile
# @param [Array<Dependency>] locked_dependencies @see locked_dependencies # @param [Array<Dependency>] locked_dependencies @see locked_dependencies
# @param [Array<Source>, Source] sources @see sources
# #
def initialize(sandbox, podfile, locked_dependencies = []) def initialize(sandbox, podfile, locked_deps, sources)
@sandbox = sandbox @sandbox = sandbox
@podfile = podfile @podfile = podfile
@locked_dependencies = locked_dependencies @locked_dependencies = locked_deps
@sources = Array(sources)
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -51,14 +58,15 @@ module Pod ...@@ -51,14 +58,15 @@ module Pod
# definition. # definition.
# #
def resolve def resolve
@cached_sources = SourcesManager.aggregate(true)
@cached_sets = {} @cached_sets = {}
@cached_specs = {} @cached_specs = {}
@specs_by_target = {} @specs_by_target = {}
target_definitions = podfile.target_definition_list target_definitions = podfile.target_definition_list
target_definitions.each do |target| target_definitions.each do |target|
UI.section "Resolving dependencies for target `#{target.name}' (#{target.platform})" do title = "Resolving dependencies for target `#{target.name}' " \
"(#{target.platform})"
UI.section(title) do
@loaded_specs = [] @loaded_specs = []
find_dependency_specs(podfile, target.dependencies, target) find_dependency_specs(podfile, target.dependencies, target)
specs = cached_specs.values_at(*@loaded_specs).sort_by(&:name) specs = cached_specs.values_at(*@loaded_specs).sort_by(&:name)
...@@ -83,14 +91,6 @@ module Pod ...@@ -83,14 +91,6 @@ module Pod
# !@ Resolution context # !@ Resolution context
# @return [Source::Aggregate] A cache of the sources needed to find the
# podspecs.
#
# @note The sources are cached because frequently accessed by the
# resolver and loading them requires disk activity.
#
attr_accessor :cached_sources
# @return [Hash<String => Set>] A cache that keeps tracks of the sets # @return [Hash<String => Set>] A cache that keeps tracks of the sets
# loaded by the resolution process. # loaded by the resolution process.
# #
...@@ -168,13 +168,11 @@ module Pod ...@@ -168,13 +168,11 @@ module Pod
end end
end end
# Loads or returns a previously initialized for the Pod of the given # @return [Set] Loads or returns a previously initialized set for the Pod
# dependency. # of the given dependency.
# #
# @param [Dependency] dependency # @param [Dependency] dependency
# the dependency for which the set is needed. # The dependency for which the set is needed.
#
# @return [Set] the cached set for a given dependency.
# #
def find_cached_set(dependency) def find_cached_set(dependency)
name = dependency.root_name name = dependency.root_name
...@@ -182,24 +180,41 @@ module Pod ...@@ -182,24 +180,41 @@ module Pod
if dependency.external_source if dependency.external_source
spec = sandbox.specification(dependency.root_name) spec = sandbox.specification(dependency.root_name)
unless spec unless spec
raise StandardError, "[Bug] Unable to find the specification for `#{dependency}`." raise StandardError, "[Bug] Unable to find the specification " \
"for `#{dependency}`."
end end
set = Specification::Set::External.new(spec) set = Specification::Set::External.new(spec)
else else
set = cached_sources.search(dependency) set = find_set_from_sources(dependency)
end end
cached_sets[name] = set cached_sets[name] = set
unless set unless set
raise Informative, "Unable to find a specification for `#{dependency}`." raise Informative, "Unable to find a specification " \
"for `#{dependency}`."
end end
end end
cached_sets[name] cached_sets[name]
end end
# @return [Set] Loads a set for the Pod of the given dependency from the
# sources. The set will be limited to the versions of the first
# source which includes the Pod.
#
# @param [Dependency] dependency
# The dependency for which the set is needed.
#
def find_set_from_sources(dependency)
source = sources.find { |s| s.search(dependency) }
source.search(dependency)
end
# Ensures that a specification is compatible with the platform of a target. # Ensures that a specification is compatible with the platform of a target.
# #
# @raise If the specification is not supported by the target. # @raise If the specification is not supported by the target.
# #
# @todo This step is not specific to the resolution process and should be
# performed later in the analysis.
#
# @return [void] # @return [void]
# #
def validate_platform(spec, target) def validate_platform(spec, target)
......
...@@ -5,37 +5,44 @@ module Pod ...@@ -5,37 +5,44 @@ module Pod
class << self class << self
include Config::Mixin include Config::Mixin
# @return [Source::Aggregate] The aggregate of the sources with the given
# @return [Array<Source>] the sources listed by the current Podfile. # Pods.
#
# @param [Array<#to_s>] source_names
# The names of the sources. If not given all the sources will be
# returned.
# #
def podfile_sources def aggregate(source_names = nil)
sources = [] if source_names
self.podfile_repos_dirs.each do |repo| dirs = source_names.map { |name| source_dir(name) }
sources << Source.new(repo) else
dirs = config.repos_dir.children.select(&:directory?)
end end
sources << Source.new(master_repo_dir) if sources.empty? Source::Aggregate.new(dirs)
sources
end end
# @param [Bool] podfile use podfile sources # @return [Array<Source>] The list of the sources with the given names.
# #
# @return [Source::Aggregate] the aggregate of all the sources known to # @param [Array<#to_s>] names
# this installation of CocoaPods. # The names of the sources.
# #
def aggregate(podfile = false) def sources(names)
if podfile dirs = names.map { |name| source_dir(name) }
repos = podfile_repos_dirs dirs.map { |repo| Source.new(repo) }
else
repos = config.repos_dir.children.select(&:directory?)
end
Source::Aggregate.new(repos)
end end
# @return [Array<Source>] the list of all the sources known to this # @return [Array<Source>] The list of all the sources known to this
# installation of CocoaPods. # installation of CocoaPods.
# #
def all def all
aggregate.sources dirs = config.repos_dir.children.select(&:directory?)
dirs.map { |repo| Source.new(repo) }
end
# @return [Source] The CocoaPods Master Repo source.
#
def master
sources(['master'])
end end
# @return [Array<Specification::Set>] the list of all the specification # @return [Array<Specification::Set>] the list of all the specification
...@@ -347,23 +354,18 @@ module Pod ...@@ -347,23 +354,18 @@ module Pod
end end
end end
# @return [Array<Pathname>] directories of all specified sources in # @return [Pathname] The path of the source with the given name.
# Podfile
# #
def podfile_repos_dirs # @param [String] name
pathnames = [] # The name of the source.
if config.podfile
config.podfile.sources.each do |source_name|
pathnames << source_repo_dir(source_name)
end
end
pathnames
end
# @return [Pathname] the directory where a given CocoaPods source is stored.
# #
def source_repo_dir(name) def source_dir(name)
config.repos_dir + name dir = config.repos_dir + name
if dir
dir
else
raise Informative, "Unable to find the `#{name}` repo."
end
end end
end end
end end
......
...@@ -464,33 +464,6 @@ module Pod ...@@ -464,33 +464,6 @@ module Pod
e = lambda { @analyzer.send(:compute_platform_for_target_definition, target_definition, user_targets) }.should.raise Informative e = lambda { @analyzer.send(:compute_platform_for_target_definition, target_definition, user_targets) }.should.raise Informative
e.message.should.match /Targets with different platforms/ e.message.should.match /Targets with different platforms/
end end
end
#--------------------------------------#
describe "#update_repositories_if_needed" do
it "updates the podfile repositories" do
config.skip_repo_update = false
def @podfile.sources
["netbe", "master"]
end
SourcesManager.expects(:update).with("netbe").once
SourcesManager.expects(:update).with("master").once
@analyzer.send(:update_repositories_if_needed)
end
it "updates the default repositories" do
config.skip_repo_update = false
def @podfile.sources
[]
end
SourcesManager.expects(:update).once
@analyzer.send(:update_repositories_if_needed)
end
end end
end end
end end
......
...@@ -9,7 +9,7 @@ module Pod ...@@ -9,7 +9,7 @@ module Pod
pod 'BlocksKit', '1.5.2' pod 'BlocksKit', '1.5.2'
end end
locked_deps = [Dependency.new('BlocksKit', '1.5.2')] locked_deps = [Dependency.new('BlocksKit', '1.5.2')]
@resolver = Resolver.new(config.sandbox, @podfile, locked_deps) @resolver = Resolver.new(config.sandbox, @podfile, locked_deps, SourcesManager.all)
end end
it 'returns the sandbox' do it 'returns the sandbox' do
...@@ -55,7 +55,7 @@ module Pod ...@@ -55,7 +55,7 @@ module Pod
platform :ios platform :ios
pod 'Reachability', :podspec => podspec pod 'Reachability', :podspec => podspec
end end
resolver = Resolver.new(config.sandbox, podfile) resolver = Resolver.new(config.sandbox, podfile, [], SourcesManager.all)
resolver.resolve resolver.resolve
specs = resolver.specs_by_target.values.flatten specs = resolver.specs_by_target.values.flatten
specs.map(&:to_s).should == ['Reachability (3.0.0)'] specs.map(&:to_s).should == ['Reachability (3.0.0)']
...@@ -70,7 +70,7 @@ module Pod ...@@ -70,7 +70,7 @@ module Pod
platform :ios, '6.0' platform :ios, '6.0'
pod 'BlocksKit', '1.5.2' pod 'BlocksKit', '1.5.2'
end end
@resolver = Resolver.new(config.sandbox, @podfile) @resolver = Resolver.new(config.sandbox, @podfile, [], SourcesManager.all)
end end
it 'cross resolves dependencies' do it 'cross resolves dependencies' do
...@@ -80,7 +80,7 @@ module Pod ...@@ -80,7 +80,7 @@ module Pod
pod 'AFQuickLookView', '= 0.1.0' # requires 'AFNetworking', '>= 0.9.0' pod 'AFQuickLookView', '= 0.1.0' # requires 'AFNetworking', '>= 0.9.0'
end end
resolver = Resolver.new(config.sandbox, @podfile) resolver = Resolver.new(config.sandbox, @podfile, [], SourcesManager.all)
specs = resolver.resolve.values.flatten.map(&:to_s).sort specs = resolver.resolve.values.flatten.map(&:to_s).sort
specs.should == ['AFNetworking (0.9.1)', 'AFQuickLookView (0.1.0)'] specs.should == ['AFNetworking (0.9.1)', 'AFQuickLookView (0.1.0)']
end end
...@@ -110,7 +110,7 @@ module Pod ...@@ -110,7 +110,7 @@ module Pod
platform :ios, '7.0' platform :ios, '7.0'
pod 'RestKit', '0.10.3' pod 'RestKit', '0.10.3'
end end
resolver = Resolver.new(config.sandbox, @podfile) resolver = Resolver.new(config.sandbox, @podfile, [], SourcesManager.all)
resolver.resolve.values.flatten.map(&:name).sort.should == %w( resolver.resolve.values.flatten.map(&:name).sort.should == %w(
FileMD5Hash FileMD5Hash
ISO8601DateFormatter ISO8601DateFormatter
...@@ -149,9 +149,11 @@ module Pod ...@@ -149,9 +149,11 @@ module Pod
end end
end end
config.sandbox.expects(:specification).with('MainSpec').returns(spec) config.sandbox.expects(:specification).with('MainSpec').returns(spec)
resolver = Resolver.new(config.sandbox, @podfile) resolver = Resolver.new(config.sandbox, @podfile, [], SourcesManager.all)
specs = resolver.resolve.values.flatten.map(&:name).sort specs = resolver.resolve.values.flatten.map(&:name).sort
specs.should == %w( MainSpec/FirstSubSpec MainSpec/FirstSubSpec/SecondSubSpec ) specs.should == %w(
MainSpec/FirstSubSpec MainSpec/FirstSubSpec/SecondSubSpec
)
end end
it "marks a specification's version to be a HEAD version" do it "marks a specification's version to be a HEAD version" do
...@@ -160,7 +162,7 @@ module Pod ...@@ -160,7 +162,7 @@ module Pod
pod 'FileMD5Hash' pod 'FileMD5Hash'
pod 'JSONKit', :head pod 'JSONKit', :head
end end
resolver = Resolver.new(config.sandbox, podfile) resolver = Resolver.new(config.sandbox, podfile, [], SourcesManager.all)
filemd5hash, jsonkit = resolver.resolve.values.first.sort_by(&:name) filemd5hash, jsonkit = resolver.resolve.values.first.sort_by(&:name)
filemd5hash.version.should.not.be.head filemd5hash.version.should.not.be.head
jsonkit.version.should.be.head jsonkit.version.should.be.head
...@@ -174,7 +176,7 @@ module Pod ...@@ -174,7 +176,7 @@ module Pod
pod 'JSONKit', '1.4' pod 'JSONKit', '1.4'
pod 'JSONKit', '1.5pre' pod 'JSONKit', '1.5pre'
end end
resolver = Resolver.new(config.sandbox, podfile) resolver = Resolver.new(config.sandbox, podfile, [], SourcesManager.all)
e = lambda { resolver.resolve }.should.raise Pod::Informative e = lambda { resolver.resolve }.should.raise Pod::Informative
e.message.should.match(/Unable to satisfy the following requirements/) e.message.should.match(/Unable to satisfy the following requirements/)
end end
...@@ -184,15 +186,31 @@ module Pod ...@@ -184,15 +186,31 @@ module Pod
platform :ios platform :ios
pod 'JSONKit', '<= 1.5pre' pod 'JSONKit', '<= 1.5pre'
end end
resolver = Resolver.new(config.sandbox, podfile) resolver = Resolver.new(config.sandbox, podfile, [], SourcesManager.all)
version = resolver.resolve.values.flatten.first.version version = resolver.resolve.values.flatten.first.version
version.to_s.should == '1.5pre' version.to_s.should == '1.5pre'
locked_deps = [Dependency.new('JSONKit', '= 1.4')] locked_deps = [Dependency.new('JSONKit', '= 1.4')]
resolver = Resolver.new(config.sandbox, podfile, locked_deps) resolver = Resolver.new(config.sandbox, podfile, locked_deps, SourcesManager.all)
version = resolver.resolve.values.flatten.first.version version = resolver.resolve.values.flatten.first.version
version.to_s.should == '1.4' version.to_s.should == '1.4'
end end
it 'takes into account the order of the sources' do
podfile = Podfile.new do
platform :ios
pod 'JSONKit'
end
sources = SourcesManager.sources(['master', 'test_repo'])
resolver = Resolver.new(config.sandbox, podfile, [], sources)
version = resolver.resolve.values.flatten.first.version
version.to_s.should.not == "999.999.999"
sources = SourcesManager.sources(['test_repo', 'master'])
resolver = Resolver.new(config.sandbox, podfile, [], sources)
version = resolver.resolve.values.flatten.first.version
version.to_s.should == "999.999.999"
end
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -205,7 +223,7 @@ module Pod ...@@ -205,7 +223,7 @@ module Pod
pod 'AFNetworking', '1.0RC3' pod 'AFNetworking', '1.0RC3'
end end
resolver = Resolver.new(config.sandbox, @podfile) resolver = Resolver.new(config.sandbox, @podfile, [], SourcesManager.all)
specs = resolver.resolve.values.flatten.map(&:to_s).sort specs = resolver.resolve.values.flatten.map(&:to_s).sort
specs.should == ['AFNetworking (1.0RC3)'] specs.should == ['AFNetworking (1.0RC3)']
end end
...@@ -216,7 +234,7 @@ module Pod ...@@ -216,7 +234,7 @@ module Pod
pod 'AFNetworking', '~> 1.0RC3' pod 'AFNetworking', '~> 1.0RC3'
end end
resolver = Resolver.new(config.sandbox, @podfile) resolver = Resolver.new(config.sandbox, @podfile, [], SourcesManager.all)
specs = resolver.resolve.values.flatten.map(&:to_s).sort specs = resolver.resolve.values.flatten.map(&:to_s).sort
specs.should != ['AFNetworking (1.0RC3)'] specs.should != ['AFNetworking (1.0RC3)']
specs.should == ['AFNetworking (1.2.0)'] specs.should == ['AFNetworking (1.2.0)']
...@@ -228,7 +246,7 @@ module Pod ...@@ -228,7 +246,7 @@ module Pod
pod 'AFNetworking', '1.0' pod 'AFNetworking', '1.0'
end end
resolver = Resolver.new(config.sandbox, @podfile) resolver = Resolver.new(config.sandbox, @podfile, [], SourcesManager.all)
specs = resolver.resolve.values.flatten.map(&:to_s).sort specs = resolver.resolve.values.flatten.map(&:to_s).sort
specs.should != ['AFNetworking (1.0RC3)'] specs.should != ['AFNetworking (1.0RC3)']
specs.should == ['AFNetworking (1.0)'] specs.should == ['AFNetworking (1.0)']
...@@ -240,7 +258,7 @@ module Pod ...@@ -240,7 +258,7 @@ module Pod
pod 'AFNetworking', '< 1.0' pod 'AFNetworking', '< 1.0'
end end
resolver = Resolver.new(config.sandbox, @podfile) resolver = Resolver.new(config.sandbox, @podfile, [], SourcesManager.all)
specs = resolver.resolve.values.flatten.map(&:to_s).sort specs = resolver.resolve.values.flatten.map(&:to_s).sort
specs.should != ['AFNetworking (1.0RC3)'] specs.should != ['AFNetworking (1.0RC3)']
specs.should == ['AFNetworking (0.10.1)'] specs.should == ['AFNetworking (0.10.1)']
...@@ -252,7 +270,7 @@ module Pod ...@@ -252,7 +270,7 @@ module Pod
pod 'AFNetworking', '<= 1.0' pod 'AFNetworking', '<= 1.0'
end end
resolver = Resolver.new(config.sandbox, @podfile) resolver = Resolver.new(config.sandbox, @podfile, [], SourcesManager.all)
specs = resolver.resolve.values.flatten.map(&:to_s).sort specs = resolver.resolve.values.flatten.map(&:to_s).sort
specs.should != ['AFNetworking (1.0RC3)'] specs.should != ['AFNetworking (1.0RC3)']
specs.should == ['AFNetworking (1.0)'] specs.should == ['AFNetworking (1.0)']
...@@ -264,7 +282,7 @@ module Pod ...@@ -264,7 +282,7 @@ module Pod
pod 'AFNetworking', '> 1.0', '< 1.3' pod 'AFNetworking', '> 1.0', '< 1.3'
end end
resolver = Resolver.new(config.sandbox, @podfile) resolver = Resolver.new(config.sandbox, @podfile, [], SourcesManager.all)
specs = resolver.resolve.values.flatten.map(&:to_s).sort specs = resolver.resolve.values.flatten.map(&:to_s).sort
specs.should != ['AFNetworking (1.0RC3)'] specs.should != ['AFNetworking (1.0RC3)']
specs.should == ['AFNetworking (1.2.1)'] specs.should == ['AFNetworking (1.2.1)']
...@@ -276,7 +294,7 @@ module Pod ...@@ -276,7 +294,7 @@ module Pod
pod 'AFNetworking', '>= 1.0', '< 1.3' pod 'AFNetworking', '>= 1.0', '< 1.3'
end end
resolver = Resolver.new(config.sandbox, @podfile) resolver = Resolver.new(config.sandbox, @podfile, [], SourcesManager.all)
specs = resolver.resolve.values.flatten.map(&:to_s).sort specs = resolver.resolve.values.flatten.map(&:to_s).sort
specs.should != ['AFNetworking (1.0RC3)'] specs.should != ['AFNetworking (1.0RC3)']
specs.should == ['AFNetworking (1.2.1)'] specs.should == ['AFNetworking (1.2.1)']
...@@ -288,7 +306,7 @@ module Pod ...@@ -288,7 +306,7 @@ module Pod
pod 'AFNetworking', '~> 1.0', '< 1.3' pod 'AFNetworking', '~> 1.0', '< 1.3'
end end
resolver = Resolver.new(config.sandbox, @podfile) resolver = Resolver.new(config.sandbox, @podfile, [], SourcesManager.all)
specs = resolver.resolve.values.flatten.map(&:to_s).sort specs = resolver.resolve.values.flatten.map(&:to_s).sort
specs.should != ['AFNetworking (1.0RC3)'] specs.should != ['AFNetworking (1.0RC3)']
specs.should == ['AFNetworking (1.2.1)'] specs.should == ['AFNetworking (1.2.1)']
......
...@@ -105,22 +105,6 @@ module Pod ...@@ -105,22 +105,6 @@ module Pod
path = SourcesManager.search_index_path.to_s path = SourcesManager.search_index_path.to_s
path.should.match %r[Library/Caches/CocoaPods/search_index.yaml] path.should.match %r[Library/Caches/CocoaPods/search_index.yaml]
end end
it "returns the sources from podfile" do
@podfile = Podfile.new do
platform :ios
source 'netbe'
source 'cocoapods'
end
SourcesManager.config.stubs(:podfile).returns(@podfile)
sources = SourcesManager.podfile_sources
sources.map(&:name).should == %w[netbe cocoapods]
end
it "returns cocoapods source if none specified" do
sources = SourcesManager.podfile_sources
sources.map(&:name).should == %w[master]
end
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
......
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