From cef5429f9373526ed1fe523bcbbbb42b5cf65ea9 Mon Sep 17 00:00:00 2001 From: Adam Vandenberg Date: Tue, 28 Feb 2012 19:56:35 -0800 Subject: [PATCH] Use new Requirements code in Homebrew --- Library/Contributions/examples/brew-server | 4 +- Library/Homebrew/exceptions.rb | 52 +++------------------- Library/Homebrew/formula.rb | 47 +++++-------------- Library/Homebrew/formula_installer.rb | 35 ++++----------- 4 files changed, 28 insertions(+), 110 deletions(-) diff --git a/Library/Contributions/examples/brew-server b/Library/Contributions/examples/brew-server index ab0c7e469a..bcc15c257e 100755 --- a/Library/Contributions/examples/brew-server +++ b/Library/Contributions/examples/brew-server @@ -146,8 +146,8 @@ get '/formula/:name' do s << <<-HTML
Depends on HTML - klass.deps.each do |name| - s << "
#{link_to_formula(name)}
" + klass.deps.each do |dep| + s << "
#{link_to_formula(dep.name)}
" end end diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index df334582ca..fd425cfc15 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -51,54 +51,12 @@ class FormulaInstallationAlreadyAttemptedError < Homebrew::InstallationError end end -class UnsatisfiedExternalDependencyError < Homebrew::InstallationError - attr :type +class UnsatisfiedRequirement < Homebrew::InstallationError + attr :dep - def initialize formula, type - @type = type - super formula, get_message(formula) - end - - def get_message formula - <<-EOS.undent - Unsatisfied external dependency: #{formula} - Homebrew does not provide #{type.to_s.capitalize} dependencies, #{tool} does: - #{command_line} #{formula} - EOS - end - - private - - def tool - case type - when :python then 'easy_install' - when :ruby, :jruby, :rbx then 'rubygems' - when :perl then 'cpan' - when :node then 'npm' - when :chicken then 'chicken-install' - when :lua then "luarocks" - end - end - - def command_line - case type - when :python - "easy_install" - when :ruby - "gem install" - when :perl - "cpan -i" - when :jruby - "jruby -S gem install" - when :rbx - "rbx gem install" - when :node - "npm install" - when :chicken - "chicken-install" - when :lua - "luarocks install" - end + def initialize formula, dep + @dep = dep + super formula, "An unsatisfied requirement failed this build." end end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index b1cb3dc0e6..4c0634d06e 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1,4 +1,5 @@ require 'download_strategy' +require 'dependencies' require 'formula_support' require 'hardware' require 'bottles' @@ -357,17 +358,10 @@ class Formula HOMEBREW_REPOSITORY+"Library/Formula/#{name.downcase}.rb" end - def mirrors - self.class.mirrors or [] - end + def mirrors; self.class.mirrors or []; end - def deps - self.class.deps or [] - end - - def external_deps - self.class.external_deps or {} - end + def deps; self.class.dependencies.deps; end + def external_deps; self.class.dependencies.external_deps; end # deps are in an installable order # which means if a depends on b then b will be ordered before a in this list @@ -377,8 +371,8 @@ class Formula def self.expand_deps f f.deps.map do |dep| - dep = Formula.factory dep - expand_deps(dep) << dep + f_dep = Formula.factory dep.to_s + expand_deps(f_dep) << f_dep end end @@ -603,7 +597,7 @@ private end end - attr_rw :version, :homepage, :mirrors, :specs, :deps, :external_deps + attr_rw :version, :homepage, :mirrors, :specs attr_rw :keg_only_reason, :fails_with_llvm_reason, :skip_clean_all attr_rw :bottle_url, :bottle_sha1 attr_rw(*CHECKSUM_TYPES) @@ -659,29 +653,12 @@ private @mirrors.uniq! end - def depends_on name - @deps ||= [] - @external_deps ||= {:python => [], :perl => [], :ruby => [], :jruby => [], :chicken => [], :rbx => [], :node => [], :lua => []} + def dependencies + @dependencies ||= DependencyCollector.new + end - case name - when String, Formula - @deps << name - when Hash - key, value = name.shift - case value - when :python, :perl, :ruby, :jruby, :chicken, :rbx, :node, :lua - @external_deps[value] << key - when :optional, :recommended, :build - @deps << key - else - raise "Unsupported dependency type #{value}" - end - when Symbol - opoo "#{self.name} -- #{name}: Using symbols for deps is deprecated; use a string instead" - @deps << name.to_s - else - raise "Unsupported type #{name.class}" - end + def depends_on dep + dependencies.add(dep) end def skip_clean paths diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index cc6d61b8e0..c09621cee1 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -52,9 +52,16 @@ class FormulaInstaller EOS end - unless ignore_deps - f.check_external_deps + f.external_deps.each do |dep| + unless dep.satisfied? + puts dep.message + if dep.fatal? and not ignore_deps + raise UnsatisfiedRequirement.new(f, dep) + end + end + end + unless ignore_deps needed_deps = f.recursive_deps.reject{ |d| d.installed? } unless needed_deps.empty? needed_deps.each do |dep| @@ -369,20 +376,6 @@ class FormulaInstaller end -def external_dep_check dep, type - case type - when :python then %W{/usr/bin/env python -c import\ #{dep}} - when :jruby then %W{/usr/bin/env jruby -rubygems -e require\ '#{dep}'} - when :ruby then %W{/usr/bin/env ruby -rubygems -e require\ '#{dep}'} - when :rbx then %W{/usr/bin/env rbx -rubygems -e require\ '#{dep}'} - when :perl then %W{/usr/bin/env perl -e use\ #{dep}} - when :chicken then %W{/usr/bin/env csi -e (use #{dep})} - when :node then %W{/usr/bin/env node -e require('#{dep}');} - when :lua then %W{/usr/bin/env luarocks show #{dep}} - end -end - - class Formula def keg_only_text # Add indent into reason so undent won't truncate the beginnings of lines @@ -400,14 +393,4 @@ class Formula CPPFLAGS -I#{include} EOS end - - def check_external_deps - [:ruby, :python, :perl, :jruby, :rbx, :chicken, :node, :lua].each do |type| - self.external_deps[type].each do |dep| - unless quiet_system(*external_dep_check(dep, type)) - raise UnsatisfiedExternalDependencyError.new(dep, type) - end - end if self.external_deps[type] - end - end end