Revert "Revert "dependency: don't recurse infinitely.""

This reverts commit fa43883dd1cd82f234b79c4a322339f03b9c098d.

Closes Homebrew/homebrew#48187.
This commit is contained in:
Mike McQuaid 2016-01-18 08:59:43 +00:00
parent a600262f68
commit 5b7dd99e99
2 changed files with 8 additions and 2 deletions

View File

@ -71,25 +71,31 @@ class Dependency
# The default filter, which is applied when a block is not given, omits
# optionals and recommendeds based on what the dependent has asked for.
def expand(dependent, deps = dependent.deps, &block)
# Keep track dependencies to avoid infinite cyclic dependency recursion.
@expand_stack ||= []
@expand_stack.push dependent.name
expanded_deps = []
deps.each do |dep|
# FIXME: don't hide cyclic dependencies
next if dependent.name == dep.name
case action(dependent, dep, &block)
when :prune
next
when :skip
next if @expand_stack.include? dep.name
expanded_deps.concat(expand(dep.to_formula, &block))
when :keep_but_prune_recursive_deps
expanded_deps << dep
else
next if @expand_stack.include? dep.name
expanded_deps.concat(expand(dep.to_formula, &block))
expanded_deps << dep
end
end
@expand_stack.pop
merge_repeats(expanded_deps)
end

View File

@ -73,7 +73,7 @@ class DependencyExpansionTests < Homebrew::TestCase
def test_merger_preserves_env_proc
env_proc = stub
dep = Dependency.new("foo", [], env_proc)
dep.stubs(:to_formula).returns(stub(:deps => []))
dep.stubs(:to_formula).returns(stub(:deps => [], :name => "foo"))
@deps.replace [dep]
assert_equal env_proc, Dependency.expand(@f).first.env_proc
end