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
begin
origin = @pkg.name
resolveDependencies
resolve_dependencies
search origin, true
install
......@@ -329,51 +329,62 @@ def resolve_dependencies_and_install
end
end
def resolveDependencies
def expand_dependencies
@dependencies = []
# check source packages existance
@source_package = 0
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
@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?
# retrieve name of all dependencies
@check_deps = @pkg.dependencies.map {|k, v| k}
check_deps = @pkg.dependencies.map {|k, v| k}
else
# 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
@source_package += 1
end
if @check_deps && !@check_deps.empty?
@dependencies.unshift @check_deps
@check_deps.each do |dep|
search dep, true
push_dependencies
end
# 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
push_dependencies
end
end
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
if @source_package > 0
@dependencies.unshift 'buildessential'
search 'buildessential', true
push_dependencies
end
push_dependencies
@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: "
@dependencies.flatten!.uniq!
@dependencies.each do |dep|
dependencies.each do |dep|
print dep + " "
end
......@@ -392,7 +403,7 @@ def resolveDependencies
end
if proceed
@dependencies.each do |dep|
dependencies.each do |dep|
search dep
install
end
......@@ -451,7 +462,7 @@ def resolve_dependencies_and_build
# mark current package as which is required to compile from source
@pkg.build_from_source = true
resolveDependencies
resolve_dependencies
search origin, true
build_package Dir.pwd
......
......@@ -12,8 +12,9 @@ class Package
@@debug_symbol = ENV['CREW_DEBUG_SYMBOL'] || false
def self.dependencies
# Not sure how to initialize instance variable of not constructed class.
# Therefore, initialize it in reader function.
# We need instance variable in derived class, so not define it here,
# base class. Instead of define it, we initialize it in a function
# called from derived classees.
@dependencies = Hash.new unless @dependencies
@dependencies
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