Class: Pod::Resolver
- Inherits:
-
Object
- Object
- Pod::Resolver
- Includes:
- Molinillo::SpecificationProvider, Molinillo::UI, Installer::InstallationOptions::Mixin
- Defined in:
- lib/cocoapods/resolver.rb
Overview
The resolver is responsible of generating a list of specifications grouped by target for a given Podfile.
Defined Under Namespace
Classes: ResolverSpecification
Instance Attribute Summary collapse
-
#locked_dependencies ⇒ Array<Dependency>
readonly
The list of dependencies locked to a specific version.
-
#podfile ⇒ Podfile
readonly
The Podfile used by the resolver.
-
#sandbox ⇒ Sandbox
readonly
The Sandbox used by the resolver to find external dependencies.
-
#sources ⇒ Array<Source>
readonly
The list of the sources which will be used for the resolution.
-
#specs_updated ⇒ Bool
(also: #specs_updated?)
readonly
Whether the resolver has sources repositories up-to-date.
Attributes included from Installer::InstallationOptions::Mixin
Resolution collapse
-
#after_resolution ⇒ Void
Called after resolution ends.
-
#before_resolution ⇒ Void
Called before resolution starts.
-
#dependencies_for(specification) ⇒ Array<Specification>
Returns the dependencies of ‘specification`.
-
#indicate_progress ⇒ Void
Called during resolution to indicate progress.
-
#name_for(dependency) ⇒ String
Returns the name for the given ‘dependency`.
-
#name_for_explicit_dependency_source ⇒ String
The user-facing name for a Podfile.
-
#name_for_locking_dependency_source ⇒ String
The user-facing name for a Lockfile.
-
#output ⇒ UserInterface
The UI object the resolver should use for displaying user-facing output.
-
#requirement_satisfied_by?(requirement, activated, spec) ⇒ Boolean
Determines whether the given ‘requirement` is satisfied by the given `spec`, in the context of the current `activated` dependency graph.
-
#resolve ⇒ Hash{TargetDefinition => Array<ResolverSpecification>}
Identifies the specifications that should be installed.
-
#resolver_specs_by_target ⇒ Hash{Podfile::TargetDefinition => Array<ResolverSpecification>}
Returns the resolved specifications grouped by target.
-
#search_for(dependency) ⇒ Array<Specification>
Returns (and caches) the specification that satisfy the given dependency.
-
#sort_dependencies(dependencies, activated, conflicts) ⇒ Array<Dependency>
Sort dependencies so that the ones that are easiest to resolve are first.
Instance Method Summary collapse
-
#initialize(sandbox, podfile, locked_dependencies, sources, specs_updated, podfile_dependency_cache: Installer::Analyzer::PodfileDependencyCache.from_podfile(podfile)) ⇒ Resolver
constructor
Init a new Resolver.
Methods included from Installer::InstallationOptions::Mixin
Constructor Details
#initialize(sandbox, podfile, locked_dependencies, sources, specs_updated, podfile_dependency_cache: Installer::Analyzer::PodfileDependencyCache.from_podfile(podfile)) ⇒ Resolver
Init a new Resolver
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cocoapods/resolver.rb', line 91 def initialize(sandbox, podfile, locked_dependencies, sources, specs_updated, podfile_dependency_cache: Installer::Analyzer::PodfileDependencyCache.from_podfile(podfile)) @sandbox = sandbox @podfile = podfile @locked_dependencies = locked_dependencies @sources = Array(sources) @specs_updated = specs_updated @podfile_dependency_cache = podfile_dependency_cache @platforms_by_dependency = Hash.new { |h, k| h[k] = [] } @cached_sets = {} end |
Instance Attribute Details
#locked_dependencies ⇒ Array<Dependency> (readonly)
Returns the list of dependencies locked to a specific version.
69 70 71 |
# File 'lib/cocoapods/resolver.rb', line 69 def locked_dependencies @locked_dependencies end |
#podfile ⇒ Podfile (readonly)
Returns the Podfile used by the resolver.
64 65 66 |
# File 'lib/cocoapods/resolver.rb', line 64 def podfile @podfile end |
#sandbox ⇒ Sandbox (readonly)
Returns the Sandbox used by the resolver to find external dependencies.
60 61 62 |
# File 'lib/cocoapods/resolver.rb', line 60 def sandbox @sandbox end |
#sources ⇒ Array<Source> (readonly)
Returns The list of the sources which will be used for the resolution.
74 75 76 |
# File 'lib/cocoapods/resolver.rb', line 74 def sources @sources end |
#specs_updated ⇒ Bool (readonly) Also known as: specs_updated?
Returns Whether the resolver has sources repositories up-to-date.
78 79 80 |
# File 'lib/cocoapods/resolver.rb', line 78 def specs_updated @specs_updated end |
Instance Method Details
#after_resolution ⇒ Void
Called after resolution ends.
Completely silence this, as we show nothing.
319 320 |
# File 'lib/cocoapods/resolver.rb', line 319 def after_resolution end |
#before_resolution ⇒ Void
Called before resolution starts.
Completely silence this, as we show nothing.
310 311 |
# File 'lib/cocoapods/resolver.rb', line 310 def before_resolution end |
#dependencies_for(specification) ⇒ Array<Specification>
Returns the dependencies of ‘specification`.
186 187 188 189 190 191 192 193 194 |
# File 'lib/cocoapods/resolver.rb', line 186 def dependencies_for(specification) specification.all_dependencies.map do |dependency| if dependency.root_name == Specification.root_name(specification.name) dependency.dup.tap { |d| d.specific_version = specification.version } else dependency end end end |
#indicate_progress ⇒ Void
Called during resolution to indicate progress.
Completely silence this, as we show nothing.
328 329 |
# File 'lib/cocoapods/resolver.rb', line 328 def indicate_progress end |
#name_for(dependency) ⇒ String
Returns the name for the given ‘dependency`.
203 204 205 |
# File 'lib/cocoapods/resolver.rb', line 203 def name_for(dependency) dependency.name end |
#name_for_explicit_dependency_source ⇒ String
Returns the user-facing name for a Podfile.
209 210 211 |
# File 'lib/cocoapods/resolver.rb', line 209 def name_for_explicit_dependency_source 'Podfile' end |
#name_for_locking_dependency_source ⇒ String
Returns the user-facing name for a Lockfile.
215 216 217 |
# File 'lib/cocoapods/resolver.rb', line 215 def name_for_locking_dependency_source 'Podfile.lock' end |
#output ⇒ UserInterface
The UI object the resolver should use for displaying user-facing output.
300 301 302 |
# File 'lib/cocoapods/resolver.rb', line 300 def output UI end |
#requirement_satisfied_by?(requirement, activated, spec) ⇒ Boolean
Determines whether the given ‘requirement` is satisfied by the given `spec`, in the context of the current `activated` dependency graph.
232 233 234 235 236 237 238 |
# File 'lib/cocoapods/resolver.rb', line 232 def requirement_satisfied_by?(requirement, activated, spec) version = spec.version return false unless requirement.requirement.satisfied_by?(version) return false unless valid_possibility_version_for_root_name?(requirement, activated, spec) return false unless spec_is_platform_compatible?(activated, requirement, spec) true end |
#resolve ⇒ Hash{TargetDefinition => Array<ResolverSpecification>}
Identifies the specifications that should be installed.
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/cocoapods/resolver.rb', line 115 def resolve dependencies = @podfile_dependency_cache.target_definition_list.flat_map do |target| @podfile_dependency_cache.target_definition_dependencies(target).each do |dep| next unless target.platform @platforms_by_dependency[dep].push(target.platform) end end @platforms_by_dependency.each_value(&:uniq!) @activated = Molinillo::Resolver.new(self, self).resolve(dependencies, locked_dependencies) resolver_specs_by_target rescue Molinillo::ResolverError => e handle_resolver_error(e) end |
#resolver_specs_by_target ⇒ Hash{Podfile::TargetDefinition => Array<ResolverSpecification>}
The returned specifications can be subspecs.
Returns the resolved specifications grouped by target.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/cocoapods/resolver.rb', line 134 def resolver_specs_by_target @resolver_specs_by_target ||= {}.tap do |resolver_specs_by_target| @podfile_dependency_cache.target_definition_list.each do |target| # can't use vertex.root? since that considers _all_ targets explicit_dependencies = @podfile_dependency_cache.target_definition_dependencies(target).map(&:name).to_set vertices = valid_dependencies_for_target(target) resolver_specs_by_target[target] = vertices. map do |vertex| payload = vertex.payload test_only = (!explicit_dependencies.include?(vertex.name) || payload.test_specification?) && (vertex.recursive_predecessors & vertices).all? { |v| !explicit_dependencies.include?(v.name) || v.payload.test_specification? } spec_source = payload.respond_to?(:spec_source) && payload.spec_source ResolverSpecification.new(payload, test_only, spec_source) end. sort_by(&:name) end end end |
#search_for(dependency) ⇒ Array<Specification>
Returns (and caches) the specification that satisfy the given dependency.
169 170 171 172 173 174 175 176 177 |
# File 'lib/cocoapods/resolver.rb', line 169 def search_for(dependency) @search ||= {} @search[dependency] ||= begin locked_requirement = requirement_for_locked_pod_named(dependency.name) additional_requirements = Array(locked_requirement) specifications_for_dependency(dependency, additional_requirements) end @search[dependency].dup end |
#sort_dependencies(dependencies, activated, conflicts) ⇒ Array<Dependency>
Sort dependencies so that the ones that are easiest to resolve are first. Easiest to resolve is (usually) defined by:
1) Is this dependency already activated?
2) How relaxed are the requirements?
3) Are there any conflicts for this dependency?
4) How many possibilities are there to satisfy this dependency?
275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/cocoapods/resolver.rb', line 275 def sort_dependencies(dependencies, activated, conflicts) dependencies.sort_by do |dependency| name = name_for(dependency) [ activated.vertex_named(name).payload ? 0 : 1, dependency.external_source ? 0 : 1, dependency.prerelease? ? 0 : 1, conflicts[name] ? 0 : 1, search_for(dependency).count, ] end end |