Commit 31b2f7a4 authored by lyxell's avatar lyxell Committed by GitHub

Merge pull request #717 from jam7/refactor/dependency

Refactor dependency expansion
parents adee0e73 864d2b33
...@@ -312,7 +312,7 @@ def resolve_dependencies_and_install ...@@ -312,7 +312,7 @@ def resolve_dependencies_and_install
begin begin
origin = @pkg.name origin = @pkg.name
resolveDependencies resolve_dependencies
search origin, true search origin, true
install install
...@@ -329,51 +329,62 @@ def resolve_dependencies_and_install ...@@ -329,51 +329,62 @@ def resolve_dependencies_and_install
end end
end end
def resolveDependencies def expand_dependencies
@dependencies = [] @dependencies = []
# check source packages existance # check source packages existance
@source_package = 0 @source_package = 0
def push_dependencies def push_dependencies
if @pkg.is_binary?(@device[:architecture]) if @pkg.is_binary?(@device[:architecture]) ||
(!@pkg.in_upgrade && @device[:installed_packages].any? { |pkg| pkg[:name] == @pkg.name })
# retrieve name of dependencies that doesn't contain :build tag # retrieve name of dependencies that doesn't contain :build tag
@check_deps = @pkg.dependencies.select {|k, v| !v.include?(:build)}.map {|k, v| k} check_deps = @pkg.dependencies.select {|k, v| !v.include?(:build)}.map {|k, v| k}
elsif @pkg.is_fake? elsif @pkg.is_fake?
# retrieve name of all dependencies # retrieve name of all dependencies
@check_deps = @pkg.dependencies.map {|k, v| k} check_deps = @pkg.dependencies.map {|k, v| k}
else else
# retrieve name of all dependencies # retrieve name of all dependencies
@check_deps = @pkg.dependencies.map {|k, v| k} check_deps = @pkg.dependencies.map {|k, v| k}
# count the number of source packages to add buildessential into dependencies later # count the number of source packages to add buildessential into dependencies later
@source_package += 1 @source_package += 1
end end
if @check_deps && !@check_deps.empty?
@dependencies.unshift @check_deps
@check_deps.each do |dep| # remove a dependent package which is equal to the target
check_deps.select! {|name| @pkgName != name}
# add new dependencies at the beginning of array
@dependencies = check_deps.clone.concat(@dependencies)
# check all dependencies recursively
check_deps.each do |dep|
search dep, true search dep, true
push_dependencies push_dependencies
end end
end end
end
push_dependencies push_dependencies
# Add buildessential and solve its dependencies if any of dependent # Add buildessential's dependencies if any of dependent
# packages are made from source # packages are made from source
if @source_package > 0 if @source_package > 0
@dependencies.unshift 'buildessential'
search 'buildessential', true search 'buildessential', true
end
push_dependencies push_dependencies
end
@dependencies.uniq
end
def resolve_dependencies
dependencies = expand_dependencies
# leave only not installed packages in dependencies
dependencies.select! {|name| @device[:installed_packages].none? {|pkg| pkg[:name] == name}}
return if @dependencies.empty? return if dependencies.empty?
puts "Following packages also need to be installed: " puts "Following packages also need to be installed: "
@dependencies.flatten!.uniq! dependencies.each do |dep|
@dependencies.each do |dep|
print dep + " " print dep + " "
end end
...@@ -392,7 +403,7 @@ def resolveDependencies ...@@ -392,7 +403,7 @@ def resolveDependencies
end end
if proceed if proceed
@dependencies.each do |dep| dependencies.each do |dep|
search dep search dep
install install
end end
...@@ -451,7 +462,7 @@ def resolve_dependencies_and_build ...@@ -451,7 +462,7 @@ def resolve_dependencies_and_build
# mark current package as which is required to compile from source # mark current package as which is required to compile from source
@pkg.build_from_source = true @pkg.build_from_source = true
resolveDependencies resolve_dependencies
search origin, true search origin, true
build_package Dir.pwd build_package Dir.pwd
......
...@@ -12,8 +12,9 @@ class Package ...@@ -12,8 +12,9 @@ class Package
@@debug_symbol = ENV['CREW_DEBUG_SYMBOL'] || false @@debug_symbol = ENV['CREW_DEBUG_SYMBOL'] || false
def self.dependencies def self.dependencies
# Not sure how to initialize instance variable of not constructed class. # We need instance variable in derived class, so not define it here,
# Therefore, initialize it in reader function. # base class. Instead of define it, we initialize it in a function
# called from derived classees.
@dependencies = Hash.new unless @dependencies @dependencies = Hash.new unless @dependencies
@dependencies @dependencies
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