From 5e83629119c47436e5f8fefa90711062e4f3ea64 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 27 Jan 2013 19:40:10 -0600 Subject: [PATCH] Extract unsatisfied dependency logic from installer --- Library/Homebrew/dependency.rb | 8 ++++++++ Library/Homebrew/exceptions.rb | 9 +++++++++ Library/Homebrew/formula_installer.rb | 14 ++++---------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/dependency.rb b/Library/Homebrew/dependency.rb index 91b939c4f3..331082219f 100644 --- a/Library/Homebrew/dependency.rb +++ b/Library/Homebrew/dependency.rb @@ -42,6 +42,14 @@ class Dependency ARGV.formulae.include?(to_formula) rescue false end + def satisfied? + installed? && missing_options.empty? + end + + def missing_options + options - Tab.for_formula(to_formula).used_options + end + def universal! tags << 'universal' if to_formula.build.has_option? 'universal' end diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index edd5cf1d1f..a1dcb101dc 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -77,6 +77,15 @@ class FormulaInstallationAlreadyAttemptedError < Homebrew::InstallationError end end +class UnsatisfiedDependencyError < Homebrew::InstallationError + def initialize(f, dep) + super f, <<-EOS.undent + #{f} dependency #{dep} not installed with: + #{dep.missing_options * ', '} + EOS + end +end + class UnsatisfiedRequirements < Homebrew::InstallationError attr :reqs diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index b934e2a864..67c90cd790 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -143,16 +143,10 @@ class FormulaInstaller dep.universal! unless dep.build? end - dep_f = dep.to_formula - dep_tab = Tab.for_formula(dep) - missing = dep.options - dep_tab.used_options - - if dep.installed? - if missing.empty? - Dependency.prune - else - raise "#{f} dependency #{dep} not installed with:\n #{missing*', '}" - end + if dep.satisfied? + Dependency.prune + elsif dep.installed? + raise UnsatisfiedDependencyError.new(f, dep) end end end