diff --git a/Library/Homebrew/dependency.rb b/Library/Homebrew/dependency.rb index 407623810e..c63e26f3ff 100644 --- a/Library/Homebrew/dependency.rb +++ b/Library/Homebrew/dependency.rb @@ -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) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 33bc97180b..d4e4e8dcc4 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -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 diff --git a/Library/Homebrew/test/test_dependency_expansion.rb b/Library/Homebrew/test/test_dependency_expansion.rb index d0dada2e07..90d4dcc363 100644 --- a/Library/Homebrew/test/test_dependency_expansion.rb +++ b/Library/Homebrew/test/test_dependency_expansion.rb @@ -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