Commit 9f6d7d0a authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #2006 from take-cheeze/tsort_dep

Refactor MRuby::Gem::List#check.
parents 5f2817b3 69cc80ab
require 'pathname'
require 'forwardable'
require 'tsort'
module MRuby
module Gem
......@@ -288,28 +289,39 @@ module MRuby
end
def check
gem_table = @ary.reduce({}) { |res,v| res[v.name] = v; res }
each do |g|
g.dependencies.each do |dep|
name = dep[:gem]
req_versions = dep[:requirements]
dep_g = gem_table[name]
# check each GEM dependency against all available GEMs
found_dep_gem = false
each do |dep_g|
if name == dep_g.name
unless dep_g.version_ok?(req_versions)
fail "#{name} version should be #{req_versions.join(' and ')} but was '#{dep_g.version}'"
end
found_dep_gem = true
break
end
if dep_g.nil?
fail "The GEM '#{g.name}' depends on the GEM '#{name}' but it could not be found"
end
unless dep_g.version_ok? req_versions
fail "#{name} version should be #{req_versions.join(' and ')} but was '#{dep_g.version}'"
end
end
end
fail "The GEM '#{g.name}' depends on the GEM '#{name}' but it could not be found" unless found_dep_gem
class << gem_table
include TSort
alias tsort_each_node each_key
def tsort_each_child(n, &b)
fetch(n).dependencies.each do |v|
b.call v[:gem]
end
end
end
begin
@ary = gem_table.tsort.map { |v| gem_table[v] }
rescue TSort::Cyclic => e
fail "Circular mrbgem dependency found: #{e.message}"
end
end
end # List
end # Gem
......
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