Commit 51dc5970 authored by Samuel E. Giddins's avatar Samuel E. Giddins

[Analyzer][LockingDependencyAnalyzer] Use new LockingDependencyAnalyzer to…

[Analyzer][LockingDependencyAnalyzer] Use new LockingDependencyAnalyzer to generate_version_locking_dependencies
parent 0e0f829e
...@@ -8,6 +8,8 @@ module Pod ...@@ -8,6 +8,8 @@ module Pod
autoload :SandboxAnalyzer, 'cocoapods/installer/analyzer/sandbox_analyzer' autoload :SandboxAnalyzer, 'cocoapods/installer/analyzer/sandbox_analyzer'
autoload :LockingDependencyAnalyzer, 'cocoapods/installer/analyzer/locking_dependency_analyzer'
# @return [Sandbox] The sandbox where the Pods should be installed. # @return [Sandbox] The sandbox where the Pods should be installed.
# #
attr_reader :sandbox attr_reader :sandbox
...@@ -232,45 +234,13 @@ module Pod ...@@ -232,45 +234,13 @@ module Pod
# a Pod. # a Pod.
# #
def generate_version_locking_dependencies def generate_version_locking_dependencies
require 'molinillo/dependency_graph' if update_mode == :all || !lockfile
dependency_graph = Molinillo::DependencyGraph.new LockingDependencyAnalyzer.unlocked_dependency_graph
else
unless update_mode == :all || !lockfile
explicit_dependencies = lockfile.to_hash['DEPENDENCIES'] || []
explicit_dependencies.each do |string|
dependency = Dependency.new(string)
dependency_graph.add_root_vertex(dependency.name, nil)
end
add_child_vertex = lambda do |dependency_string, parents|
dependency = Dependency.from_string(dependency_string)
dependency_graph.add_child_vertex(dependency.name, parents.empty? ? dependency : nil, parents, nil)
dependency
end
add_to_dependency_graph = lambda do |object, parents|
case object
when String
add_child_vertex.call(object, parents)
when Hash
object.each do |key, value|
dependency = add_child_vertex.call(key, parents)
value.each { |v| add_to_dependency_graph.call(v, [dependency.name]) }
end
end
end
pods = lockfile.to_hash['PODS'] || []
pods.each do |pod|
add_to_dependency_graph.call(pod, [])
end
pods_to_update = result.podfile_state.changed + result.podfile_state.deleted pods_to_update = result.podfile_state.changed + result.podfile_state.deleted
pods_to_update += update[:pods] if update_mode == :selected pods_to_update += update[:pods] if update_mode == :selected
pods_to_update.each { |u| dependency_graph.detach_vertex_named(u) } LockingDependencyAnalyzer.generate_version_locking_dependencies(lockfile, pods_to_update)
end end
dependency_graph
end end
# Fetches the podspecs of external sources if modifications to the # Fetches the podspecs of external sources if modifications to the
......
require 'molinillo/dependency_graph'
module Pod
class Installer
class Analyzer
# Generates dependencies that require the specific version of the Pods
# that haven't changed in the {Lockfile}.
module LockingDependencyAnalyzer
# Generates dependencies that require the specific version of the Pods
# that haven't changed in the {Lockfile}.
#
# These dependencies are passed to the {Resolver}, unless the installer
# is in update mode, to prevent it from upgrading the Pods that weren't
# changed in the {Podfile}.
#
# @return [Molinillo::DependencyGraph<Dependency>] the dependencies
# generated by the lockfile that prevent the resolver to update
# a Pod.
#
def self.generate_version_locking_dependencies(lockfile, pods_to_update)
dependency_graph = Molinillo::DependencyGraph.new
if lockfile
explicit_dependencies = lockfile.to_hash['DEPENDENCIES'] || []
explicit_dependencies.each do |string|
dependency = Dependency.new(string)
dependency_graph.add_root_vertex(dependency.name, nil)
end
pods = lockfile.to_hash['PODS'] || []
pods.each do |pod|
add_to_dependency_graph(pod, [], dependency_graph)
end
pods_to_update.each { |u| dependency_graph.detach_vertex_named(u) }
end
dependency_graph
end
# Generates a completely 'unlocked' dependency graph.
#
# @return [Molinillo::DependencyGraph<Dependency>] an empty dependency
# graph
#
def self.unlocked_dependency_graph
Molinillo::DependencyGraph.new
end
private
def self.add_child_vertex_to_graph(dependency_string, parents, dependency_graph)
dependency = Dependency.from_string(dependency_string)
dependency_graph.add_child_vertex(dependency.name, parents.empty? ? dependency : nil, parents, nil)
dependency
end
def self.add_to_dependency_graph(object, parents, dependency_graph)
case object
when String
add_child_vertex_to_graph(object, parents, dependency_graph)
when Hash
object.each do |key, value|
dependency = add_child_vertex_to_graph(key, parents, dependency_graph)
value.each { |v| add_to_dependency_graph(v, [dependency.name], dependency_graph) }
end
end
end
end
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