Check deps of satisfied deps

This commit is contained in:
Jack Nagel 2013-07-22 21:36:11 -05:00
parent 1fb4cd501b
commit fcfc53df33
3 changed files with 25 additions and 5 deletions

View File

@ -71,8 +71,11 @@ class Dependency
# optionals and recommendeds based on what the dependent has asked for.
def expand(dependent, &block)
deps = dependent.deps.map do |dep|
if prune?(dependent, dep, &block)
case action(dependent, dep, &block)
when :prune
next
when :skip
expand(dep.to_formula, &block)
else
expand(dep.to_formula, &block) << dep
end
@ -81,8 +84,8 @@ class Dependency
merge_repeats(deps)
end
def prune?(dependent, dep, &block)
catch(:prune) do
def action(dependent, dep, &block)
catch(:action) do
if block_given?
yield dependent, dep
elsif dep.optional? || dep.recommended?
@ -93,7 +96,11 @@ class Dependency
# Used to prune dependencies when calling expand with a block.
def prune
throw(:prune, true)
throw(:action, :prune)
end
def skip
throw(:action, :skip)
end
def merge_repeats(deps)

View File

@ -178,7 +178,7 @@ class FormulaInstaller
elsif dep.build? && install_bottle?(dependent)
Dependency.prune
elsif dep.satisfied?
Dependency.prune
Dependency.skip
elsif dep.installed?
raise UnsatisfiedDependencyError.new(f, dep)
end

View File

@ -82,4 +82,17 @@ class DependencyExpansionTests < Test::Unit::TestCase
assert_equal %w{option}, Dependency.expand(@f).first.tags
end
def test_skip_skips_parent_but_yields_children
f = stub(:deps => [
build_dep(:foo, [], [@bar, @baz]),
build_dep(:foo, [], [@baz]),
])
deps = Dependency.expand(f) do |dependent, dep|
Dependency.skip if %w{foo qux}.include? dep.name
end
assert_equal [@bar, @baz], deps
end
end