Extract unsatisfied dependency logic from installer

This commit is contained in:
Jack Nagel 2013-01-27 19:40:10 -06:00
parent 41dec56d29
commit 5e83629119
3 changed files with 21 additions and 10 deletions

View File

@ -42,6 +42,14 @@ class Dependency
ARGV.formulae.include?(to_formula) rescue false ARGV.formulae.include?(to_formula) rescue false
end end
def satisfied?
installed? && missing_options.empty?
end
def missing_options
options - Tab.for_formula(to_formula).used_options
end
def universal! def universal!
tags << 'universal' if to_formula.build.has_option? 'universal' tags << 'universal' if to_formula.build.has_option? 'universal'
end end

View File

@ -77,6 +77,15 @@ class FormulaInstallationAlreadyAttemptedError < Homebrew::InstallationError
end end
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 class UnsatisfiedRequirements < Homebrew::InstallationError
attr :reqs attr :reqs

View File

@ -143,16 +143,10 @@ class FormulaInstaller
dep.universal! unless dep.build? dep.universal! unless dep.build?
end end
dep_f = dep.to_formula if dep.satisfied?
dep_tab = Tab.for_formula(dep) Dependency.prune
missing = dep.options - dep_tab.used_options elsif dep.installed?
raise UnsatisfiedDependencyError.new(f, dep)
if dep.installed?
if missing.empty?
Dependency.prune
else
raise "#{f} dependency #{dep} not installed with:\n #{missing*', '}"
end
end end
end end
end end